Skip to content

Commit

Permalink
dart-lang#1959. Grammar tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Apr 28, 2023
1 parent fc31789 commit b8bcb3d
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 0 deletions.
49 changes: 49 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 The grammar is:
///
/// classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
/// typeParameters? superclass? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
/// | classModifiers 'class' mixinApplicationClass
///
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
///
/// mixinClassModifiers ::= 'abstract'? 'base'? 'mixin'
///
/// mixinDeclaration ::= 'base'? 'mixin' typeIdentifier typeParameters?
/// ('on' typeNotVoidList)? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
///
/// @description Check that it is a compile-time error if any of
/// keywords/built-in identifiers `abstract`, `final`, `interface`, `mixin`, or
/// `class` is used as an identifier
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

class class {}
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

class interface {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

class abstract {}
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

class mixin {}
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
}
34 changes: 34 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A01_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 The grammar is:
///
/// classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
/// typeParameters? superclass? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
/// | classModifiers 'class' mixinApplicationClass
///
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
///
/// mixinClassModifiers ::= 'abstract'? 'base'? 'mixin'
///
/// mixinDeclaration ::= 'base'? 'mixin' typeIdentifier typeParameters?
/// ('on' typeNotVoidList)? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
///
/// @description Check that it is not an error to create a class named `base` or
/// `sealed`
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

class base {}

class sealed {}

main() {
print(base);
print(sealed);
}
39 changes: 39 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 The grammar is:
///
/// classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
/// typeParameters? superclass? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
/// | classModifiers 'class' mixinApplicationClass
///
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
///
/// mixinClassModifiers ::= 'abstract'? 'base'? 'mixin'
///
/// mixinDeclaration ::= 'base'? 'mixin' typeIdentifier typeParameters?
/// ('on' typeNotVoidList)? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
///
/// @description Check that it is not an error to declare a variable named
/// `base`, `sealed`, `interface`, `abstract` or `mixin`
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

main() {
var base = 1;
var sealed = 2;
var interface = 3;
var abstract = 4;
var mixin = 5;

print(base);
print(sealed);
print(interface);
print(abstract);
print(mixin);
}
46 changes: 46 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 The grammar is:
///
/// classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
/// typeParameters? superclass? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
/// | classModifiers 'class' mixinApplicationClass
///
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
///
/// mixinClassModifiers ::= 'abstract'? 'base'? 'mixin'
///
/// mixinDeclaration ::= 'base'? 'mixin' typeIdentifier typeParameters?
/// ('on' typeNotVoidList)? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
///
/// @description Check that it is a compile-time error if 'base', 'interface' or
/// 'final' modifiers are placed before an `abstract` modifier
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

base abstract class C1 {}
//^^^^
// [analyzer] unspecified
// [cfe] unspecified

interface abstract class C2 {}
//^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

final abstract class C3 {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(C1);
print(C2);
print(C3);
}
70 changes: 70 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A02_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 The grammar is:
///
/// classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
/// typeParameters? superclass? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
/// | classModifiers 'class' mixinApplicationClass
///
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
///
/// mixinClassModifiers ::= 'abstract'? 'base'? 'mixin'
///
/// mixinDeclaration ::= 'base'? 'mixin' typeIdentifier typeParameters?
/// ('on' typeNotVoidList)? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
///
/// @description Check that it is a compile-time error if 'mixin', 'base', or
/// `abstract` modifiers goes in a wrong order
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

base abstract mixin class C1 {}
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

base mixin abstract class C2 {}
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

mixin base abstract class C3 {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

mixin abstract base class C4 {}
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract mixin base class C5 {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

mixin abstract class C6 {}
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

mixin base class C7 {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(C1);
print(C2);
print(C3);
print(C4);
print(C5);
print(C6);
print(C7);
}

0 comments on commit b8bcb3d

Please sign in to comment.