Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: packages/petitparser/lib/test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packages/petitparser/lib/src/smalltalk/grammar.dart ('k') | packages/petitparser/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /// This package contains matches to write tests for parsers.
2 * This package contains matches to write tests for parsers. 2 ///
3 * 3 /// Examples:
4 * Examples: 4 ///
5 * 5 /// var json = new JsonParser();
6 * var json = new JsonParser(); 6 ///
7 * 7 /// // verifies that the input gets parsed and all input is consumed
8 * // verifies that the input gets parsed and all input is consumed 8 /// expect('{"a": 1}', accepts(new JsonParser()));
9 * expect('{"a": 1}', accepts(new JsonParser())); 9 ///
10 * 10 /// // verifies that the input gets parsed to a dictionary and that all inpu t is consumed
11 * // verifies that the input gets parsed to a dictionary and that all input is consumed 11 /// expect('{"a": 1}', parses(new JsonParser(), {'a': 1}));
12 * expect('{"a": 1}', parses(new JsonParser(), {'a': 1}));
13 */
14 12
15 library test_util; 13 library petitparser.test_util;
16 14
17 import 'package:matcher/matcher.dart'; 15 import 'package:matcher/matcher.dart';
18 import 'package:petitparser/petitparser.dart' hide predicate; 16 import 'package:petitparser/petitparser.dart' hide predicate;
19 17
20 /** 18 /// Returns a matcher that succeeds if the [parser] accepts the input.
21 * Returns a matcher that succeeds if the [parser] accepts the input.
22 */
23 Matcher accept(Parser parser) { 19 Matcher accept(Parser parser) {
24 return parse(parser, predicate((value) => true, 'input')); 20 return parse(parser, predicate((value) => true, 'input'));
25 } 21 }
26 22
27 /** 23 /// Returns a matcher that succeeds if the [parser] succeeds and accepts the pro vided [matcher].
28 * Returns a matcher that succeeds if the [parser] succeeds and accepts the prov ided [matcher].
29 */
30 Matcher parse(Parser parser, matcher, [int position = -1]) { 24 Matcher parse(Parser parser, matcher, [int position = -1]) {
31 return new _Parse(parser, wrapMatcher(matcher), position); 25 return new _Parse(parser, wrapMatcher(matcher), position);
32 } 26 }
33 27
34 class _Parse extends Matcher { 28 class _Parse extends Matcher {
35 29
36 final Parser parser; 30 final Parser parser;
37 final Matcher matcher; 31 final Matcher matcher;
38 final int position; 32 final int position;
39 33
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 description 79 description
86 .add(' that consumes input to ') 80 .add(' that consumes input to ')
87 .add(matchState['result'].position.toString()) 81 .add(matchState['result'].position.toString())
88 .add(' instead of ') 82 .add(' instead of ')
89 .add(position.toString()); 83 .add(position.toString());
90 return description; 84 return description;
91 } 85 }
92 throw new Exception('Internal matcher error'); 86 throw new Exception('Internal matcher error');
93 } 87 }
94 } 88 }
OLDNEW
« no previous file with comments | « packages/petitparser/lib/src/smalltalk/grammar.dart ('k') | packages/petitparser/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698