/
type_test.bigint_test.dart
106 lines (82 loc) · 2.8 KB
/
type_test.bigint_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// ignore_for_file: prefer_const_declarations
@TestOn('vm')
import 'dart:convert';
import 'package:test/test.dart';
import '../test_utils.dart';
import 'input.type_bigint.dart';
void main() {
group('non-nullable', () {
test('round trip', () {
final object = SimpleClass.fromJson(_defaultInput);
final encoded = loudEncode(object);
expect(encoded, loudEncode(_defaultOutput));
final object2 = SimpleClass.fromJson(
jsonDecode(encoded) as Map<String, Object?>,
);
expect(loudEncode(object2), encoded);
});
test('round trip null', () {
expect(
() => loudEncode(SimpleClass.fromJson({})),
throwsTypeError,
);
});
test('round trip alternate values', () {
final object = SimpleClass.fromJson(_nonDefaultJson);
final encoded = loudEncode(object);
expect(encoded, loudEncode(_nonDefaultJson));
expect(encoded, isNot(loudEncode(_defaultOutput)));
final object2 = SimpleClass.fromJson(
jsonDecode(encoded) as Map<String, Object?>,
);
expect(loudEncode(object2), encoded);
});
}); // end non-nullable group
group('nullable', () {
test('round trip', () {
final object = SimpleClassNullable.fromJson(_defaultInput);
final encoded = loudEncode(object);
expect(encoded, loudEncode(_defaultOutput));
final object2 = SimpleClassNullable.fromJson(
jsonDecode(encoded) as Map<String, Object?>,
);
expect(loudEncode(object2), encoded);
});
test('round trip null', () {
final object = SimpleClassNullable.fromJson({});
final encoded = loudEncode(object);
expect(encoded, loudEncode(_nullableDefaultOutput));
final object2 = SimpleClassNullable.fromJson(
jsonDecode(encoded) as Map<String, Object?>,
);
expect(loudEncode(object2), encoded);
});
test('round trip alternate values', () {
final object = SimpleClassNullable.fromJson(_nonDefaultJson);
final encoded = loudEncode(object);
expect(encoded, loudEncode(_nonDefaultJson));
expect(encoded, isNot(loudEncode(_defaultOutput)));
final object2 = SimpleClassNullable.fromJson(
jsonDecode(encoded) as Map<String, Object?>,
);
expect(loudEncode(object2), encoded);
});
}); // end nullable group
}
final _defaultValue = '12345';
final _altValue = '67890';
final _defaultInput = <String, Object?>{
'value': _defaultValue,
};
final _defaultOutput = {
'value': _defaultValue,
};
final _nullableDefaultOutput = {
'value': null,
};
final _nonDefaultJson = {
'value': _altValue,
};