Skip to content

Commit ac1144e

Browse files
authored
[record_use] Large ints (dart-lang#3227)
Bug: * dart-lang#3220
1 parent 5cc737d commit ac1144e

2 files changed

Lines changed: 70 additions & 2 deletions

File tree

‎pkgs/record_use/test/double_constant_test.dart‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:convert';
6+
57
import 'package:record_use/record_use.dart';
68
import 'package:record_use/src/canonicalization_context.dart';
79
import 'package:test/test.dart';
@@ -41,8 +43,10 @@ void main() {
4143
instances: {},
4244
);
4345

44-
final json = recordings.toJson();
45-
final roundTripped = Recordings.fromJson(json);
46+
final json = jsonEncode(recordings.toJson());
47+
final roundTripped = Recordings.fromJson(
48+
jsonDecode(json) as Map<String, Object?>,
49+
);
4650

4751
final roundTrippedConstant =
4852
(roundTripped.calls.values.first.first as CallWithArguments)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:convert';
6+
7+
import 'package:record_use/record_use.dart';
8+
import 'package:test/test.dart';
9+
10+
void main() {
11+
group('IntConstant', () {
12+
test('serialization round-trip', () {
13+
final constants = [
14+
const IntConstant(0),
15+
const IntConstant(1),
16+
const IntConstant(-1),
17+
const IntConstant(42),
18+
const IntConstant(-42),
19+
// 53-bit limit (max precise integer in 64-bit float)
20+
const IntConstant(9007199254740991), // 2^53 - 1
21+
const IntConstant(9007199254740992), // 2^53
22+
const IntConstant(9007199254740993), // 2^53 + 1
23+
// 64-bit signed limits
24+
const IntConstant(9223372036854775807), // 2^63 - 1
25+
const IntConstant(-9223372036854775808), // -2^63
26+
// Interesting bit patterns
27+
const IntConstant(0xAAAAAAAAAAAAAAAA),
28+
const IntConstant(0x5555555555555555),
29+
const IntConstant(0x7FFFFFFFFFFFFFFF),
30+
const IntConstant(0x8000000000000000),
31+
const IntConstant(0xFF00FF00FF00FF00),
32+
];
33+
34+
for (final constant in constants) {
35+
final recordings = Recordings(
36+
calls: {
37+
const Definition('package:a/a.dart', [Name('foo')]): [
38+
CallWithArguments(
39+
positionalArguments: [constant],
40+
namedArguments: const {},
41+
loadingUnit: const LoadingUnit('1'),
42+
),
43+
],
44+
},
45+
instances: const {},
46+
);
47+
48+
final json = jsonEncode(recordings.toJson());
49+
final roundTripped = Recordings.fromJson(
50+
jsonDecode(json) as Map<String, Object?>,
51+
);
52+
53+
final roundTrippedConstant =
54+
(roundTripped.calls.values.first.first as CallWithArguments)
55+
.positionalArguments
56+
.first
57+
as IntConstant;
58+
59+
expect(roundTrippedConstant.value, equals(constant.value));
60+
expect(roundTrippedConstant, equals(constant));
61+
}
62+
});
63+
});
64+
}

0 commit comments

Comments
 (0)