-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathcontext_test.dart
80 lines (78 loc) · 2.89 KB
/
context_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import 'package:petitparser/petitparser.dart';
import 'package:test/test.dart';
import 'utils/matchers.dart';
void main() {
const buffer = 'a\nc';
const context = Context(buffer, 0);
test('context', () {
expect(context.buffer, buffer);
expect(context.position, 0);
expect(context.toString(), isToString(name: 'Context', rest: ['[1:1]']));
});
group('success', () {
test('default', () {
final success = context.success('result');
expect(success.buffer, buffer);
expect(success.position, 0);
expect(success.value, 'result');
expect(() => success.message, throwsA(isUnsupportedError));
expect(
success.toString(),
isToString(
name: 'Success', generic: '<String>', rest: ['[1:1]: result']));
});
test('with position', () {
final success = context.success('result', 2);
expect(success.buffer, buffer);
expect(success.position, 2);
expect(success.value, 'result');
expect(() => success.message, throwsA(isUnsupportedError));
expect(
success.toString(),
isToString(
name: 'Success', generic: '<String>', rest: ['[2:1]: result']));
});
});
group('failure', () {
test('default', () {
final failure = context.failure('error');
expect(failure.buffer, buffer);
expect(failure.position, 0);
expect(
() => failure.value,
throwsA(isParserException
.having((error) => error.failure, 'failure', same(failure))
.having((error) => error.message, 'message', 'error')
.having((error) => error.offset, 'offset', 0)
.having((error) => error.source, 'source', same(buffer))
.having(
(error) => error.toString(),
'toString',
isToString(
name: 'ParserException', rest: ['[1:1]: error']))));
expect(failure.message, 'error');
expect(failure.toString(),
isToString(name: 'Failure', rest: ['[1:1]: error']));
});
test('with position', () {
final failure = context.failure('error', 2);
expect(failure.buffer, buffer);
expect(failure.position, 2);
expect(
() => failure.value,
throwsA(isParserException
.having((error) => error.failure, 'failure', same(failure))
.having((error) => error.message, 'message', 'error')
.having((error) => error.offset, 'offset', 2)
.having((error) => error.source, 'source', same(buffer))
.having(
(error) => error.toString(),
'toString',
isToString(
name: 'ParserException', rest: ['[2:1]: error']))));
expect(failure.message, 'error');
expect(failure.toString(),
isToString(name: 'Failure', rest: ['[2:1]: error']));
});
});
}