-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fixes #1620. Missed experimental flag added * Fixes #1620. Small fixes in patterns tests * Variable pattern test fixed * Fix spec_parser failure
- Loading branch information
Showing
3 changed files
with
65 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
/// @description Checks a logical-and in a variable declaration pattern | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=patterns | ||
// SharedOptions=--enable-experiment=patterns,records | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,24 +23,20 @@ | |
/// print('First field is int $x and second is String $s.'); | ||
/// } | ||
/// ``` | ||
/// @description Check that if the type annotation is omitted then the | ||
/// variable's type is inferred and the pattern matches all values. Test the | ||
/// case when type, `var` and `final` are omitted | ||
/// @description Check that if type, `var` and `final` are all omitted then it | ||
/// is a compile-time error | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=patterns,records | ||
|
||
import "../../Utils/static_type_helper.dart"; | ||
import "../../Utils/expect.dart"; | ||
import "patterns_lib.dart"; | ||
|
||
String testRecord1(Record r, [bool doTypeTest = false]) { | ||
String testRecord1(Record r) { | ||
switch (r) { | ||
case (a, b): | ||
if (doTypeTest) { | ||
a.expectStaticType<Exactly<Object?>>(); | ||
b.expectStaticType<Exactly<Object?>>(); | ||
} | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "($a, $b)"; | ||
default: | ||
return "default"; | ||
|
@@ -50,31 +46,30 @@ String testRecord1(Record r, [bool doTypeTest = false]) { | |
String testRecord2(Record r) { | ||
return switch (r) { | ||
(a, b) => "($a, $b)", | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
_ => "default" | ||
}; | ||
} | ||
|
||
String testRecord3(Record r, [bool doTypeTest = false]) { | ||
String testRecord3(Record r) { | ||
if (r case (a, b)) { | ||
if (doTypeTest) { | ||
a.expectStaticType<Exactly<Object?>>(); | ||
b.expectStaticType<Exactly<Object?>>(); | ||
} | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "($a, $b)"; | ||
} else { | ||
return "default"; | ||
} | ||
} | ||
|
||
String testList1(List l, [bool doTypeTest = false]) { | ||
String testList1(List l) { | ||
switch (l) { | ||
case [a, b]: | ||
if (doTypeTest) { | ||
a.isOdd; | ||
b.substring(0); | ||
Expect.throws(() {a.whatever;}); | ||
Expect.throws(() {b.whatever;}); | ||
} | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "[$a, $b]"; | ||
default: | ||
return "default"; | ||
|
@@ -83,19 +78,19 @@ String testList1(List l, [bool doTypeTest = false]) { | |
|
||
String testList2(List l) { | ||
return switch (l) { | ||
[a, b] => "[$a, $b]", | ||
[a, b] => "[$a, $b]", | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
_ => "default" | ||
}; | ||
} | ||
|
||
String testList3(List l, [bool doTypeTest = false]) { | ||
String testList3(List l) { | ||
if (l case [a, b]) { | ||
if (doTypeTest) { | ||
a.isOdd; | ||
b.substring(0); | ||
Expect.throws(() {a.whatever;}); | ||
Expect.throws(() {b.whatever;}); | ||
} | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "[$a, $b]"; | ||
} else { | ||
return "default"; | ||
|
@@ -105,13 +100,10 @@ String testList3(List l, [bool doTypeTest = false]) { | |
String testMap1(Map m) { | ||
switch (m) { | ||
case {1: a}: | ||
a.isOdd; | ||
Expect.throws(() {a.whatever;}); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "{1: $a}"; | ||
case {2: b}: | ||
b.substring(0); | ||
Expect.throws(() {b.whatever;}); | ||
return "{2: $b}"; | ||
default: | ||
return "default"; | ||
} | ||
|
@@ -120,21 +112,19 @@ String testMap1(Map m) { | |
String testMap2(Map m) { | ||
return switch (m) { | ||
{1: a} => "{1: $a}", | ||
{2: b} => "{2: $b}", | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
_ => "default" | ||
}; | ||
} | ||
|
||
String testMap3(Map m) { | ||
if (m case {1: a}) { | ||
a.isOdd; | ||
Expect.throws(() {a.whatever;}); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "{1: $a}"; | ||
} | ||
if (m case {2: final b}) { | ||
b.substring(0); | ||
Expect.throws(() {b.whatever;}); | ||
return "{2: $b}"; | ||
} else { | ||
return "default"; | ||
} | ||
|
@@ -143,9 +133,10 @@ String testMap3(Map m) { | |
String testObject1(Shape shape) { | ||
switch (shape) { | ||
case Square(area: a): | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "a=$a"; | ||
case Rectangle(area: b): | ||
return "b=$b"; | ||
default: | ||
return "default"; | ||
} | ||
|
@@ -154,98 +145,38 @@ String testObject1(Shape shape) { | |
String testObject2(Shape shape) { | ||
return switch (shape) { | ||
Square(area: a) => "a=$a", | ||
Rectangle(area: b) => "b=$b", | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
_ => "default" | ||
}; | ||
} | ||
|
||
String testObject3(Shape shape) { | ||
if (shape case Square(area: a)) { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "a=$a"; | ||
} | ||
if (shape case Rectangle(area: b)) { | ||
return "b=$b"; | ||
} else { | ||
return "default"; | ||
} | ||
} | ||
|
||
main() { | ||
Expect.equals("(1, x)", testRecord1((1, "x"), true)); | ||
Expect.equals("(1, 2)", testRecord1((1, 2))); | ||
Expect.equals("(true, false)", testRecord1((true, false))); | ||
Expect.equals("default", testRecord1((1, 2, 3))); | ||
Expect.equals("default", testRecord1(("x",))); | ||
|
||
Expect.equals("(1, x)", testRecord2((1, "x"))); | ||
Expect.equals("(1, 2)", testRecord2((1, 2))); | ||
Expect.equals("(true, false)", testRecord2((true, false))); | ||
Expect.equals("default", testRecord2((1, 2, 3))); | ||
Expect.equals("default", testRecord2(("x",))); | ||
|
||
Expect.equals("(1, x)", testRecord3((1, "x"), true)); | ||
Expect.equals("(1, 2)", testRecord3((1, 2))); | ||
Expect.equals("(true, false)", testRecord3((true, false))); | ||
Expect.equals("default", testRecord3((1, 2, 3))); | ||
Expect.equals("default", testRecord3(("x",))); | ||
|
||
Expect.equals("[1, x]", testList1([1, "x"], true)); | ||
Expect.equals("[1, 2]", testList1([1, 2])); | ||
Expect.equals("[true, false]", testList1([true, false])); | ||
Expect.equals("default", testList1([1, 2, 3])); | ||
Expect.equals("default", testList1(["x"])); | ||
|
||
Expect.equals("[1, x]", testList2([1, "x"])); | ||
Expect.equals("[1, 2]", testList2([1, 2])); | ||
Expect.equals("[true, false]", testList2([true, false])); | ||
Expect.equals("default", testList2([1, 2, 3])); | ||
Expect.equals("default", testList2(["x"])); | ||
|
||
Expect.equals("[1, x]", testList3([1, "x"])); | ||
Expect.equals("[1, 2]", testList3([1, 2])); | ||
Expect.equals("[true, false]", testList3([true, false])); | ||
Expect.equals("default", testList3([1, 2, 3])); | ||
Expect.equals("default", testList3(["x"])); | ||
|
||
Expect.equals("{1: 2}", testMap1({1: 2})); | ||
Expect.equals("{1: 3}", testMap1({1: 3, 3: 4})); | ||
Expect.equals("{2: x}", testMap1({2: "x"})); | ||
Expect.equals("{2: true}", testMap1({2: true})); | ||
Expect.equals("default", testMap1({3: 3})); | ||
Expect.equals("default", testMap1({})); | ||
|
||
Expect.equals("{1: 2}", testMap2({1: 2})); | ||
Expect.equals("{1: 3}", testMap2({1: 3, 3: 4})); | ||
Expect.equals("{2: x}", testMap2({2: "x"})); | ||
Expect.equals("{2: true}", testMap2({2: true})); | ||
Expect.equals("default", testMap2({3: 3})); | ||
Expect.equals("default", testMap2({})); | ||
|
||
Expect.equals("{1: 2}", testMap3({1: 2})); | ||
Expect.equals("{1: 3}", testMap3({1: 3, 3: 4})); | ||
Expect.equals("{2: x}", testMap3({2: "x"})); | ||
Expect.equals("{2: true}", testMap3({2: true})); | ||
Expect.equals("default", testMap3({3: 3})); | ||
Expect.equals("default", testMap3({})); | ||
|
||
Expect.equals("a=1.00", testObject1(Square(1))); | ||
Expect.equals("a=4.00", testObject1(Square(2))); | ||
Expect.equals("b=2.00", testObject1(Rectangle(1, 2))); | ||
Expect.equals("b=4.00", testObject1(Rectangle(2, 2))); | ||
Expect.equals("default", testObject1(Circle(1))); | ||
Expect.equals("default", testObject1(Shape())); | ||
|
||
Expect.equals("a=1.00", testObject2(Square(1))); | ||
Expect.equals("a=4.00", testObject2(Square(2))); | ||
Expect.equals("b=2.00", testObject2(Rectangle(1, 2))); | ||
Expect.equals("b=4.00", testObject2(Rectangle(2, 2))); | ||
Expect.equals("default", testObject2(Circle(1))); | ||
Expect.equals("default", testObject2(Shape())); | ||
|
||
Expect.equals("a=1.00", testObject3(Square(1))); | ||
Expect.equals("a=4.00", testObject3(Square(2))); | ||
Expect.equals("b=2.00", testObject3(Rectangle(1, 2))); | ||
Expect.equals("b=4.00", testObject3(Rectangle(2, 2))); | ||
Expect.equals("default", testObject3(Circle(1))); | ||
Expect.equals("default", testObject3(Shape())); | ||
testRecord1((1, "x")); | ||
testRecord2((1, "x")); | ||
testRecord3((1, "x")); | ||
|
||
testList1([1, "x"]); | ||
testList2([1, "x"]); | ||
testList3([1, "x"]); | ||
|
||
testMap1({1: 2}); | ||
testMap2({1: 2}); | ||
testMap3({1: 2}); | ||
|
||
testObject1(Square(1)); | ||
testObject2(Square(1)); | ||
testObject3(Square(1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters