platform/packages/combinator/test/list_test.dart

23 lines
649 B
Dart
Raw Normal View History

2021-03-17 23:04:36 +00:00
import 'package:combinator/combinator.dart';
import 'package:test/test.dart';
import 'common.dart';
main() {
var number = chain([
2021-03-18 00:00:56 +00:00
match(new RegExp(r'[0-9]+')).value((r) => int.parse(r.span!.text)),
2021-03-17 23:04:36 +00:00
match(',').opt(),
]).first().cast<int>();
var numbers = number.plus();
test('sort', () {
2021-03-18 00:00:56 +00:00
var parser = numbers.sort((a, b) => a!.compareTo(b!));
expect(parser.parse(scan('21,2,3,34,20'))!.value, [2, 3, 20, 21, 34]);
2021-03-17 23:04:36 +00:00
});
test('reduce', () {
2021-03-18 00:00:56 +00:00
var parser = numbers.reduce((a, b) => a! + b!);
expect(parser.parse(scan('21,2,3,34,20'))!.value, 80);
expect(parser.parse(scan('not numbers'))!.value, isNull);
2021-03-17 23:04:36 +00:00
});
}