Skip to content

Commit 4bf0049

Browse files
authored
Add testing for the set literals experiment (#1928)
* Beginning of set literals tests * Verify set literals with test and clean up a lint
1 parent 93e5da1 commit 4bf0049

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

test/model_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void main() {
5353
PackageGraph packageGraph;
5454
PackageGraph packageGraphSmall;
5555
PackageGraph packageGraphErrors;
56+
PackageGraph packageGraphExperiments;
5657
PackageGraph ginormousPackageGraph;
5758
Library exLibrary;
5859
Library fakeLibrary;
@@ -67,6 +68,7 @@ void main() {
6768
packageGraph = utils.testPackageGraph;
6869
packageGraphSmall = utils.testPackageGraphSmall;
6970
packageGraphErrors = utils.testPackageGraphErrors;
71+
packageGraphExperiments = utils.testPackageGraphExperiments;
7072
ginormousPackageGraph = utils.testPackageGraphGinormous;
7173
exLibrary = packageGraph.libraries.firstWhere((lib) => lib.name == 'ex');
7274
errorLibrary = packageGraphErrors.libraries
@@ -82,6 +84,40 @@ void main() {
8284
sdkAsPackageGraph = utils.testPackageGraphSdk;
8385
});
8486

87+
// Experimental features not yet enabled by default. Move tests out of this block
88+
// when the feature is enabled by default.
89+
group('Experiments', () {
90+
Library main;
91+
TopLevelVariable aComplexSet, inferredTypeSet, specifiedSet, untypedMap, typedSet;
92+
93+
setUpAll(() {
94+
main = packageGraphExperiments.libraries.firstWhere((lib) => lib.name == 'main');
95+
aComplexSet = main.constants.firstWhere((v) => v.name == 'aComplexSet');
96+
inferredTypeSet = main.constants.firstWhere((v) => v.name == 'inferredTypeSet');
97+
specifiedSet = main.constants.firstWhere((v) => v.name == 'specifiedSet');
98+
untypedMap = main.constants.firstWhere((v) => v.name == 'untypedMap');
99+
typedSet = main.constants.firstWhere((v) => v.name == 'typedSet');
100+
});
101+
102+
test('Set literals test', () {
103+
expect(aComplexSet.modelType.name, equals('Set'));
104+
expect(aComplexSet.modelType.typeArguments.map((a) => a.name).toList(), equals(['AClassContainingLiterals']));
105+
expect(aComplexSet.constantValue, equals('const {const AClassContainingLiterals(3, 5)}'));
106+
expect(inferredTypeSet.modelType.name, equals('Set'));
107+
expect(inferredTypeSet.modelType.typeArguments.map((a) => a.name).toList(), equals(['num']));
108+
expect(inferredTypeSet.constantValue, equals('const {1, 2.5, 3}'));
109+
expect(specifiedSet.modelType.name, equals('Set'));
110+
expect(specifiedSet.modelType.typeArguments.map((a) => a.name).toList(), equals(['int']));
111+
expect(specifiedSet.constantValue, equals('const {}'));
112+
expect(untypedMap.modelType.name, equals('Map'));
113+
expect(untypedMap.modelType.typeArguments.map((a) => a.name).toList(), equals(['dynamic', 'dynamic']));
114+
expect(untypedMap.constantValue, equals('const {}'));
115+
expect(typedSet.modelType.name, equals('Set'));
116+
expect(typedSet.modelType.typeArguments.map((a) => a.name).toList(), equals(['String']));
117+
expect(typedSet.constantValue, equals('const <String> {}'));
118+
});
119+
});
120+
85121
group('Tools', () {
86122
Class toolUser;
87123
Class _NonCanonicalToolUser, CanonicalToolUser, PrivateLibraryToolUser;

test/src/utils.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ final RegExp observatoryPortRegexp =
2121
Directory sdkDir;
2222
PackageMeta sdkPackageMeta;
2323
PackageGraph testPackageGraph;
24+
PackageGraph testPackageGraphExperiments;
2425
PackageGraph testPackageGraphGinormous;
2526
PackageGraph testPackageGraphSmall;
2627
PackageGraph testPackageGraphErrors;
2728
PackageGraph testPackageGraphSdk;
2829

2930
final Directory testPackageBadDir = new Directory('testing/test_package_bad');
3031
final Directory testPackageDir = new Directory('testing/test_package');
32+
final Directory testPackageExperimentsDir = new Directory('testing/test_package_experiments');
3133
final Directory testPackageMinimumDir =
3234
new Directory('testing/test_package_minimum');
3335
final Directory testPackageWithEmbedderYaml =
@@ -78,6 +80,11 @@ void init({List<String> additionalArguments}) async {
7880
additionalArguments:
7981
additionalArguments + ['--auto-include-dependencies']);
8082

83+
testPackageGraphExperiments = await bootBasicPackage(
84+
'testing/test_package_experiments', [],
85+
additionalArguments: additionalArguments + ['--enable-experiment', 'set-literals']
86+
);
87+
8188
testPackageGraphSmall = await bootBasicPackage(
8289
'testing/test_package_small', [],
8390
additionalArguments: additionalArguments);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const inferredTypeSet = {1, 2.5, 3};
2+
const Set<int> specifiedSet = const {};
3+
const untypedMap = {};
4+
const typedSet = <String>{};
5+
6+
class AClassContainingLiterals {
7+
final int value1;
8+
final int value2;
9+
10+
const AClassContainingLiterals(this.value1, this.value2);
11+
12+
@override
13+
bool operator==(Object other) => other is AClassContainingLiterals && value1 == other.value1;
14+
}
15+
16+
const aComplexSet = {AClassContainingLiterals(3, 5)};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: test_package_experiments
2+
version: 0.0.1
3+
description: Experimental flags are tested here.

tool/grind.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,6 @@ final _generated_files_list = <String>[
801801
Future<void> checkBuild() async {
802802
var originalFileContents = new Map<String, String>();
803803
var differentFiles = <String>[];
804-
var launcher = new SubprocessLauncher('check-build');
805804

806805
// Load original file contents into memory before running the builder;
807806
// it modifies them in place.

0 commit comments

Comments
 (0)