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!));
|
2021-03-31 06:33:31 +00:00
|
|
|
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!);
|
2021-03-31 06:33:31 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|