OLD | NEW |
| (Empty) |
1 library petitparser.test.test_test; | |
2 | |
3 import 'package:test/test.dart'; | |
4 | |
5 import 'package:petitparser/petitparser.dart'; | |
6 import 'package:petitparser/test.dart'; | |
7 | |
8 void main() { | |
9 group('accept', () { | |
10 test('success', () { | |
11 var matcher = accept(char('a')); | |
12 var state = new Map(); | |
13 expect(matcher.matches('a', state), isTrue); | |
14 expect(state, isEmpty); | |
15 var description = new StringDescription(); | |
16 matcher.describe(description); | |
17 expect(description.toString(), '"Instance of \'CharacterParser\'["a" expec
ted]" accepts input'); | |
18 }); | |
19 test('failure', () { | |
20 var matcher = accept(char('a')); | |
21 var state = new Map(); | |
22 expect(matcher.matches('b', state), isFalse); | |
23 expect(state, isNot(isEmpty)); | |
24 var description = new StringDescription(); | |
25 matcher.describeMismatch('b', description, state, false); | |
26 expect(description.toString(), '"Instance of \'CharacterParser\'["a" expec
ted]" produces "Failure[1:1]: "a" expected" which is not accepted'); | |
27 }); | |
28 }); | |
29 group('parse', () { | |
30 test('success', () { | |
31 var matcher = parse(char('a'), 'a'); | |
32 var state = new Map(); | |
33 expect(matcher.matches('a', state), isTrue); | |
34 expect(state, isEmpty); | |
35 var description = new StringDescription(); | |
36 matcher.describe(description); | |
37 expect(description.toString(), '"Instance of \'CharacterParser\'["a" expec
ted]" ' | |
38 'accepts \'a\''); | |
39 }); | |
40 test('failure', () { | |
41 var matcher = parse(char('a'), 'a'); | |
42 var state = new Map(); | |
43 expect(matcher.matches('b', state), isFalse); | |
44 expect(state, isNot(isEmpty)); | |
45 var description = new StringDescription(); | |
46 matcher.describeMismatch('b', description, state, false); | |
47 expect(description.toString(), '"Instance of \'CharacterParser\'["a" expec
ted]" ' | |
48 'produces "Failure[1:1]: "a" expected" which is not accepted'); | |
49 }); | |
50 test('matcher', () { | |
51 var matcher = parse(char('a'), 'b'); | |
52 var state = new Map(); | |
53 expect(matcher.matches('a', state), isFalse); | |
54 expect(state, isNot(isEmpty)); | |
55 var description = new StringDescription(); | |
56 matcher.describeMismatch('a', description, state, false); | |
57 expect(description.toString(), '"Instance of \'CharacterParser\'["a" expec
ted]" ' | |
58 'produces "Success[1:2]: a" which parse result is different.\n' | |
59 'Expected: b\n Actual: a\n ^\n Differ at offset 0'); | |
60 }); | |
61 test('position', () { | |
62 var matcher = parse(char('a'), 'a', 0); | |
63 var state = new Map(); | |
64 expect(matcher.matches('a', state), isFalse); | |
65 expect(state, isNot(isEmpty)); | |
66 var description = new StringDescription(); | |
67 matcher.describeMismatch('a', description, state, false); | |
68 expect(description.toString(), '"Instance of \'CharacterParser\'["a" expec
ted]" ' | |
69 'produces "Success[1:2]: a" that consumes input to 1 instead of 0'); | |
70 }); | |
71 }); | |
72 } | |
OLD | NEW |