Skip to content

#1401. [Patterns] Logical and relational patterns tests refactored #1573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions LanguageFeatures/Patterns/logical_and_A06_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ main() {
break;
default:
}
Expect.equals("Square.area=1;Square.area=2;", shape2.log);
Expect.equals("Square.area=1;=2;", shape2.log);

Shape shape3 = Square(1);
switch (shape3) {
case Shape(area: 1) && Shape(size: 1) && Square(area: 2)
&& Square(size: 2):
&& Square(size: 3):
Expect.fail("Pattern should not match");
break;
default:
}
Expect.equals("Square.area=1;Square.size=1;Square.area=2;", shape3.log);
Expect.equals("Square.area=1;Square.size=1;=2;", shape3.log);
}
4 changes: 2 additions & 2 deletions LanguageFeatures/Patterns/logical_or_A05_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ main() {

Shape shape2 = Square(2);
switch (shape2) {
case Square(area: 2) || Square(area: 4) || Square(area: 4):
Expect.equals("Circle.area=2;Circle.area=4;", shape2.log);
case Square(area: 2) || Square(area: 4) || Square(area: 8):
Expect.equals("Square.area=2;=4;", shape2.log);
break;
default:
print("Other");
Expand Down
8 changes: 3 additions & 5 deletions LanguageFeatures/Patterns/logical_or_A05_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ main() {
Shape shape1 = Square(1);
switch (shape1) {
case Square(area: 2) || Square(area: 1):
Expect.equals("Square.area=2;Square.area=1;", shape1.log);
Expect.equals("Square.area=2;=1;", shape1.log);
break;
default:
print("Other");
Expand All @@ -50,8 +50,7 @@ main() {
case Circle(area: 2) || Circle(area: 1) || Circle(area: 0)
|| Circle(area: 3.14):
Expect.equals(
"Circle.area=2;Circle.area=1;Circle.area=0;Circle.area=3.14;",
shape3.log);
"Circle.area=2;=1;=0;=3.14;", shape3.log);
break;
default:
print("Other");
Expand All @@ -65,8 +64,7 @@ main() {
break;
default:
other = true;
Expect.equals("Rectangle.area=3;Rectangle.area=1;Rectangle.area=42;",
shape4.log);
Expect.equals("Rectangle.area=3;=1;=42;", shape4.log);
}
Expect.isTrue(other);
}
2 changes: 1 addition & 1 deletion LanguageFeatures/Patterns/logical_or_A05_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ main() {

Shape shape2 = Square(2);
if (shape2 case Square(area: 2) || Square(area: 4) || Square(area: 4)) {
Expect.equals("Circle.area=2;Circle.area=4;", shape2.log);
Expect.equals("Square.area=2;=4;", shape2.log);
} else {
Expect.fail("Expression should match");
}
Expand Down
10 changes: 5 additions & 5 deletions LanguageFeatures/Patterns/logical_or_A05_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import "../../Utils/expect.dart";
main() {
Shape shape1 = Square(1);
if (shape1 case Square(area: 2) || Square(area: 1)) {
Expect.equals("Square.area=2;Square.area=1;", shape1.log);
Expect.equals("Square.area=2;=1;", shape1.log);
} else {
Expect.fail("Expression should match");
}
Expand All @@ -45,17 +45,17 @@ main() {
if (shape2 case Circle(area: 2) || Circle(area: 1) || Circle(area: 0)
|| Circle(area: 3.14)) {
Expect.equals(
"Circle.area=2;Circle.area=1;Circle.area=0;Circle.area=3.14;",
"Circle.area=2;=1;=0;=3.14;",
shape3.log);
} else {
Expect.fail("Expression should match");
}

Shape shape4 = Rectangle(1, 2);
if (shape4 case Rectangle(area: 3) || Rectangle(area: 1) || Rectangle(area: 42)) {
if (shape4 case Rectangle(area: 3) || Rectangle(area: 1)
|| Rectangle(area: 42)) {
Expect.fail("No branches should match");
} else {
Expect.equals("Rectangle.area=3;Rectangle.area=1;Rectangle.area=42;",
shape4.log);
Expect.equals("Rectangle.area=3;=1;=42;", shape4.log);
}
}
2 changes: 1 addition & 1 deletion LanguageFeatures/Patterns/logical_or_A05_t05.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ main() {
case Square(area: 2) || Square(area: 4) || Square(area: 4) => shape2.log;
default => "Other";
};
Expect.equals("Circle.area=2;Circle.area=4;", s2);
Expect.equals("Square.area=2;=4;", s2);

Shape shape3 = Shape();
String s3 = switch (shape3) {
Expand Down
5 changes: 2 additions & 3 deletions LanguageFeatures/Patterns/logical_or_A05_t06.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ main() {
case Square(area: 2) || Square(area: 1) => shape1.log;
default => "Other";
};
Expect.equals("Square.area=2;Square.area=1;", s1);
Expect.equals("Square.area=2;=1;", s1);

Shape shape2 = Shape();
String s2 = switch (shape2) {
Expand All @@ -47,8 +47,7 @@ main() {
|| Circle(area: 3.14) => shape3.log;
default => "Other";
};
Expect.equals("Circle.area=2;Circle.area=1;Circle.area=0;Circle.area=3.14;",
s3);
Expect.equals("Circle.area=2;=1;=0;=3.14;", s3);

Shape shape4 = Rectangle(1, 2);
String s4 = switch (shape4) {
Expand Down
2 changes: 1 addition & 1 deletion LanguageFeatures/Patterns/relational_A04_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ String test() {
// [cfe] unspecified
case [== i++] => "case 2";
// ^^^
// [analyzer] unspecifiedList<num> list
// [analyzer] unspecified
// [cfe] unspecified
case [>= j && < 20] => "case 3";
// ^
Expand Down
32 changes: 0 additions & 32 deletions LanguageFeatures/Patterns/relational_A05_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ main() {
case < "i":
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
break;
case == true:
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
break;
case > o:
Expand All @@ -72,20 +67,6 @@ main() {
default:
}

switch (value) {
case != "":
// ^^
// [analyzer] unspecified
// [cfe] unspecified
break;
case == true:
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
break;
default:
}

switch (value) {
case >= "1":
// ^^^
Expand All @@ -103,23 +84,10 @@ main() {
if (value case < "i") {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
if (value case == true) {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
if (value case > o) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (value case != "") {}
// ^^
// [analyzer] unspecified
// [cfe] unspecified
if (value case == true) {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
if (value case >= "1") {}
// ^^^
Expand Down