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

Unified Diff: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « petitparser/lib/src/smalltalk/grammar.dart ('k') | petitparser/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: petitparser/lib/test.dart
diff --git a/petitparser/lib/test.dart b/petitparser/lib/test.dart
deleted file mode 100644
index fb681f8287741d0b1c646f63d034920406809cbd..0000000000000000000000000000000000000000
--- a/petitparser/lib/test.dart
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * This package contains matches to write tests for parsers.
- *
- * Examples:
- *
- * var json = new JsonParser();
- *
- * // verifies that the input gets parsed and all input is consumed
- * expect('{"a": 1}', accepts(new JsonParser()));
- *
- * // verifies that the input gets parsed to a dictionary and that all input is consumed
- * expect('{"a": 1}', parses(new JsonParser(), {'a': 1}));
- */
-
-library test_util;
-
-import 'package:matcher/matcher.dart';
-import 'package:petitparser/petitparser.dart' hide predicate;
-
-/**
- * Returns a matcher that succeeds if the [parser] accepts the input.
- */
-Matcher accept(Parser parser) {
- return parse(parser, predicate((value) => true, 'input'));
-}
-
-/**
- * Returns a matcher that succeeds if the [parser] succeeds and accepts the provided [matcher].
- */
-Matcher parse(Parser parser, matcher, [int position = -1]) {
- return new _Parse(parser, wrapMatcher(matcher), position);
-}
-
-class _Parse extends Matcher {
-
- final Parser parser;
- final Matcher matcher;
- final int position;
-
- _Parse(this.parser, this.matcher, this.position);
-
- @override
- bool matches(item, Map matchState) {
- Result result = parser.parse(item);
- if (result.isFailure) {
- addStateInfo(matchState, {'reason': 'failure', 'result': result});
- return false;
- }
- if (!matcher.matches(result.value, matchState)) {
- addStateInfo(matchState, {'reason': 'matcher', 'result': result});
- return false;
- }
- if (position >= 0 && position != result.value) {
- addStateInfo(matchState, {'reason': 'position', 'result': result});
- return false;
- }
- return true;
- }
-
- @override
- Description describe(Description description) {
- return description.add('"$parser" accepts ').addDescriptionOf(matcher);
- }
-
- @override
- Description describeMismatch(item, Description description, Map matchState, bool verbose) {
- description.add('"$parser" produces "${matchState['result']}"');
- switch (matchState['reason']) {
- case 'failure':
- description.add(' which is not accepted');
- return description;
- case 'matcher':
- description.add(' which parse result ');
- var subDescription = new StringDescription();
- matcher.describeMismatch(matchState['result'].value, subDescription,
- matchState['state'], verbose);
- if (subDescription.length > 0) {
- description.add(subDescription.toString());
- } else {
- description.add('doesn\'t match');
- matcher.describe(description);
- }
- return description;
- case 'position':
- description
- .add(' that consumes input to ')
- .add(matchState['result'].position.toString())
- .add(' instead of ')
- .add(position.toString());
- return description;
- }
- throw new Exception('Internal matcher error');
- }
-}
« no previous file with comments | « petitparser/lib/src/smalltalk/grammar.dart ('k') | petitparser/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698