Skip to content

Commit

Permalink
Fixes dart-lang#1620. Small fixes in patterns tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Dec 27, 2022
1 parent 8e0a7b0 commit a6b5e68
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
36 changes: 18 additions & 18 deletions LanguageFeatures/Patterns/variable_A02_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import "patterns_lib.dart";

String testRecord1(Record r, [bool doTypeTest = false]) {
switch (r) {
case (a, b):
case var (a, b):
if (doTypeTest) {
a.expectStaticType<Exactly<Object?>>();
b.expectStaticType<Exactly<Object?>>();
Expand All @@ -49,13 +49,13 @@ String testRecord1(Record r, [bool doTypeTest = false]) {

String testRecord2(Record r) {
return switch (r) {
(a, b) => "($a, $b)",
var (a, b) => "($a, $b)",
_ => "default"
};
}

String testRecord3(Record r, [bool doTypeTest = false]) {
if (r case (a, b)) {
if (r case final (a, b)) {
if (doTypeTest) {
a.expectStaticType<Exactly<Object?>>();
b.expectStaticType<Exactly<Object?>>();
Expand All @@ -68,7 +68,7 @@ String testRecord3(Record r, [bool doTypeTest = false]) {

String testList1(List l, [bool doTypeTest = false]) {
switch (l) {
case [a, b]:
case var [a, b]:
if (doTypeTest) {
a.isOdd;
b.substring(0);
Expand All @@ -83,13 +83,13 @@ String testList1(List l, [bool doTypeTest = false]) {

String testList2(List l) {
return switch (l) {
[a, b] => "[$a, $b]",
var [a, b] => "[$a, $b]",
_ => "default"
};
}

String testList3(List l, [bool doTypeTest = false]) {
if (l case [a, b]) {
if (l case final [a, b]) {
if (doTypeTest) {
a.isOdd;
b.substring(0);
Expand All @@ -104,11 +104,11 @@ String testList3(List l, [bool doTypeTest = false]) {

String testMap1(Map m) {
switch (m) {
case {1: a}:
case var {1: a}:
a.isOdd;
Expect.throws(() {a.whatever;});
return "{1: $a}";
case {2: b}:
case final {2: b}:
b.substring(0);
Expect.throws(() {b.whatever;});
return "{2: $b}";
Expand All @@ -119,19 +119,19 @@ String testMap1(Map m) {

String testMap2(Map m) {
return switch (m) {
{1: a} => "{1: $a}",
{2: b} => "{2: $b}",
var {1: a} => "{1: $a}",
final {2: b} => "{2: $b}",
_ => "default"
};
}

String testMap3(Map m) {
if (m case {1: a}) {
if (m case var {1: a}) {
a.isOdd;
Expect.throws(() {a.whatever;});
return "{1: $a}";
}
if (m case {2: final b}) {
if (m case final {2: final b}) {
b.substring(0);
Expect.throws(() {b.whatever;});
return "{2: $b}";
Expand All @@ -142,9 +142,9 @@ String testMap3(Map m) {

String testObject1(Shape shape) {
switch (shape) {
case Square(area: a):
case var Square(area: a):
return "a=$a";
case Rectangle(area: b):
case final Rectangle(area: b):
return "b=$b";
default:
return "default";
Expand All @@ -153,17 +153,17 @@ String testObject1(Shape shape) {

String testObject2(Shape shape) {
return switch (shape) {
Square(area: a) => "a=$a",
Rectangle(area: b) => "b=$b",
var Square(area: a) => "a=$a",
final Rectangle(area: b) => "b=$b",
_ => "default"
};
}

String testObject3(Shape shape) {
if (shape case Square(area: a)) {
if (shape case var Square(area: a)) {
return "a=$a";
}
if (shape case Rectangle(area: b)) {
if (shape case final Rectangle(area: b)) {
return "b=$b";
} else {
return "default";
Expand Down
12 changes: 6 additions & 6 deletions LanguageFeatures/Patterns/wildcards_A01_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import "../../Utils/expect.dart";
String test1(Record r) {
switch (r) {
case (_, 2, var x):
return "[_, 2, var x]";
return "(_, 2, var x)";
case (String _, _, _):
return "(String _, _, _)";
default:
Expand All @@ -38,15 +38,15 @@ String test1(Record r) {

String test2(Record r) {
return switch (r) {
(_, 2, var x) => "[_, 2, var x]",
(_, 2, var x) => "(_, 2, var x)",
(String _, _, _) => "(String _, _, _)",
_ => "default"
};
}

String test3(Record r) {
if (r case (_, 2, var x)) {
return "[_, 2, var x]";
return "(_, 2, var x)";
}
if (r case (String _, _, _)) {
return "(String _, _, _)";
Expand All @@ -72,17 +72,17 @@ main() {
Expect.throws(() {
var (_, String _, _, num _) = r2;
});
Expect.equals("[_, 2, var x]", test1((1, 2, "3")));
Expect.equals("(_, 2, var x)", test1((1, 2, "3")));
Expect.equals("(String _, _, _)", test1(("0", 1, 2)));
Expect.equals("default", test1((1, 1, 3)));
Expect.equals("default", test1(((1, 2), 3, 4)));

Expect.equals("[_, 2, var x]", test2((1, 2, "3")));
Expect.equals("(_, 2, var x)", test2((1, 2, "3")));
Expect.equals("(String _, _, _)", test2(("0", 1, 2)));
Expect.equals("default", test2((1, 1, 3)));
Expect.equals("default", test2(((1, 2), 3, 4)));

Expect.equals("[_, 2, var x]", test3((1, 2, "3")));
Expect.equals("(_, 2, var x)", test3((1, 2, "3")));
Expect.equals("(String _, _, _)", test3(("0", 1, 2)));
Expect.equals("default", test3((1, 1, 3)));
Expect.equals("default", test3(((1, 2), 3, 4)));
Expand Down

0 comments on commit a6b5e68

Please sign in to comment.