Skip to content

Commit

Permalink
Add tests for combined keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
frenic committed Apr 17, 2018
1 parent aa33392 commit 34ca26c
Showing 1 changed file with 40 additions and 39 deletions.
79 changes: 40 additions & 39 deletions __tests__/typer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import typing, { Type } from '../src/typer';

describe('typing', () => {
it('types combinators', () => {
expect(typing(parse('something another-thing'))).toHaveLength(1);
expect(typing(parse('something && another-thing'))).toHaveLength(1);
expect(typing(parse('something || another-thing'))).toHaveLength(3);
expect(typing(parse('something | another-thing'))).toHaveLength(2);
expect(typing(parse('something || another-thing'))).toHaveLength(4);
expect(typing(parse('something && another-thing'))).toHaveLength(2);
expect(typing(parse('something another-thing'))).toHaveLength(1);
});

it('types components', () => {
Expand All @@ -26,52 +26,53 @@ describe('typing', () => {
});

it('types optional components', () => {
expect(typing(parse('something another-thing? | 100'))).toMatchObject([
{ type: Type.StringLiteral },
{ type: Type.String },
{ type: Type.NumericLiteral },
]);
expect(typing(parse('something another-thing? yet-another-thing? | 100'))).toMatchObject([
{ type: Type.StringLiteral },
{ type: Type.String },
{ type: Type.NumericLiteral },
expect(typing(parse('something another-thing?'))).toMatchObject([
{ type: Type.StringLiteral, literal: 'something' },
{ type: Type.StringLiteral, literal: 'something another-thing' },
]);
expect(typing(parse('something? another-thing yet-another-thing? | 100'))).toMatchObject([
{ type: Type.String },
{ type: Type.StringLiteral },
{ type: Type.NumericLiteral },
expect(typing(parse('something another-thing? yet-another-thing?'))).toMatchObject([
{ type: Type.StringLiteral, literal: 'something another-thing yet-another-thing' },
{ type: Type.StringLiteral, literal: 'something another-thing' },
{ type: Type.StringLiteral, literal: 'something yet-another-thing' },
{ type: Type.StringLiteral, literal: 'something' },
]);
expect(typing(parse('something? another-thing? yet-another-thing | 100'))).toMatchObject([
{ type: Type.String },
{ type: Type.StringLiteral },
{ type: Type.NumericLiteral },
expect(typing(parse('something? another-thing yet-another-thing?'))).toMatchObject([
{ type: Type.StringLiteral, literal: 'something another-thing yet-another-thing' },
{ type: Type.StringLiteral, literal: 'something another-thing' },
{ type: Type.StringLiteral, literal: 'another-thing yet-another-thing' },
{ type: Type.StringLiteral, literal: 'another-thing' },
]);
expect(typing(parse('something? another-thing? yet-another-thing? | 100'))).toMatchObject([
{ type: Type.StringLiteral },
{ type: Type.String },
{ type: Type.StringLiteral },
{ type: Type.StringLiteral },
{ type: Type.NumericLiteral },
expect(typing(parse('something? another-thing? yet-another-thing'))).toMatchObject([
{ type: Type.StringLiteral, literal: 'something another-thing yet-another-thing' },
{ type: Type.StringLiteral, literal: 'something yet-another-thing' },
{ type: Type.StringLiteral, literal: 'another-thing yet-another-thing' },
{ type: Type.StringLiteral, literal: 'yet-another-thing' },
]);
expect(typing(parse('something another-thing yet-another-thing? | 100'))).toMatchObject([
{ type: Type.String },
{ type: Type.NumericLiteral },
expect(typing(parse('something? another-thing? yet-another-thing?'))).toMatchObject([
{ type: Type.StringLiteral, literal: 'something another-thing yet-another-thing' },
{ type: Type.StringLiteral, literal: 'something another-thing' },
{ type: Type.StringLiteral, literal: 'something yet-another-thing' },
{ type: Type.StringLiteral, literal: 'another-thing yet-another-thing' },
{ type: Type.StringLiteral, literal: 'something yet-another-thing' },
{ type: Type.StringLiteral, literal: 'something' },
{ type: Type.StringLiteral, literal: 'another-thing' },
{ type: Type.StringLiteral, literal: 'yet-another-thing' },
]);
expect(typing(parse('something another-thing? yet-another-thing | 100'))).toMatchObject([
{ type: Type.String },
{ type: Type.NumericLiteral },
expect(typing(parse('something another-thing yet-another-thing?'))).toMatchObject([
{ type: Type.StringLiteral, literal: 'something another-thing yet-another-thing' },
{ type: Type.StringLiteral, literal: 'something another-thing' },
]);
expect(typing(parse('something? another-thing yet-another-thing | 100'))).toMatchObject([
{ type: Type.String },
{ type: Type.NumericLiteral },
expect(typing(parse('something another-thing? yet-another-thing'))).toMatchObject([
{ type: Type.StringLiteral, literal: 'something another-thing yet-another-thing' },
{ type: Type.StringLiteral, literal: 'something yet-another-thing' },
]);
});

it('types optional group components', () => {
expect(typing(parse('[ something ] [ another-thing ]? | 100'))).toMatchObject([
{ type: Type.StringLiteral },
{ type: Type.String },
{ type: Type.NumericLiteral },
expect(typing(parse('something [ another-thing | yet-another-thing ]?'))).toMatchObject([
{ type: Type.StringLiteral, literal: 'something another-thing' },
{ type: Type.StringLiteral, literal: 'something yet-another-thing' },
{ type: Type.StringLiteral, literal: 'something' },
]);
});
});

0 comments on commit 34ca26c

Please sign in to comment.