Skip to content

Commit

Permalink
Add some more stress tests for character parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed Jan 2, 2025
1 parent 8098305 commit 677a3e6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/parser_character_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import 'package:petitparser/src/parser/character/predicates/ranges.dart';
import 'package:petitparser/src/parser/character/predicates/uppercase.dart';
import 'package:petitparser/src/parser/character/predicates/whitespace.dart';
import 'package:petitparser/src/parser/character/predicates/word.dart';
import 'package:petitparser/src/parser/predicate/single_character.dart';
import 'package:petitparser/src/parser/predicate/unicode_character.dart';
import 'package:test/test.dart' hide anyOf;

import 'utils/assertions.dart';
Expand Down Expand Up @@ -601,4 +603,39 @@ void main() {
test('lookup', () => stress(LookupCharPredicate.fromRanges));
test('ranges', () => stress(RangesCharPredicate.fromRanges));
});
group('reader', () {
const predicate = ConstantCharPredicate(true);
test('single character', () {
final parser =
SingleCharacterParser.internal(predicate, 'single character');
for (var code = 0; code < 0xffff; code++) {
final char = String.fromCharCode(code);
expect(parser, isParseSuccess(char, result: char));
}
});
test('any single character', () {
final parser =
AnySingleCharacterParser.internal(predicate, 'any single character');
for (var code = 0; code < 0xffff; code++) {
final char = String.fromCharCode(code);
expect(parser, isParseSuccess(char, result: char));
}
});
test('unicode character', () {
final parser =
UnicodeCharacterParser.internal(predicate, 'unicode character');
for (var code = 0; code < 0x10ffff; code++) {
final char = String.fromCharCode(code);
expect(parser, isParseSuccess(char, result: char));
}
});
test('any unicode character', () {
final parser = AnyUnicodeCharacterParser.internal(
predicate, 'any unicode character');
for (var code = 0; code < 0x10ffff; code++) {
final char = String.fromCharCode(code);
expect(parser, isParseSuccess(char, result: char));
}
});
});
}

0 comments on commit 677a3e6

Please sign in to comment.