Skip to content

Commit

Permalink
dart-lang#1959. Grammar tests added (dart-lang#2031)
Browse files Browse the repository at this point in the history
Add grammar tests
  • Loading branch information
sgrekhov authored Apr 28, 2023
1 parent 80f4d80 commit be5c6fa
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 0 deletions.
33 changes: 33 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 a built-in identifier
/// `interface` is used as an identifier
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

class interface {}
// ^^^^^^^^^
// [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);
}
35 changes: 35 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A01_t03.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 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` or `interface`
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

main() {
var base = 1;
var sealed = 2;
var interface = 3;

print(base);
print(sealed);
print(interface);
}
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 be5c6fa

Please sign in to comment.