-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {matchers} from './helpers/matchers.js'; | ||
|
||
beforeEach(() => { | ||
jasmine.addMatchers(matchers); | ||
}); | ||
|
||
describe('CharacterSet', () => { | ||
describe('any', () => { | ||
it('should match any character except line feed', () => { | ||
expect('a').toMatchTranspiled('.'); | ||
expect('\0').toMatchTranspiled('.'); | ||
expect('\r').toMatchTranspiled('.'); | ||
}); | ||
|
||
it('should not match line feed with flag m disabled', () => { | ||
expect('\n').not.toMatchTranspiled('.'); | ||
}); | ||
|
||
it('should match line feed with flag m enabled', () => { | ||
expect('\n').toMatchTranspiled({pattern: '.', flags: 'm'}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {compile} from '../src/index.js'; | ||
|
||
describe('compile', () => { | ||
it('should return an object with pattern and flags properties', () => { | ||
expect(compile('')).toEqual({pattern: '', flags: 'v'}); | ||
}); | ||
|
||
it('should accept supported targets', () => { | ||
expect(compile('', '', {target: 'ES2018'})).toEqual({pattern: '', flags: 'u'}); | ||
expect(compile('', '', {target: 'ES2024'})).toEqual({pattern: '', flags: 'v'}); | ||
expect(compile('', '', {target: 'ESNext'})).toEqual({pattern: '', flags: 'v'}); | ||
}); | ||
|
||
it('should not accept unsupported targets', () => { | ||
expect(() => compile('', '', {target: 'ES2019'})).toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {toRegExp} from '../../src/index.js'; | ||
import {Target} from '../../src/utils.js'; | ||
|
||
const targets = Object.keys(Target); | ||
|
||
export const matchers = { | ||
toMatchTranspiled() { | ||
return { | ||
compare(actual, expected) { | ||
const pattern = typeof expected === 'string' ? expected : expected.pattern; | ||
const flags = expected?.flags ?? ''; | ||
for (const target of targets) { | ||
const re = toRegExp(pattern, flags, {target}); | ||
if (!re.test(actual)) { | ||
return { | ||
pass: false, | ||
message: `Expected "${actual}" to match "${pattern}" with ${flags ? `flags "${flags}" and ` : ''}target ${target}`, | ||
}; | ||
} | ||
} | ||
return {pass: true}; | ||
}, | ||
}; | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.