2021-05-14 06:11:50 +00:00
|
|
|
import 'package:angel3_combinator/angel3_combinator.dart';
|
2021-03-17 23:04:36 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'common.dart';
|
|
|
|
|
2021-05-18 13:15:28 +00:00
|
|
|
void main() {
|
2021-03-17 23:04:36 +00:00
|
|
|
var number = chain([
|
2021-05-07 04:42:02 +00:00
|
|
|
match(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-05-11 09:03:52 +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-05-11 09:03:52 +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
|
|
|
});
|
|
|
|
}
|