Skip to content

Commit

Permalink
#1243 Runtime type checks added to Spread collections tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Dec 23, 2021
1 parent a2335af commit fe659c4
Show file tree
Hide file tree
Showing 32 changed files with 281 additions and 26 deletions.
3 changes: 2 additions & 1 deletion LanguageFeatures/Spread-collections/Ambiguity_A02_t06.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
/// @description Checks that empty collection is a map.
/// @author [email protected]

import "../../Utils/expect.dart";

main() {
Expect.isTrue({} is Map);
Expect.runtimeIsType<Map>({});

dynamic map = {};
Expect.isTrue(map is Map);
Expect.runtimeIsType<Map>(map);
}
3 changes: 2 additions & 1 deletion LanguageFeatures/Spread-collections/Ambiguity_A03_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/// @description Checks that [setOrMapLiteral] has one type argument, it's a set.
/// @author [email protected]

import "../../Utils/expect.dart";

main() {
Expand All @@ -25,7 +24,9 @@ main() {

var res1 = <int>{...aSet};
Expect.isTrue(res1 is Set);
Expect.runtimeIsType<Set>(res1);

var res2 = <Object>{...aList};
Expect.isTrue(res2 is Set);
Expect.runtimeIsType<Object>(res2);
}
3 changes: 2 additions & 1 deletion LanguageFeatures/Spread-collections/Ambiguity_A03_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/// @description Checks that [setOrMapLiteral] has one type argument, it's a set.
/// @author [email protected]

import "../../Utils/expect.dart";

main() {
Expand All @@ -25,7 +24,9 @@ main() {

var res1 = <int>{...?aSet};
Expect.isTrue(res1 is Set);
Expect.runtimeIsType<Set>(res1);

var res2 = <Object>{...?aList};
Expect.isTrue(res2 is Set);
Expect.runtimeIsType<Set>(res2);
}
3 changes: 2 additions & 1 deletion LanguageFeatures/Spread-collections/Ambiguity_A03_t05.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/// @description Checks that [setOrMapLiteral] has one type argument, it's a set.
/// @author [email protected]

import "../../Utils/expect.dart";

main() {
Expand All @@ -26,9 +25,11 @@ main() {

var res1 = <int>{...aSet};
Expect.isTrue(res1 is Set);
Expect.runtimeIsType<Set>(res1);

var res2 = <Object>{...aList};
Expect.isTrue(res2 is Set);
Expect.runtimeIsType<Set>(res2);

var res3;
Expect.throws(() => res3 = <int>{...aMap});
Expand Down
1 change: 1 addition & 0 deletions LanguageFeatures/Spread-collections/Ambiguity_A04_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ main() {

var res = <int, int>{...aMap};
Expect.isTrue(res is Map);
Expect.runtimeIsType<Map>(res);
}
1 change: 1 addition & 0 deletions LanguageFeatures/Spread-collections/Ambiguity_A04_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ main() {

var res = <int, int>{...?aMap};
Expect.isTrue(res is Map);
Expect.runtimeIsType<Map>(res);
}
1 change: 1 addition & 0 deletions LanguageFeatures/Spread-collections/Ambiguity_A04_t05.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ main() {

var res1 = <int, int>{...?aMap};
Expect.isTrue(res1 is Map);
Expect.runtimeIsType<Map>(res1);

var res2;
Expect.throws(() => res2 = <int, int>{...aList});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/// or set.
/// @author [email protected]

import "../../Utils/expect.dart";

const l1 = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/// constant list or set.
/// @author [email protected]

import "../../Utils/expect.dart";

class A {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/// element is not potentially constant list or set.
/// @author [email protected]

class MyClass {
final String a;
const MyClass(Object o) : a = o as String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/// element is not potentially constant list or set.
/// @author [email protected]

class A {
const A();
}
Expand Down
2 changes: 0 additions & 2 deletions LanguageFeatures/Spread-collections/ConstSpreads_A09_t10.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/// constant list or set.
/// @author [email protected]

import "../../Utils/expect.dart";

Set emptyset = {};
Expand All @@ -29,7 +28,6 @@ class MyClass {
const MyClass(Object o) : a = o as String;
}


main() {
const Set s1 = {...(A() is B ? [12345] : [])};
Expect.setEquals(emptyset, s1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class MyClass {
const MyClass(Object o) : a = o as String;
}


main() {
const Set l4 = {...(MyClass(12345) is MyClass ? [12] : [])};
// ^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/// element is not a potentially constant list or set.
/// @author [email protected]

class A {
const A();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/// constant map.
/// @author [email protected]

import "../../Utils/expect.dart";

class A {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/// constant map.
/// @author [email protected]

class MyClass {
const MyClass();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/// potentially constant list or set or [null].
/// @author [email protected]

class MyClass {
final String a;
const MyClass(Object o) : a = o as String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/// potentially constant list or set or [null].
/// @author [email protected]

class A {
const A();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/// potentially constant list or set.
/// @author [email protected]

class A {
const A();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/// potentially constant list or set.
/// @author [email protected]

class MyClass {
final String a;
const MyClass(Object o) : a = o as String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/// potentially constant map or [null].
/// @author [email protected]

class A {
const A();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/// potentially constant map or null.
/// @author [email protected]

class MyClass {
final String a;
const MyClass(Object o) : a = o as String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
/// @description Checks that instance of [List<E>] is created for a list literal
/// @author [email protected]

import "../../Utils/expect.dart";

main() {
Expand All @@ -30,4 +29,8 @@ main() {
Expect.isTrue(<String>[...?list3] is List<String>);
Expect.isTrue(<int>[...?list3] is List<int>);
Expect.isTrue([...list4] is List<Object?>);
Expect.runtimeIsType<List<String>>(<String>[...list2, "123"]);
Expect.runtimeIsType<List<String>>(<String>[...?list3]);
Expect.runtimeIsType<List<int>>(<int>[...?list3] );
Expect.runtimeIsType<List<Object?>>([...list4]);
}
3 changes: 2 additions & 1 deletion LanguageFeatures/Spread-collections/Syntax_A03_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
/// three or more type arguments.
/// @author [email protected]

import "../../Utils/expect.dart";

main() {
var a;
Expect.isTrue(<int>{} is Set);
Expect.isTrue(<int, int>{} is Map);
Expect.runtimeIsType<Set>(<int>{});
Expect.runtimeIsType<Map>(<int, int>{});
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/// the list literal
/// @author [email protected]

import "../../Utils/expect.dart";

class A {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/// the set literal
/// @author [email protected]

import "../../Utils/expect.dart";

class A {}
Expand All @@ -30,25 +29,32 @@ main() {

Set set1 = <int>{2, 7, ...int_list, 4};
Expect.isTrue(set1 is Set<int>);
Expect.runtimeIsType<Set<int>>(set1);

Set set2 = <A>{a, ...a_list};
Expect.isTrue(set2 is Set<A>);
Expect.runtimeIsType<Set<A>>(set2);

Set set3 = <A>{a, ...b_list};
Expect.isTrue(set3 is Set<A>);
Expect.runtimeIsType<Set<A>>(set3);

Set set4 = <A>{a, c, ...c_list, b};
Expect.isTrue(set4 is Set<A>);
Expect.runtimeIsType<Set<A>>(set4);

Set set5 = <A>{a, b, c, ...c_list, new B(), ...a_list, ...b_list, new A()};
Expect.isTrue(set5 is Set<A>);
Expect.runtimeIsType<Set<A>>(set5);

Set set6 = <B>{b, ...b_list, c, ...c_list};
Expect.isTrue(set6 is Set<B>);
Expect.runtimeIsType<Set<B>>(set6);

Set set7 = {123, "123", null, a, ...a_list, ...?b_list, c, b, ...?c_list,
...str_list, ...int_list, null, 1499, []};
Expect.isTrue(set7 is Set<Object?>);
Expect.runtimeIsType<Set<Object?>>(set7);

Set set8;
Expect.throws(() => set8 = <int>{...str_list});
Expand Down
Loading

0 comments on commit fe659c4

Please sign in to comment.