-
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.
Issue #1087: New Constructor Tear Offs tests added
- Loading branch information
Showing
19 changed files
with
722 additions
and
7 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
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
25 changes: 25 additions & 0 deletions
25
LanguageFeatures/Constructor-tear-offs/named_constructor_A05_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,25 @@ | ||
// Copyright (c) 2021, 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 When tearing off a constructor of a generic class using [C.name], | ||
/// the type arguments may be implicitly instantiated, just as for a normal | ||
/// generic method tear-off of the corresponding static function. The | ||
/// instantiation is based on the context-type at the tear-off position. If the | ||
/// context types allows a generic function, the tear-off is not instantiated | ||
/// and the result is a generic function. | ||
/// | ||
/// @description Checks that type arguments can be implicitly instantiated. | ||
/// @author iarkh@unipro.ru | ||
import "../../Utils/expect.dart"; | ||
|
||
class C<T1, T2 extends num, T3 extends String> { | ||
C.constr() {} | ||
C.constr1(T1 t, T2 t2) {} | ||
} | ||
|
||
main() { | ||
Expect.isTrue(C.constr is C Function<T1 extends dynamic, T2 extends num, T3 extends String>()); | ||
Expect.isTrue(C.constr1 is C Function<T1 extends dynamic, T2 extends num, T3 extends String>(T1, T2)); | ||
} |
51 changes: 51 additions & 0 deletions
51
LanguageFeatures/Constructor-tear-offs/named_constructor_A05_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,51 @@ | ||
// Copyright (c) 2021, 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 When tearing off a constructor of a generic class using [C.name], | ||
/// the type arguments may be implicitly instantiated, just as for a normal | ||
/// generic method tear-off of the corresponding static function. The | ||
/// instantiation is based on the context-type at the tear-off position. If the | ||
/// context types allows a generic function, the tear-off is not instantiated | ||
/// and the result is a generic function. | ||
/// | ||
/// @description Checks that type arguments can be implicitly instantiated. | ||
/// @author iarkh@unipro.ru | ||
import "../../Utils/expect.dart"; | ||
|
||
class C<T1, T2 extends num, T3 extends String> { | ||
var t1, t2, t3; | ||
var p1, p2; | ||
|
||
C.constr() { | ||
t1 = T1; | ||
t2 = T2; | ||
t3 = T3; | ||
} | ||
C.constr1(T1 par1, T2 par2) { | ||
t1 = T1; | ||
t2 = T2; | ||
t3 = T3; | ||
p1 = par1; | ||
p2 = par2; | ||
} | ||
|
||
void check(exp1, exp2, exp3, exp4, exp5) { | ||
Expect.equals(exp1, T1); | ||
Expect.equals(exp2, T2); | ||
Expect.equals(exp3, T3); | ||
Expect.equals(exp4, p1); | ||
Expect.equals(exp5, p2); | ||
} | ||
} | ||
|
||
main() { | ||
var v = C.constr; | ||
C c = v(); | ||
c.check(dynamic, num, String, null, null); | ||
|
||
var v1 = C.constr1; | ||
C c1 = v1(1, 2); | ||
c1.check(dynamic, num, String, 1, 2); | ||
} |
34 changes: 34 additions & 0 deletions
34
LanguageFeatures/Constructor-tear-offs/named_constructor_A06_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,34 @@ | ||
// Copyright (c) 2021, 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 When tearing off a constructor of a generic class using | ||
/// [C<typeArgs>.name, the torn off method is always instantiated to the | ||
/// provided type arguments (which must be valid type arguments for the | ||
/// class/corresponding function). It otherwise behaves as an implicitly | ||
/// instantiated function tear-off. | ||
/// | ||
/// @description Checks that type arguments correctly instantiated for | ||
/// [C<typeArgs>.name. | ||
/// @author iarkh@unipro.ru | ||
import "../../Utils/expect.dart"; | ||
|
||
class C<T1, T2 extends num, T3 extends String> { | ||
C.constr() {} | ||
C.constr1(T1 t, T2 t2) {} | ||
} | ||
|
||
main() { | ||
var v1 = C<dynamic, num, String>.constr; | ||
Expect.isTrue(v1 is C Function<T1 extends dynamic, T2 extends num, T3 extends String>()); | ||
|
||
var v2 = C<dynamic, num, String>.constr1; | ||
Expect.isTrue(v2 is C Function<T1 extends dynamic, T2 extends num, T3 extends String>(dynamic, num)); | ||
|
||
var v3 = C<List<int>, int, String>.constr; | ||
Expect.isTrue(v3 is C Function<T1 extends List<int>, T2 extends int, T3 extends String>()); | ||
|
||
var v4 = C<List<int>, int, String>.constr1; | ||
Expect.isTrue(v3 is C Function<T1 extends List<int>, T2 extends int, T3 extends String>(List<int>, int)); | ||
} |
61 changes: 61 additions & 0 deletions
61
LanguageFeatures/Constructor-tear-offs/named_constructor_A06_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,61 @@ | ||
// Copyright (c) 2021, 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 When tearing off a constructor of a generic class using [C.name], | ||
/// the type arguments may be implicitly instantiated, just as for a normal | ||
/// generic method tear-off of the corresponding static function. The | ||
/// instantiation is based on the context-type at the tear-off position. If the | ||
/// context types allows a generic function, the tear-off is not instantiated | ||
/// and the result is a generic function. | ||
/// | ||
/// @description Checks that type arguments can be instantiated during the | ||
/// constructor tearing off. | ||
/// @author iarkh@unipro.ru | ||
import "../../Utils/expect.dart"; | ||
|
||
class C<T1, T2 extends num, T3 extends String> { | ||
var t1, t2, t3; | ||
var p1, p2; | ||
|
||
C.constr() { | ||
t1 = T1; | ||
t2 = T2; | ||
t3 = T3; | ||
} | ||
C.constr1(T1 par1, T2 par2) { | ||
t1 = T1; | ||
t2 = T2; | ||
t3 = T3; | ||
p1 = par1; | ||
p2 = par2; | ||
} | ||
|
||
void check(exp1, exp2, exp3, exp4, exp5) { | ||
Expect.equals(exp1, T1); | ||
Expect.equals(exp2, T2); | ||
Expect.equals(exp3, T3); | ||
Expect.equals(exp4, p1); | ||
Expect.equals(exp5, p2); | ||
} | ||
} | ||
|
||
main() { | ||
var v1 = C<dynamic, num, String>.constr; | ||
C c1 = v1(); | ||
c1.check(dynamic, num, String, null, null); | ||
|
||
var v2 = C<dynamic, num, String>.constr1; | ||
C c2 = v2([], 0); | ||
c2.check(dynamic, num, String, [], 0); | ||
|
||
var v3 = C<List, int, String>.constr; | ||
C c3 = v3(); | ||
c3.check(List, int, String, null, null); | ||
|
||
var v4 = C<List, int, String>.constr1; | ||
C c4 = v4([], 0); | ||
c1.check(List, int, String, [], 0); | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
LanguageFeatures/Constructor-tear-offs/named_constructor_A07_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,28 @@ | ||
// Copyright (c) 2021, 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 The constant-ness, identity and equality of the torn-off | ||
/// constructor functions behave exactly the same as if they were tear-offs of | ||
/// the corresponding static function. This means that a non-generic class | ||
/// constructor always tears off to the same function value, as does an | ||
/// uninstantiated tear off of a generic class constructor. | ||
/// | ||
/// @description Checks that a non-generic class constructor always tears off to | ||
/// the same function value: test default constructor | ||
/// @author iarkh@unipro.ru | ||
import "../../Utils/expect.dart"; | ||
|
||
class C { | ||
C() {} | ||
} | ||
|
||
main() { | ||
var v1 = C.new; | ||
var v2 = C.new; | ||
var v3 = C.new; | ||
Expect.equals(v1, v2); | ||
Expect.equals(v1, v3); | ||
Expect.equals(v2, v3); | ||
} |
48 changes: 48 additions & 0 deletions
48
LanguageFeatures/Constructor-tear-offs/named_constructor_A07_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,48 @@ | ||
// Copyright (c) 2021, 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 The constant-ness, identity and equality of the torn-off | ||
/// constructor functions behave exactly the same as if they were tear-offs of | ||
/// the corresponding static function. This means that a non-generic class | ||
/// constructor always tears off to the same function value, as does an | ||
/// uninstantiated tear off of a generic class constructor. | ||
/// | ||
/// @description Checks that a non-generic class constructor always tears off to | ||
/// the same function value: test named constructors | ||
/// @author iarkh@unipro.ru | ||
import "../../Utils/expect.dart"; | ||
|
||
class C { | ||
C.name1() {} | ||
C.name2(int i) {} | ||
C.name3(int i, String s, List l) {} | ||
} | ||
|
||
main() { | ||
var v1 = C.name1; | ||
var v2 = C.name1; | ||
var v3 = C.name1; | ||
Expect.equals(v1, v2); | ||
Expect.equals(v1, v3); | ||
Expect.equals(v2, v3); | ||
|
||
var v4 = C.name2; | ||
var v5 = C.name2; | ||
var v6 = C.name2; | ||
Expect.equals(v4, v5); | ||
Expect.equals(v4, v6); | ||
Expect.equals(v5, v6); | ||
|
||
var v7 = C.name3; | ||
var v8 = C.name3; | ||
var v9 = C.name3; | ||
Expect.equals(v7, v8); | ||
Expect.equals(v7, v9); | ||
Expect.equals(v8, v9); | ||
|
||
Expect.notEquals(v1, v4); | ||
Expect.notEquals(v2, v7); | ||
Expect.notEquals(v5, v9); | ||
} |
49 changes: 49 additions & 0 deletions
49
LanguageFeatures/Constructor-tear-offs/named_constructor_A07_t03.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,49 @@ | ||
// Copyright (c) 2021, 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 The constant-ness, identity and equality of the torn-off | ||
/// constructor functions behave exactly the same as if they were tear-offs of | ||
/// the corresponding static function. This means that a non-generic class | ||
/// constructor always tears off to the same function value, as does an | ||
/// uninstantiated tear off of a generic class constructor. | ||
/// | ||
/// @description Checks that a non-generic class constructor always tears off to | ||
/// the same function value: test constructors with initializing formals. | ||
/// @author iarkh@unipro.ru | ||
import "../../Utils/expect.dart"; | ||
|
||
class C { | ||
int? i, j; | ||
C(this.i, this.j) {} | ||
C.constr1(this.i, this.j); | ||
C.constr2(i, this.j) {} | ||
} | ||
|
||
main() { | ||
var v1 = C.new; | ||
var v2 = C.new; | ||
var v3 = C.new; | ||
Expect.equals(v1, v2); | ||
Expect.equals(v1, v3); | ||
Expect.equals(v2, v3); | ||
|
||
var v4 = C.constr1; | ||
var v5 = C.constr1; | ||
var v6 = C.constr1; | ||
Expect.equals(v4, v5); | ||
Expect.equals(v4, v6); | ||
Expect.equals(v5, v6); | ||
|
||
var v7 = C.constr1; | ||
var v8 = C.constr1; | ||
var v9 = C.constr1; | ||
Expect.equals(v7, v8); | ||
Expect.equals(v7, v9); | ||
Expect.equals(v8, v9); | ||
|
||
Expect.notEquals(v1, v4); | ||
Expect.notEquals(v2, v7); | ||
Expect.notEquals(v5, v9); | ||
} |
48 changes: 48 additions & 0 deletions
48
LanguageFeatures/Constructor-tear-offs/named_constructor_A07_t04.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,48 @@ | ||
// Copyright (c) 2021, 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 The constant-ness, identity and equality of the torn-off | ||
/// constructor functions behave exactly the same as if they were tear-offs of | ||
/// the corresponding static function. This means that a non-generic class | ||
/// constructor always tears off to the same function value, as does an | ||
/// uninstantiated tear off of a generic class constructor. | ||
/// | ||
/// @description Checks that a non-generic class constructor always tears off to | ||
/// the same function value: test constructors with named parameters. | ||
/// @author iarkh@unipro.ru | ||
import "../../Utils/expect.dart"; | ||
|
||
class C { | ||
C.name1({int i = 1, j = "testme"}) {} | ||
C.name2(int i, {List? l, String check = "check"}) {} | ||
C.name3(int i, {String s = "", required l}) {} | ||
} | ||
|
||
main() { | ||
var v1 = C.name1; | ||
var v2 = C.name1; | ||
var v3 = C.name1; | ||
Expect.equals(v1, v2); | ||
Expect.equals(v1, v3); | ||
Expect.equals(v2, v3); | ||
|
||
var v4 = C.name2; | ||
var v5 = C.name2; | ||
var v6 = C.name2; | ||
Expect.equals(v4, v5); | ||
Expect.equals(v4, v6); | ||
Expect.equals(v5, v6); | ||
|
||
var v7 = C.name3; | ||
var v8 = C.name3; | ||
var v9 = C.name3; | ||
Expect.equals(v7, v8); | ||
Expect.equals(v7, v9); | ||
Expect.equals(v8, v9); | ||
|
||
Expect.notEquals(v1, v4); | ||
Expect.notEquals(v2, v7); | ||
Expect.notEquals(v5, v9); | ||
} |
Oops, something went wrong.