-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoney2_test.dart
50 lines (45 loc) · 1.66 KB
/
money2_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'package:test/test.dart';
import 'package:money2/money2.dart';
void main() {
const maxScale = 18;
const maxInts = 18;
setUp(() {
for (var scale = 0; scale <= maxScale; scale++) {
final c = Currency.create('C$scale', scale, symbol: '=$scale=');
Currencies().register(c);
}
});
test('scale 0-$maxScale test', () {
for (var scale = 0; scale <= maxScale; scale++) {
final c = Currencies().find('C$scale');
expect(c, isNotNull);
final str = scale == 0 ? '1' : '1.${'0' * (scale - 1)}1';
final fmt = scale == 0 ? 'S#' : 'S#.${'#' * scale}';
expect(Money.parseWithCurrency(str, c!).format(fmt), '=$scale=$str',
reason: 'Failed with $scale scale');
}
});
test('integers 0-$maxInts test', () {
for (var ints = 0; ints <= maxInts; ints++) {
final c = Currencies().find('C0');
expect(c, isNotNull);
final str = ints == 0 ? '0' : '9' * ints;
final fmt = 'S#';
expect(Money.parseWithCurrency(str, c!).format(fmt), '=0=$str',
reason: 'Failed with $ints ints');
}
});
test('scale 0-$maxScale and integers 0-$maxInts test', () {
for (var scale = 0; scale <= maxScale; scale++) {
for (var ints = 0; ints <= maxInts; ints++) {
final c = Currencies().find('C$scale');
expect(c, isNotNull);
final intsStr = ints == 0 ? '0' : '9' * ints;
final str = scale == 0 ? intsStr : '$intsStr.${'0' * (scale - 1)}1';
final fmt = scale == 0 ? 'S#' : 'S#.${'#' * scale}';
expect(Money.parseWithCurrency(str, c!).format(fmt), '=$scale=$str',
reason: 'Failed with $scale scale, $ints ints');
}
}
});
}