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

Unified Diff: packages/petitparser/test/debug_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 | « packages/petitparser/test/dart_test.dart ('k') | packages/petitparser/test/json_benchmark.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/petitparser/test/debug_test.dart
diff --git a/packages/petitparser/test/debug_test.dart b/packages/petitparser/test/debug_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c31af68bcdbea6baff27da76c1519555dcdf77e7
--- /dev/null
+++ b/packages/petitparser/test/debug_test.dart
@@ -0,0 +1,146 @@
+library petitparser.test.debug_test;
+
+import 'package:test/test.dart';
+
+import 'package:petitparser/petitparser.dart';
+import 'package:petitparser/debug.dart';
+
+final identifier = letter() & word().star();
+
+main() {
+ group('continuation', () {
+ test('delegation', () {
+ var parser = new ContinuationParser(digit(), (continuation, context) {
+ return continuation(context);
+ });
+ expect(parser.parse('1').isSuccess, isTrue);
+ expect(parser.parse('a').isSuccess, isFalse);
+ });
+ test('divertion', () {
+ var parser = new ContinuationParser(digit(), (continuation, context) {
+ return letter().parseOn(context);
+ });
+ expect(parser.parse('1').isSuccess, isFalse);
+ expect(parser.parse('a').isSuccess, isTrue);
+ });
+ test('resume', () {
+ var capture = new List();
+ var parser = new ContinuationParser(digit(), (continuation, Context context) {
+ capture.add([continuation, context]);
+ // we have to return something for now
+ return context.failure('Abort');
+ });
+ // execute the parser twice to collect the continuations
+ expect(parser.parse('1').isSuccess, isFalse);
+ expect(parser.parse('a').isSuccess, isFalse);
+ // later we can execute the captured continuations
+ expect(capture[0][0](capture[0][1]).isSuccess, isTrue);
+ expect(capture[1][0](capture[1][1]).isSuccess, isFalse);
+ // of course the continuations can be resumed multiple times
+ expect(capture[0][0](capture[0][1]).isSuccess, isTrue);
+ expect(capture[1][0](capture[1][1]).isSuccess, isFalse);
+ });
+ test('success', () {
+ var parser = new ContinuationParser(digit(), (continuation, Context context) {
+ return context.success('Always succeed');
+ });
+ expect(parser.parse('1').isSuccess, isTrue);
+ expect(parser.parse('a').isSuccess, isTrue);
+ });
+ test('failure', () {
+ var parser = new ContinuationParser(digit(), (continuation, Context context) {
+ return context.failure('Always fail');
+ });
+ expect(parser.parse('1').isSuccess, isFalse);
+ expect(parser.parse('a').isSuccess, isFalse);
+ });
+ test('copy', () {
+ var parser = new ContinuationParser(digit(), (continuation, context) {
+ return continuation(context);
+ });
+ var copy = parser.copy();
+ expect(copy.parse('1').isSuccess, isTrue);
+ expect(copy.parse('a').isSuccess, isFalse);
+ });
+ });
+ group('trace', () {
+ test('success', () {
+ var lines = new List();
+ expect(trace(identifier, (line) => lines.add(line)).parse('a').isSuccess, isTrue);
+ expect(lines, [
+ 'Instance of \'SequenceParser\'',
+ ' Instance of \'CharacterParser\'[letter expected]',
+ ' Success[1:2]: a',
+ ' Instance of \'PossessiveRepeatingParser\'[0..*]',
+ ' Instance of \'CharacterParser\'[letter or digit expected]',
+ ' Failure[1:2]: letter or digit expected',
+ ' Success[1:2]: []',
+ 'Success[1:2]: [a, []]'
+ ]);
+ });
+ test('failure', () {
+ var lines = new List();
+ expect(trace(identifier, (line) => lines.add(line)).parse('1').isFailure, isTrue);
+ expect(lines, [
+ 'Instance of \'SequenceParser\'',
+ ' Instance of \'CharacterParser\'[letter expected]',
+ ' Failure[1:1]: letter expected',
+ 'Failure[1:1]: letter expected'
+ ]);
+ });
+ });
+ group('profile', () {
+ test('success', () {
+ var lines = new List();
+ expect(profile(identifier, (line) => lines.add(line))
+ .parse('ab123').isSuccess, isTrue);
+ lines = lines
+ .map((row) => row.split('\t'))
+ .map((row) => [int.parse(row[0]), int.parse(row[1]), row[2]]);
+ expect(lines, hasLength(4));
+ expect(lines.every((row) => row[1] >= 0), isTrue);
+ expect(lines.firstWhere((row) => row[2].indexOf('SequenceParser') > 0)[0], 1);
+ expect(lines.firstWhere((row) => row[2].indexOf('letter expected') > 0)[0], 1);
+ expect(lines.firstWhere((row) => row[2].indexOf('PossessiveRepeatingParser') > 0)[0], 1);
+ expect(lines.firstWhere((row) => row[2].indexOf('letter or digit expected') > 0)[0], 5);
+ });
+ test('failure', () {
+ var lines = new List();
+ expect(profile(identifier, (line) => lines.add(line)).parse('1').isFailure, isTrue);
+ lines = lines
+ .map((row) => row.split('\t'))
+ .map((row) => [int.parse(row[0]), int.parse(row[1]), row[2]]);
+ expect(lines, hasLength(4));
+ expect(lines.every((row) => row[1] >= 0), isTrue);
+ expect(lines.firstWhere((row) => row[2].indexOf('SequenceParser') > 0)[0], 1);
+ expect(lines.firstWhere((row) => row[2].indexOf('letter expected') > 0)[0], 1);
+ expect(lines.firstWhere((row) => row[2].indexOf('PossessiveRepeatingParser') > 0)[0], 0);
+ expect(lines.firstWhere((row) => row[2].indexOf('letter or digit expected') > 0)[0], 0);
+ });
+ });
+ group('progress', () {
+ test('success', () {
+ var lines = new List();
+ expect(progress(identifier, (line) => lines.add(line))
+ .parse('ab123').isSuccess, isTrue);
+ expect(lines, [
+ '* Instance of \'SequenceParser\'',
+ '* Instance of \'CharacterParser\'[letter expected]',
+ '** Instance of \'PossessiveRepeatingParser\'[0..*]',
+ '** Instance of \'CharacterParser\'[letter or digit expected]',
+ '*** Instance of \'CharacterParser\'[letter or digit expected]',
+ '**** Instance of \'CharacterParser\'[letter or digit expected]',
+ '***** Instance of \'CharacterParser\'[letter or digit expected]',
+ '****** Instance of \'CharacterParser\'[letter or digit expected]'
+ ]);
+ });
+ test('failure', () {
+ var lines = new List();
+ expect(progress(identifier, (line) => lines.add(line)).parse('1').isFailure, isTrue);
+ expect(lines, [
+ '* Instance of \'SequenceParser\'',
+ '* Instance of \'CharacterParser\'[letter expected]'
+ ]);
+ });
+ });
+}
« no previous file with comments | « packages/petitparser/test/dart_test.dart ('k') | packages/petitparser/test/json_benchmark.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698