Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
marihachi committed Aug 19, 2023
1 parent 2b516ef commit a216892
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ describe('Parser', () => {
assert.deepStrictEqual(result.value, 2);
});

test('text()', () => {
test('span()', () => {
const input = 'abc123';
const parser = T.seq([
T.str('abc'),
T.str('123'),
]).text();
T.token('abc'),
T.token('123'),
]).span();
const result = parser.parse(input);
assert.ok(result.success);
assert.deepStrictEqual(result.value, input);
Expand All @@ -51,7 +51,7 @@ describe('Parser', () => {
test('0 item', () => {
let input: string, result: T.Result<string[]>;

const parser = T.str('abc').many();
const parser = T.token('abc').many();

input = '';
result = parser.parse(input);
Expand All @@ -63,7 +63,7 @@ describe('Parser', () => {
test('1 item', () => {
let input: string, result: T.Result<string[]>;

const parser = T.str('abc').many();
const parser = T.token('abc').many();

input = 'abc';
result = parser.parse(input);
Expand All @@ -77,7 +77,7 @@ describe('Parser', () => {
test('0 item', () => {
let input: string, result: T.Result<string[]>;

const parser = T.str('').many(1);
const parser = T.token('').many(1);

input = '';
result = parser.parse(input);
Expand All @@ -88,7 +88,7 @@ describe('Parser', () => {
test('1 item', () => {
let input: string, result: T.Result<string[]>;

const parser = T.str('abc').many(1);
const parser = T.token('abc').many(1);

input = 'abc';
result = parser.parse(input);
Expand All @@ -100,7 +100,7 @@ describe('Parser', () => {
test('2 items', () => {
let input: string, result: T.Result<string[]>;

const parser = T.str('abc').many(1);
const parser = T.token('abc').many(1);

input = 'abcabc';
result = parser.parse(input);
Expand All @@ -114,9 +114,9 @@ describe('Parser', () => {
let input: string, result: T.Result<string>;

const parser = T.seq([
T.str('('),
T.char.many({ min: 1, notMatch: T.str(')') }).text(),
T.str(')'),
T.token('('),
T.any.many({ min: 1, notMatch: T.token(')') }).span(),
T.token(')'),
], 1);

input = '(abc)';
Expand All @@ -132,11 +132,11 @@ describe('Parser', () => {
});

describe('Combinators', () => {
describe('str()', () => {
describe('token()', () => {
describe('with string value', () => {
test('matched', () => {
const input = 'abc';
const parser = T.str('abc');
const parser = T.token('abc');
const result = parser.parse(input);
assert.ok(result.success);
assert.deepStrictEqual(result.value, input);
Expand All @@ -145,7 +145,7 @@ describe('Combinators', () => {

test('not matched', () => {
const input = 'ab';
const parser = T.str('abc');
const parser = T.token('abc');
const result = parser.parse(input);
assert.ok(!result.success);
assert.strictEqual(result.index, 0);
Expand All @@ -154,7 +154,7 @@ describe('Combinators', () => {

test('with RegExp value', () => {
const input = 'abcDEF';
const parser = T.str(/[a-z]+/i);
const parser = T.token(/[a-z]+/i);
const result = parser.parse(input);
assert.ok(result.success);
assert.deepStrictEqual(result.value, input);
Expand All @@ -167,8 +167,8 @@ describe('Combinators', () => {
test('success', () => {
const input = 'abc123';
const parser = T.seq([
T.str('abc'),
T.str('123'),
T.token('abc'),
T.token('123'),
]);
const result = parser.parse(input);
assert.ok(result.success);
Expand All @@ -179,8 +179,8 @@ describe('Combinators', () => {
test('partial success', () => {
const input = 'abc1';
const parser = T.seq([
T.str('abc'),
T.str('123'),
T.token('abc'),
T.token('123'),
]);
const result = parser.parse(input);
assert.ok(!result.success);
Expand All @@ -190,8 +190,8 @@ describe('Combinators', () => {
test('failure', () => {
const input = 'a';
const parser = T.seq([
T.str('abc'),
T.str('123'),
T.token('abc'),
T.token('123'),
]);
const result = parser.parse(input);
assert.ok(!result.success);
Expand All @@ -202,8 +202,8 @@ describe('Combinators', () => {
test('with select param', () => {
const input = 'abc123';
const parser = T.seq([
T.str('abc'),
T.str('123'),
T.token('abc'),
T.token('123'),
], 0);
const result = parser.parse(input);
assert.ok(result.success);
Expand All @@ -215,8 +215,8 @@ describe('Combinators', () => {
test('alt()', () => {
const input = '123';
const parser = T.alt([
T.str('abc'),
T.str('123'),
T.token('abc'),
T.token('123'),
]);
const result = parser.parse(input);
assert.ok(result.success);
Expand All @@ -238,7 +238,7 @@ describe('Combinators', () => {

// 1
parser = T.where(state => state.enabled,
T.char
T.any
).state('enabled', () => true);

result = parser.parse('a');
Expand All @@ -247,7 +247,7 @@ describe('Combinators', () => {

// 2
parser = T.where(state => state.enabled,
T.char
T.any
).state('enabled', () => false);

result = parser.parse('a');
Expand All @@ -258,7 +258,7 @@ describe('Combinators', () => {
parser = T.seq([
T.succeeded(null).state('enabled', () => true),
T.where(state => !state.enabled,
T.str('a')
T.token('a')
),
], 1);

Expand All @@ -282,9 +282,9 @@ describe('Combinators', () => {
assert.strictEqual(result.index, 0);
});

test('char', () => {
test('any', () => {
const input = 'a';
const parser = T.char;
const parser = T.any;
const result = parser.parse(input);
assert.ok(result.success);
assert.deepStrictEqual(result.value, 'a');
Expand Down

0 comments on commit a216892

Please sign in to comment.