Skip to content

Commit 861fd1e

Browse files
MarkzipanCommit Queue
authored andcommitted
[test] Adding a level of indirection for more clarity in constant identity tests.
Change-Id: I9aa6c6bf278e8c8357d416d1a25be1eda4a4bf21 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398761 Commit-Queue: Mark Zhou <[email protected]> Reviewed-by: Nate Biggs <[email protected]>
1 parent 4c1d453 commit 861fd1e

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

tests/hot_reload/constant_identical/main.0.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ class Fruit {
1616

1717
var x;
1818

19+
helper() {
20+
return const Fruit('Pear');
21+
}
22+
1923
Future<void> main() async {
2024
x = const Fruit('Pear');
2125
Expect.equals('Pear', x.toString());
26+
Expect.identical(x, helper());
27+
2228
await hotReload();
2329
Expect.equals('Pear', x.toString());
2430
Expect.identical(x, const Fruit('Pear'));
31+
Expect.identical(x, helper());
2532
}

tests/hot_reload/constant_identical/main.1.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ class Fruit {
1616

1717
var x;
1818

19+
helper() {
20+
return const Fruit('Pear');
21+
}
22+
1923
Future<void> main() async {
2024
x = const Fruit('Pear');
2125
Expect.equals('Pear', x.toString());
26+
Expect.identical(x, helper());
27+
2228
await hotReload();
2329
Expect.equals('Pear', x.toString());
2430
Expect.identical(x, const Fruit('Pear'));
31+
Expect.identical(x, helper());
2532
}
2633
/** DIFF **/
2734
/*
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2024, 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 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/26f2ff4f11f56841fc5a250231ef7d49f01eb234/runtime/vm/isolate_reload_test.cc#L2604
10+
// Extended with logic to check for non-identity.
11+
12+
class Fruit {
13+
final String name;
14+
const Fruit(this.name);
15+
String toString() => name;
16+
}
17+
18+
var x;
19+
20+
helper() {
21+
return const Fruit('Pear');
22+
}
23+
24+
Future<void> main() async {
25+
x = const Fruit('Pear');
26+
Expect.equals('Pear', x.toString());
27+
Expect.identical(x, helper());
28+
29+
await hotReload();
30+
Expect.equals('Pear', x.toString());
31+
Expect.identical(x, const Fruit('Pear'));
32+
Expect.notIdentical(x, helper());
33+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2024, 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 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/26f2ff4f11f56841fc5a250231ef7d49f01eb234/runtime/vm/isolate_reload_test.cc#L2604
10+
// Extended with logic to check for non-identity.
11+
12+
class Fruit {
13+
final String name;
14+
final String field = 'field';
15+
const Fruit(this.name);
16+
String toString() => name;
17+
}
18+
19+
var x;
20+
21+
helper() {
22+
return const Fruit('Pear');
23+
}
24+
25+
Future<void> main() async {
26+
x = const Fruit('Pear');
27+
Expect.equals('Pear', x.toString());
28+
Expect.identical(x, helper());
29+
30+
await hotReload();
31+
Expect.equals('Pear', x.toString());
32+
Expect.identical(x, const Fruit('Pear'));
33+
Expect.notIdentical(x, helper());
34+
}
35+
/** DIFF **/
36+
/*
37+
@@ -11,6 +11,7 @@
38+
39+
class Fruit {
40+
final String name;
41+
+ final String field = 'field';
42+
const Fruit(this.name);
43+
String toString() => name;
44+
}
45+
*/

0 commit comments

Comments
 (0)