forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#2420. Add null-assert pattern exhaustiveness tests
- Loading branch information
Showing
2 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
LanguageFeatures/Extension-types/exhaustiveness_null_assert_A01_t01.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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion Null-assert pattern is exhausted if a of the subpattern and a | ||
/// type Null is exhausted. | ||
/// | ||
/// @description Check that a null-assert pattern is exhausted if a of the | ||
/// subpattern and a type `Null` is exhausted. Test switch statement | ||
/// @author sgrekhov22@gmail.com | ||
import "../../Utils/expect.dart"; | ||
|
||
extension type const BoolET1(bool _) {} | ||
extension type const BoolET2(bool _) implements bool {} | ||
|
||
String test1(bool? o) { | ||
switch (o) { | ||
case BoolET1 _!: | ||
return "exhaustive"; | ||
} | ||
} | ||
|
||
String test2(bool? o) { | ||
switch (o) { | ||
case BoolET2 _!: | ||
return "exhaustive"; | ||
} | ||
} | ||
|
||
String test3(BoolET1? o) { | ||
switch (o) { | ||
case bool _!: | ||
return "exhaustive"; | ||
} | ||
} | ||
|
||
String test4(BoolET2? o) { | ||
switch (o) { | ||
case bool _!: | ||
return "exhaustive"; | ||
} | ||
} | ||
|
||
String test5(BoolET1? o) { | ||
switch (o) { | ||
case BoolET1 _!: | ||
return "exhaustive"; | ||
} | ||
} | ||
|
||
String test6(BoolET2? o) { | ||
switch (o) { | ||
case BoolET2 _!: | ||
return "exhaustive"; | ||
} | ||
} | ||
|
||
String test7(BoolET1? o) { | ||
switch (o) { | ||
case BoolET2 _!: | ||
return "exhaustive"; | ||
} | ||
} | ||
|
||
String test8(BoolET2? o) { | ||
switch (o) { | ||
case BoolET1 _!: | ||
return "exhaustive"; | ||
} | ||
} | ||
|
||
main() { | ||
Expect.equals("exhaustive" ,test1(true)); | ||
Expect.equals("exhaustive" ,test2(false)); | ||
Expect.equals("exhaustive" ,test3(BoolET1(true))); | ||
Expect.equals("exhaustive" ,test4(BoolET2(false))); | ||
Expect.equals("exhaustive" ,test5(BoolET1(true))); | ||
Expect.equals("exhaustive" ,test6(BoolET2(false))); | ||
Expect.equals("exhaustive" ,test7(BoolET1(true))); | ||
Expect.equals("exhaustive" ,test8(BoolET2(false))); | ||
|
||
Expect.throws(() { | ||
test1(null); | ||
}); | ||
Expect.throws(() { | ||
test2(null); | ||
}); | ||
Expect.throws(() { | ||
test3(null); | ||
}); | ||
Expect.throws(() { | ||
test4(null); | ||
}); | ||
Expect.throws(() { | ||
test5(null); | ||
}); | ||
Expect.throws(() { | ||
test6(null); | ||
}); | ||
Expect.throws(() { | ||
test7(null); | ||
}); | ||
Expect.throws(() { | ||
test8(null); | ||
}); | ||
} |
83 changes: 83 additions & 0 deletions
83
LanguageFeatures/Extension-types/exhaustiveness_null_assert_A01_t02.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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion Null-assert pattern is exhausted if a of the subpattern and a | ||
/// type Null is exhausted. | ||
/// | ||
/// @description Check that a null-assert pattern is exhausted if a of the | ||
/// subpattern and a type `Null` is exhausted. Test switch expression | ||
/// @author sgrekhov22@gmail.com | ||
import "../../Utils/expect.dart"; | ||
|
||
extension type const ObjectET1(Object _) {} | ||
extension type const ObjectET2(Object _) implements Object {} | ||
|
||
String test1(Object? o) => switch (o) { | ||
ObjectET1 _! => "exhaustive" | ||
}; | ||
|
||
String test2(Object? o) => switch (o) { | ||
ObjectET2 _! => "exhaustive" | ||
}; | ||
|
||
String test3(ObjectET1? o) => switch (o) { | ||
Object _! => "exhaustive" | ||
}; | ||
|
||
String test4(ObjectET2? o) => switch (o) { | ||
Object _! => "exhaustive" | ||
}; | ||
|
||
String test5(ObjectET1? o) => switch (o) { | ||
ObjectET1 _! => "exhaustive" | ||
}; | ||
|
||
String test6(ObjectET2? o) => switch (o) { | ||
ObjectET2 _! => "exhaustive" | ||
}; | ||
|
||
String test7(ObjectET1? o) => switch (o) { | ||
ObjectET2 _! => "exhaustive" | ||
}; | ||
|
||
String test8(ObjectET2? o) => switch (o) { | ||
ObjectET1 _! => "exhaustive" | ||
}; | ||
|
||
main() { | ||
Expect.equals("exhaustive" ,test1(true)); | ||
Expect.equals("exhaustive" ,test2(42)); | ||
Expect.equals("exhaustive" ,test3(ObjectET1(true))); | ||
Expect.equals("exhaustive" ,test4(ObjectET2(42))); | ||
Expect.equals("exhaustive" ,test5(ObjectET1(true))); | ||
Expect.equals("exhaustive" ,test6(ObjectET2(42))); | ||
Expect.equals("exhaustive" ,test7(ObjectET1(true))); | ||
Expect.equals("exhaustive" ,test8(ObjectET2(42))); | ||
|
||
Expect.throws(() { | ||
test1(null); | ||
}); | ||
Expect.throws(() { | ||
test2(null); | ||
}); | ||
Expect.throws(() { | ||
test3(null); | ||
}); | ||
Expect.throws(() { | ||
test4(null); | ||
}); | ||
Expect.throws(() { | ||
test5(null); | ||
}); | ||
Expect.throws(() { | ||
test6(null); | ||
}); | ||
Expect.throws(() { | ||
test7(null); | ||
}); | ||
Expect.throws(() { | ||
test8(null); | ||
}); | ||
} |