2023-12-28 14:12:55 +00:00
|
|
|
import assert from 'assert';
|
|
|
|
import * as P from '../src/internal/core';
|
|
|
|
|
2024-06-29 08:30:55 +00:00
|
|
|
const state = {
|
|
|
|
nestLimit: 3,
|
|
|
|
depth: 0,
|
|
|
|
};
|
|
|
|
|
2023-12-28 14:12:55 +00:00
|
|
|
describe('core', () => {
|
|
|
|
describe('difference', () => {
|
|
|
|
test('basic', () => {
|
|
|
|
const parser = P.difference(P.regexp(/\p{Letter}/u), P.str('x'));
|
|
|
|
|
2024-06-29 08:30:55 +00:00
|
|
|
let result = parser.handler('x',0,state) as P.Success<any>;
|
2023-12-28 14:12:55 +00:00
|
|
|
assert.deepStrictEqual(result,P.failure());
|
|
|
|
|
2024-06-29 08:30:55 +00:00
|
|
|
result = parser.handler('a',0,state) as P.Success<any>;
|
2023-12-28 14:12:55 +00:00
|
|
|
assert.deepStrictEqual(result,P.success(1,'a'));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('horizontal whitespace', () => {
|
|
|
|
const parser = P.difference(P.regexp(/\s/u), P.newline);
|
|
|
|
|
2024-06-29 08:30:55 +00:00
|
|
|
let result = parser.handler('\n',0,state) as P.Success<any>;
|
2023-12-28 14:12:55 +00:00
|
|
|
assert.deepStrictEqual(result,P.failure());
|
|
|
|
|
2024-06-29 08:30:55 +00:00
|
|
|
result = parser.handler(' ',0,state) as P.Success<any>;
|
2023-12-28 14:12:55 +00:00
|
|
|
assert.deepStrictEqual(result,P.success(1,' '));
|
|
|
|
|
2024-06-29 08:30:55 +00:00
|
|
|
result = parser.handler('\t',0,state) as P.Success<any>;
|
2023-12-28 14:12:55 +00:00
|
|
|
assert.deepStrictEqual(result,P.success(1,'\t'));
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|