64 lines
2 KiB
Dart
64 lines
2 KiB
Dart
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
import 'package:halkyon_app/halkyon_app.dart';
|
||
|
|
|
||
|
|
// A limit as the operator types it into the grant's sheet (Halkyon Learn's
|
||
|
|
// ADR 0021, D38): money in millionths, tokens whole.
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
const money = AssistantLimitUnit.money;
|
||
|
|
const tokens = AssistantLimitUnit.tokens;
|
||
|
|
|
||
|
|
test('reads money as millionths, with a point or a comma', () {
|
||
|
|
expect(limitFromText('5', money), 5000000);
|
||
|
|
expect(limitFromText('2.50', money), 2500000);
|
||
|
|
expect(limitFromText('2,5', money), 2500000);
|
||
|
|
expect(limitFromText('0.000001', money), 1);
|
||
|
|
expect(limitFromText(' 1 000.25 ', money), 1000250000);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('reads tokens whole, grouped by thousands or not', () {
|
||
|
|
expect(limitFromText('1000000', tokens), 1000000);
|
||
|
|
expect(limitFromText('1,000,000', tokens), 1000000);
|
||
|
|
expect(limitFromText('1.000.000', tokens), 1000000);
|
||
|
|
expect(limitFromText('1_000_000', tokens), 1000000);
|
||
|
|
expect(limitFromText('250', tokens), 250);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('reads nothing typed as no limit', () {
|
||
|
|
expect(limitFromText('', money), isNull);
|
||
|
|
expect(limitFromText(' ', tokens), isNull);
|
||
|
|
});
|
||
|
|
|
||
|
|
test("refuses what isn't an amount", () {
|
||
|
|
for (final (text, unit) in [
|
||
|
|
('-1', money),
|
||
|
|
('1.5.0', money),
|
||
|
|
('0.0000001', money),
|
||
|
|
('five', money),
|
||
|
|
('1e6', money),
|
||
|
|
('1234567890123', money),
|
||
|
|
('1.5', tokens),
|
||
|
|
('1,00', tokens),
|
||
|
|
('1,000.000', tokens),
|
||
|
|
('-5', tokens),
|
||
|
|
('1234567890123', tokens),
|
||
|
|
]) {
|
||
|
|
expect(
|
||
|
|
() => limitFromText(text, unit),
|
||
|
|
throwsFormatException,
|
||
|
|
reason: '$text in ${unit.name}',
|
||
|
|
);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('writes a limit as it is read back', () {
|
||
|
|
expect(limitText(null, money), '');
|
||
|
|
expect(limitText(5000000, money), '5');
|
||
|
|
expect(limitText(2500000, money), '2.5');
|
||
|
|
expect(limitText(1, money), '0.000001');
|
||
|
|
expect(limitText(1000000, tokens), '1000000');
|
||
|
|
for (final micros in [0, 1, 990000, 12345678]) {
|
||
|
|
expect(limitFromText(limitText(micros, money), money), micros);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|