blob: dd925d676f190a492ee97f9c9abd22c20bd849f2 [file] [log] [blame]
import { BACKTICK, COLON, ASTERISK, DOUBLE_ASTERISK } from '../src/patterns';
function testPatterns(
pattern: string,
testCases: { [key: string]: string[] },
): void {
for (const [label, [state, name]] of Object.entries(testCases)) {
const regexp = new RegExp(pattern, 'g');
const m = regexp.exec(label);
if (m === null) {
throw new Error('No match found');
}
expect(m[1]).toBe(state);
expect(m[2]).toBe(name);
}
}
describe('patterns', (): void => {
it('backtick', (): void => {
const testCases = {
'- [] `abc`': ['', 'abc'],
'- [ ] `abc`': [' ', 'abc'],
'- [ ] `abc`': [' ', 'abc'],
'- [x] `abc`': ['x', 'abc'],
'- [ x] `abc`': [' x', 'abc'],
'- [x ] `abc`': ['x ', 'abc'],
'- [ x ] `abc`': [' x ', 'abc'],
};
testPatterns(BACKTICK, testCases);
});
it('colon', (): void => {
const testCases = {
'- [] abc:': ['', 'abc'],
'- [ ] abc:': [' ', 'abc'],
'- [ ] abc:': [' ', 'abc'],
'- [x] abc:': ['x', 'abc'],
'- [ x] abc:': [' x', 'abc'],
'- [x ] abc:': ['x ', 'abc'],
'- [ x ] abc:': [' x ', 'abc'],
};
testPatterns(COLON, testCases);
});
it('asterisk', (): void => {
const testCases = {
'- [] *abc*': ['', 'abc'],
'- [ ] *abc*': [' ', 'abc'],
'- [ ] *abc*': [' ', 'abc'],
'- [x] *abc*': ['x', 'abc'],
'- [ x] *abc*': [' x', 'abc'],
'- [x ] *abc*': ['x ', 'abc'],
'- [ x ] *abc*': [' x ', 'abc'],
};
testPatterns(ASTERISK, testCases);
});
it('double asterisk', (): void => {
const testCases = {
'- [] **abc**': ['', 'abc'],
'- [ ] **abc**': [' ', 'abc'],
'- [ ] **abc**': [' ', 'abc'],
'- [x] **abc**': ['x', 'abc'],
'- [ x] **abc**': [' x', 'abc'],
'- [x ] **abc**': ['x ', 'abc'],
'- [ x ] **abc**': [' x ', 'abc'],
};
testPatterns(DOUBLE_ASTERISK, testCases);
});
});