Skip to content

Commit 5b6211c

Browse files
committed
dart-lang#1399. [Records] Record expressions tests updated according to the specification changes
1 parent 401b528 commit 5b6211c

12 files changed

+242
-16
lines changed

LanguageFeatures/Records/record_expressions_A01_t01.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
///
1616
/// The same field name more than once.
1717
///
18-
/// No named fields and only one positional field. This avoids ambiguity with
19-
/// parenthesized expressions.
18+
/// Only one positional field and no trailing comma.
2019
///
2120
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
2221
///
2322
/// A field name that starts with an underscore.
2423
///
24+
/// A field name that collides with the synthesized getter name of a positional
25+
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
26+
/// with the getter for the first positional field.
27+
///
2528
/// @description Checks that it is a compile-time error if a record has the same
2629
/// field name more than once
2730
/// @author [email protected]

LanguageFeatures/Records/record_expressions_A01_t02.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
///
1616
/// The same field name more than once.
1717
///
18-
/// No named fields and only one positional field. This avoids ambiguity with
19-
/// parenthesized expressions.
18+
/// Only one positional field and no trailing comma.
2019
///
2120
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
2221
///
2322
/// A field name that starts with an underscore.
2423
///
24+
/// A field name that collides with the synthesized getter name of a positional
25+
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
26+
/// with the getter for the first positional field.
27+
///
2528
/// @description Checks that it is a compile-time error if a record has the same
2629
/// field name more than once
2730
/// @author [email protected]

LanguageFeatures/Records/record_expressions_A02_t01.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
///
1616
/// The same field name more than once.
1717
///
18-
/// No named fields and only one positional field. This avoids ambiguity with
19-
/// parenthesized expressions.
18+
/// Only one positional field and no trailing comma.
2019
///
2120
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
2221
///
2322
/// A field name that starts with an underscore.
2423
///
24+
/// A field name that collides with the synthesized getter name of a positional
25+
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
26+
/// with the getter for the first positional field.
27+
///
2528
/// @description Checks that it is a compile-time error if a record has no named
26-
/// fields and only one positional field
29+
/// fields and only one positional field with no trailing comma
2730
/// @author [email protected]
2831
2932
// SharedOptions=--enable-experiment=records

LanguageFeatures/Records/record_expressions_A02_t02.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
///
1616
/// The same field name more than once.
1717
///
18-
/// No named fields and only one positional field. This avoids ambiguity with
19-
/// parenthesized expressions.
18+
/// Only one positional field and no trailing comma.
2019
///
2120
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
2221
///
2322
/// A field name that starts with an underscore.
2423
///
24+
/// A field name that collides with the synthesized getter name of a positional
25+
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
26+
/// with the getter for the first positional field.
27+
///
2528
/// @description Checks that it is a compile-time error if a record has no named
26-
/// fields and only one positional field
29+
/// fields and only one positional field with no trailing comma
2730
/// @author [email protected]
2831
2932
// SharedOptions=--enable-experiment=records
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion A record is created using a record expression. The grammar is:
6+
///
7+
/// literal ::= record
8+
/// | // Existing literal productions...
9+
/// record ::= '(' recordField ( ',' recordField )* ','? ')'
10+
/// recordField ::= (identifier ':' )? expression
11+
///
12+
/// This is identical to the grammar for a function call argument list. There
13+
/// are a couple of syntactic restrictions not captured by the grammar. It is a
14+
/// compile-time error if a record has any of:
15+
///
16+
/// The same field name more than once.
17+
///
18+
/// Only one positional field and no trailing comma.
19+
///
20+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
21+
///
22+
/// A field name that starts with an underscore.
23+
///
24+
/// A field name that collides with the synthesized getter name of a positional
25+
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
26+
/// with the getter for the first positional field.
27+
///
28+
/// @description Checks that it is no error if a record has no named fields and
29+
/// only one positional field but with a trailing comma
30+
/// @author [email protected]
31+
32+
// SharedOptions=--enable-experiment=records
33+
34+
import "../../Utils/expect.dart";
35+
36+
main() {
37+
var r1 = (1,);
38+
var r2 = ((2),);
39+
var r3 = ((3,),);
40+
41+
Expect.equals(1, r1.$0);
42+
Expect.equals(2, r2.$0);
43+
Expect.equals(3, r2.$0.$0);
44+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion A record is created using a record expression. The grammar is:
6+
///
7+
/// literal ::= record
8+
/// | // Existing literal productions...
9+
/// record ::= '(' recordField ( ',' recordField )* ','? ')'
10+
/// recordField ::= (identifier ':' )? expression
11+
///
12+
/// This is identical to the grammar for a function call argument list. There
13+
/// are a couple of syntactic restrictions not captured by the grammar. It is a
14+
/// compile-time error if a record has any of:
15+
///
16+
/// The same field name more than once.
17+
///
18+
/// Only one positional field and no trailing comma.
19+
///
20+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
21+
///
22+
/// A field name that starts with an underscore.
23+
///
24+
/// A field name that collides with the synthesized getter name of a positional
25+
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
26+
/// with the getter for the first positional field.
27+
///
28+
/// @description Checks that it is no error if a record has no named fields and
29+
/// only one positional field but with a trailing comma
30+
/// @author [email protected]
31+
32+
// SharedOptions=--enable-experiment=records
33+
34+
import "../../Utils/expect.dart";
35+
36+
Record foo1() => (1,);
37+
38+
Record foo2() => ((2),);
39+
40+
Record foo3() => ((3,),);
41+
42+
dynamic bar(Record r) => r
43+
44+
main() {
45+
Expect.equals(1, foo1());
46+
Expect.equals(2, foo2());
47+
Expect.equals((3,), foo3());
48+
Expect.equals(("Hello",), bar(("Hello",)));
49+
Expect.equals(("Hello",), bar((("Hello"),)));
50+
}

LanguageFeatures/Records/record_expressions_A03_t01.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
///
1616
/// The same field name more than once.
1717
///
18-
/// No named fields and only one positional field. This avoids ambiguity with
19-
/// parenthesized expressions.
18+
/// Only one positional field and no trailing comma.
2019
///
2120
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
2221
///
2322
/// A field name that starts with an underscore.
2423
///
24+
/// A field name that collides with the synthesized getter name of a positional
25+
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
26+
/// with the getter for the first positional field.
27+
///
2528
/// @description Checks that it is a compile-time error if a record has a field
2629
/// named `hashCode`, `runtimeType`, `noSuchMethod`, or `toString`
2730
/// @author [email protected]

LanguageFeatures/Records/record_expressions_A03_t02.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
///
1616
/// The same field name more than once.
1717
///
18-
/// No named fields and only one positional field. This avoids ambiguity with
19-
/// parenthesized expressions.
18+
/// Only one positional field and no trailing comma.
2019
///
2120
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
2221
///
2322
/// A field name that starts with an underscore.
2423
///
24+
/// A field name that collides with the synthesized getter name of a positional
25+
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
26+
/// with the getter for the first positional field.
27+
///
2528
/// @description Checks that it is a compile-time error if a record has a field
2629
/// named `hashCode`, `runtimeType`, `noSuchMethod`, or `toString`
2730
/// @author [email protected]

LanguageFeatures/Records/record_expressions_A04_t01.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
///
1616
/// The same field name more than once.
1717
///
18-
/// No named fields and only one positional field. This avoids ambiguity with
19-
/// parenthesized expressions.
18+
/// Only one positional field and no trailing comma.
2019
///
2120
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
2221
///
2322
/// A field name that starts with an underscore.
2423
///
24+
/// A field name that collides with the synthesized getter name of a positional
25+
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
26+
/// with the getter for the first positional field.
27+
///
2528
/// @description Checks that it is a compile-time error if a record has a field
2629
/// name that starts with an underscore
2730
/// @author [email protected]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion A record is created using a record expression. The grammar is:
6+
///
7+
/// literal ::= record
8+
/// | // Existing literal productions...
9+
/// record ::= '(' recordField ( ',' recordField )* ','? ')'
10+
/// recordField ::= (identifier ':' )? expression
11+
///
12+
/// This is identical to the grammar for a function call argument list. There
13+
/// are a couple of syntactic restrictions not captured by the grammar. It is a
14+
/// compile-time error if a record has any of:
15+
///
16+
/// The same field name more than once.
17+
///
18+
/// Only one positional field and no trailing comma.
19+
///
20+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
21+
///
22+
/// A field name that starts with an underscore.
23+
///
24+
/// A field name that collides with the synthesized getter name of a positional
25+
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
26+
/// with the getter for the first positional field.
27+
///
28+
/// @description Checks that it is a compile-time error if a record has a field
29+
/// name that collides with the synthesized getter name of a positional field
30+
/// @author [email protected]
31+
32+
// SharedOptions=--enable-experiment=records
33+
34+
Record foo() => (42, $0: "Lily was here");
35+
// ^^
36+
// [analyzer] unspecified
37+
// [cfe] unspecified
38+
39+
void bar(Record r) {}
40+
41+
main() {
42+
var record1 = (42, $0: "Lily was here");
43+
// ^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
47+
var record2 = (1, 2, 3, $2: 42);
48+
// ^^
49+
// [analyzer] unspecified
50+
// [cfe] unspecified
51+
52+
bar((42, $0: 42));
53+
// ^^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion There is no syntax for a zero-field record expression. Instead,
6+
/// there is a static constant empty on [Record] that returns the empty record.
7+
///
8+
/// @description Checks that there is no syntax for a zero-field record
9+
/// expression.
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=records
13+
14+
Record foo() => ();
15+
// ^^
16+
// [analyzer] unspecified
17+
// [cfe] unspecified
18+
19+
void bar(Record r) {}
20+
21+
main() {
22+
var record1 = ();
23+
// ^^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
27+
bar(());
28+
// ^^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion There is no syntax for a zero-field record expression. Instead,
6+
/// there is a static constant empty on [Record] that returns the empty record.
7+
///
8+
/// @description Checks that there is a static constant empty on [Record] that
9+
/// returns the empty record
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=records
13+
14+
import "../../Utils/expect.dart";
15+
16+
Record foo() => Record.empty;
17+
18+
Record bar(Record r) => r;
19+
20+
main() {
21+
var record1 = Record.empty;
22+
Expect.equals(Record.empty, record1);
23+
Expect.equals(Record.empty, bar(Record.empty));
24+
}

0 commit comments

Comments
 (0)