Skip to content

Commit

Permalink
#2142. Add syntax tests (#2148)
Browse files Browse the repository at this point in the history
Add syntax tests for extension type declarations.
  • Loading branch information
sgrekhov authored Jul 25, 2023
1 parent 1530f9b commit f500a37
Show file tree
Hide file tree
Showing 22 changed files with 890 additions and 0 deletions.
15 changes: 15 additions & 0 deletions LanguageFeatures/Extension-types/extension_type_lib.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2023, 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.

/// @description Helper library for testing extension types
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

library extension_type_lib;

int x = 42;

extension type _PrivateExtensionType(int id) {
}
36 changes: 36 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2023, 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 A rule for <extensionTypeDeclaration> is added to the grammar,
/// along with some rules for elements used in extension type declarations:
///
/// <extensionTypeDeclaration> ::=
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
/// <representationDeclaration> <interfaces>?
/// '{'
/// (<metadata> <extensionTypeMemberDeclaration>)*
/// '}'
///
/// <representationDeclaration> ::=
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
///
/// <identifierOrNew> ::= <identifier> | 'new'
///
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
///
/// The token `type` is not made a built-in identifier: the built-in identifier
/// extension that occurs right before type serves to disambiguate the extension
/// type declaration with a fixed lookahead.
///
/// @description Checks that it is not an error to declare a class named `type`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

class type {
}

main() {
type();
}
38 changes: 38 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2023, 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 A rule for <extensionTypeDeclaration> is added to the grammar,
/// along with some rules for elements used in extension type declarations:
///
/// <extensionTypeDeclaration> ::=
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
/// <representationDeclaration> <interfaces>?
/// '{'
/// (<metadata> <extensionTypeMemberDeclaration>)*
/// '}'
///
/// <representationDeclaration> ::=
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
///
/// <identifierOrNew> ::= <identifier> | 'new'
///
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
///
/// The token `type` is not made a built-in identifier: the built-in identifier
/// extension that occurs right before type serves to disambiguate the extension
/// type declaration with a fixed lookahead.
///
/// @description Checks that it is not an error to declare a mixin named `type`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

mixin type on Object {
}

class IA = Object with type;

main() {
IA();
}
36 changes: 36 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2023, 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 A rule for <extensionTypeDeclaration> is added to the grammar,
/// along with some rules for elements used in extension type declarations:
///
/// <extensionTypeDeclaration> ::=
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
/// <representationDeclaration> <interfaces>?
/// '{'
/// (<metadata> <extensionTypeMemberDeclaration>)*
/// '}'
///
/// <representationDeclaration> ::=
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
///
/// <identifierOrNew> ::= <identifier> | 'new'
///
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
///
/// The token `type` is not made a built-in identifier: the built-in identifier
/// extension that occurs right before type serves to disambiguate the extension
/// type declaration with a fixed lookahead.
///
/// @description Checks that it is not an error to import a library with
/// import prefix `type`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

import "extension_type_lib.dart" as type;

main() {
print(type.x);
}
37 changes: 37 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A01_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2023, 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 A rule for <extensionTypeDeclaration> is added to the grammar,
/// along with some rules for elements used in extension type declarations:
///
/// <extensionTypeDeclaration> ::=
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
/// <representationDeclaration> <interfaces>?
/// '{'
/// (<metadata> <extensionTypeMemberDeclaration>)*
/// '}'
///
/// <representationDeclaration> ::=
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
///
/// <identifierOrNew> ::= <identifier> | 'new'
///
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
///
/// The token `type` is not made a built-in identifier: the built-in identifier
/// extension that occurs right before type serves to disambiguate the extension
/// type declaration with a fixed lookahead.
///
/// @description Checks that it is not an error to declare a type alias named
/// `type`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

typedef type = String;

main() {
type s = "type";
s.substring(1);
}
36 changes: 36 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2023, 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 A rule for <extensionTypeDeclaration> is added to the grammar,
/// along with some rules for elements used in extension type declarations:
///
/// <extensionTypeDeclaration> ::=
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
/// <representationDeclaration> <interfaces>?
/// '{'
/// (<metadata> <extensionTypeMemberDeclaration>)*
/// '}'
///
/// <representationDeclaration> ::=
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
///
/// <identifierOrNew> ::= <identifier> | 'new'
///
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
///
/// @description Checks that it is a compile-time error if an extension type
/// declaration doesn't contain `typeIdentifier`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

extension type (int id) {
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {

}
34 changes: 34 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A02_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2023, 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 A rule for <extensionTypeDeclaration> is added to the grammar,
/// along with some rules for elements used in extension type declarations:
///
/// <extensionTypeDeclaration> ::=
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
/// <representationDeclaration> <interfaces>?
/// '{'
/// (<metadata> <extensionTypeMemberDeclaration>)*
/// '}'
///
/// <representationDeclaration> ::=
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
///
/// <identifierOrNew> ::= <identifier> | 'new'
///
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
///
/// @description Checks that it is a compile-time error to refer an extension
/// type with the `typeIdentifier` started with `_` outside of the library where
/// it is defined
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

main() {
print(_PrivateExtensionType);
// ^^^^^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
38 changes: 38 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A03_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2023, 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 A rule for <extensionTypeDeclaration> is added to the grammar,
/// along with some rules for elements used in extension type declarations:
///
/// <extensionTypeDeclaration> ::=
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
/// <representationDeclaration> <interfaces>?
/// '{'
/// (<metadata> <extensionTypeMemberDeclaration>)*
/// '}'
///
/// <representationDeclaration> ::=
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
///
/// <identifierOrNew> ::= <identifier> | 'new'
///
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
///
/// @description Checks that an extension type declaration may have type
/// parameters
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

extension type ET<T>(T id) {}

main() {
ET<int> et1 = ET<int>(42);
Expect.equals(42, et1.id);

ET<String> et2 = ET<String>.new("42");
Expect.equals("42", et2.id);
}
36 changes: 36 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A04_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2023, 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 A rule for <extensionTypeDeclaration> is added to the grammar,
/// along with some rules for elements used in extension type declarations:
///
/// <extensionTypeDeclaration> ::=
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
/// <representationDeclaration> <interfaces>?
/// '{'
/// (<metadata> <extensionTypeMemberDeclaration>)*
/// '}'
///
/// <representationDeclaration> ::=
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
///
/// <identifierOrNew> ::= <identifier> | 'new'
///
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
///
/// @description Checks that it is a compile-time error if an extension type
/// declaration doesn't contain `representationDeclaration`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

extension type ET {
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(ET);
}
35 changes: 35 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A04_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2023, 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 A rule for <extensionTypeDeclaration> is added to the grammar,
/// along with some rules for elements used in extension type declarations:
///
/// <extensionTypeDeclaration> ::=
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
/// <representationDeclaration> <interfaces>?
/// '{'
/// (<metadata> <extensionTypeMemberDeclaration>)*
/// '}'
///
/// <representationDeclaration> ::=
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
///
/// <identifierOrNew> ::= <identifier> | 'new'
///
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
///
/// @description Checks that a `representationDeclaration` may have form
/// `identifier`.`identifier`...
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

extension type ET.et(int id) {}

main() {
ET et = ET.et(42);
Expect.equals(42, et.id);
}
38 changes: 38 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A04_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2023, 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 A rule for <extensionTypeDeclaration> is added to the grammar,
/// along with some rules for elements used in extension type declarations:
///
/// <extensionTypeDeclaration> ::=
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
/// <representationDeclaration> <interfaces>?
/// '{'
/// (<metadata> <extensionTypeMemberDeclaration>)*
/// '}'
///
/// <representationDeclaration> ::=
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
///
/// <identifierOrNew> ::= <identifier> | 'new'
///
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
///
/// @description Checks that a `representationDeclaration` may have form
/// `identifier`.new
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

extension type ET.new(int id) {}

main() {
ET et1 = ET(1);
Expect.equals(1, et1.id);

ET et2 = ET.new(2);
Expect.equals(2, et2.id);
}
Loading

0 comments on commit f500a37

Please sign in to comment.