Skip to content

Commit

Permalink
dart-lang#2825. Add scope tests. Part 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Sep 9, 2024
1 parent 2494f09 commit 8e9beda
Show file tree
Hide file tree
Showing 15 changed files with 726 additions and 0 deletions.
25 changes: 25 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A05_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024, 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 Let P be a prefix scope containing all the import prefixes
/// declared by the current file. The parent scope of P is I.
/// ...
/// - If an import is `deferred`, its Pname is a deferred scope which
/// has an extra `loadLibrary` member added, as usual, and the import has an
/// implicit `hide loadLibrary` modifier.
///
/// @description Check that if an import is deferred an extra `loadLibrary`
/// member is added and it is a runtime error to access any of its members
/// before `loadLibrary()` completes successfully. Test the case when
/// `loadLibrary()` is called from another part file.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

import '../../Utils/expect.dart';
part 'scope_A05_t02_part1.dart';

main() {
testPart2();
}
24 changes: 24 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A05_t02_part1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2024, 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 Let P be a prefix scope containing all the import prefixes
/// declared by the current file. The parent scope of P is I.
/// ...
/// - If an import is `deferred`, its Pname is a deferred scope which
/// has an extra `loadLibrary` member added, as usual, and the import has an
/// implicit `hide loadLibrary` modifier.
///
/// @description Check that if an import is deferred an extra `loadLibrary`
/// member is added and it is a runtime error to access any of its members
/// before `loadLibrary()` completes successfully. Test the case when
/// `loadLibrary()` is called from another part file.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A05_t02.dart';

import 'scope_lib1.dart' deferred as l1;

part 'scope_A05_t02_part2.dart';
47 changes: 47 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A05_t02_part2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2024, 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 Let P be a prefix scope containing all the import prefixes
/// declared by the current file. The parent scope of P is I.
/// ...
/// - If an import is `deferred`, its Pname is a deferred scope which
/// has an extra `loadLibrary` member added, as usual, and the import has an
/// implicit `hide loadLibrary` modifier.
///
/// @description Check that if an import is deferred an extra `loadLibrary`
/// member is added and it is a runtime error to access any of its members
/// before `loadLibrary()` completes successfully. Test the case when
/// `loadLibrary()` is called from another part file.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A05_t02_part1.dart';

testPart2() async {
// From scope_lib1.dart
Expect.throws(() {print(l1.libVar);});
Expect.throws(() {print(l1.libGetter);});
Expect.throws(() {l1.libSetter = "x";});
Expect.throws(() {print(l1.libFunc);});
Expect.throws(() {print(l1.LibClass.id);});
Expect.throws(() {print(l1.LibMixin.id);});
Expect.throws(() {print(l1.LibEnum.id);});
Expect.throws(() {print(l1.LibExt.id);});
Expect.throws(() {print(l1.LibET.id);});

await l1.loadLibrary();

Expect.equals("scope_lib1 libVar", l1.libVar);
Expect.equals("scope_lib1 libGetter", l1.libGetter);
l1.libSetter = "x";
Expect.equals("scope_lib1 libFunc", l1.libFunc);
Expect.equals("scope_lib1 LibClass", l1.LibClass.id);
Expect.equals("scope_lib1 LibMixin", l1.LibMixin.id);
Expect.equals("scope_lib1 LibEnum", l1.LibEnum.id);
Expect.equals("scope_lib1 LibExt", l1.LibExt.id);
Expect.equals("scope_lib1 LibET", l1.LibET.id);

await l1.loadLibrary(); // Not an error
}
30 changes: 30 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A06_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2024, 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 Let P be a prefix scope containing all the import prefixes
/// declared by the current file. The parent scope of P is I.
/// ...
/// - If Pname is not `deferred`, and the parent scope in C has a non-deferred
/// prefix import scope with the same name, Cname, then the parent scope of
/// Pname is Cname. A part file can use the same prefix as a prefix that it
/// inherits, because inherited imports are only suggestions. If it adds to
/// that import scope, by importing into it, that can shadow existing
/// declarations, just like in the top-level declaration scope. A deferred
/// prefix import scope cannot be extended, and cannot extend another prefix
/// scope, deferred prefix scopes are always linked to a single import
/// directive.
///
/// @description Check that a part file can use the same prefix as a prefix that
/// it inherits. In this case it shadows inherited declarations.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

import '../../Utils/expect.dart';
part 'scope_A06_t01_part1.dart';

main() {
testPart1();
testPart2();
}
42 changes: 42 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A06_t01_part1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2024, 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 Let P be a prefix scope containing all the import prefixes
/// declared by the current file. The parent scope of P is I.
/// ...
/// - If Pname is not `deferred`, and the parent scope in C has a non-deferred
/// prefix import scope with the same name, Cname, then the parent scope of
/// Pname is Cname. A part file can use the same prefix as a prefix that it
/// inherits, because inherited imports are only suggestions. If it adds to
/// that import scope, by importing into it, that can shadow existing
/// declarations, just like in the top-level declaration scope. A deferred
/// prefix import scope cannot be extended, and cannot extend another prefix
/// scope, deferred prefix scopes are always linked to a single import
/// directive.
///
/// @description Check that a part file can use the same prefix as a prefix that
/// it inherits. In this case it shadows inherited declarations.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A06_t01.dart';

import 'parts_lib.dart' as l;

part 'scope_A06_t01_part2.dart';

testPart1() async {
// From parts_lib.dart
Expect.equals("libVar", l.libVar);
Expect.equals("libGetter", l.libGetter);
l.libSetter = "x";
Expect.equals("libSetter", l.log);
Expect.equals("libFunc", l.libFunc);
Expect.equals("LibClass", l.LibClass.id);
Expect.equals("LibMixin", l.LibMixin.id);
Expect.equals("LibEnum", l.LibEnum.id);
Expect.equals("LibExt", l.LibExt.id);
Expect.equals("LibET", l.LibET.id);
}
42 changes: 42 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A06_t01_part2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2024, 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 Let P be a prefix scope containing all the import prefixes
/// declared by the current file. The parent scope of P is I.
/// ...
/// - If Pname is not `deferred`, and the parent scope in C has a non-deferred
/// prefix import scope with the same name, Cname, then the parent scope of
/// Pname is Cname. A part file can use the same prefix as a prefix that it
/// inherits, because inherited imports are only suggestions. If it adds to
/// that import scope, by importing into it, that can shadow existing
/// declarations, just like in the top-level declaration scope. A deferred
/// prefix import scope cannot be extended, and cannot extend another prefix
/// scope, deferred prefix scopes are always linked to a single import
/// directive.
///
/// @description Check that a part file can use the same prefix as a prefix that
/// it inherits. In this case it shadows inherited declarations.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A06_t01_part1.dart';

import 'scope_lib1.dart' as l;

testPart2() async {
// From scope_lib1.dart
Expect.equals("scope_lib1 libVar", l.libVar);
Expect.equals("scope_lib1 libGetter", l.libGetter);
l.libSetter = "x";
Expect.equals("libSetter", l.log);
Expect.equals("scope_lib1 libFunc", l.libFunc);
Expect.equals("scope_lib1 LibClass", l.LibClass.id);
Expect.equals("scope_lib1 LibMixin", l.LibMixin.id);
Expect.equals("scope_lib1 LibEnum", l.LibEnum.id);
Expect.equals("scope_lib1 LibExt", l.LibExt.id);
Expect.equals("scope_lib1 LibET", l.LibET.id);
// From parts_lib.dart
Expect.equals(0, l.counter);
}
37 changes: 37 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A07_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2024, 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 combined import scope of a Dart file is a chain of the
/// combined import scopes of the file and its parent files, each step adding
/// two scopes: The (unnamed, top-level) import scope of the unprefixed imports
/// and the prefix scope with prefixed imports, each shadowing names further up
/// in the chain.
///
/// @description Check that it is a compile-time error to access an import
/// declared in any of part files.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part 'scope_A07_t01_part1.dart';

main() {
print(libVar); // from scope_lib1.dart
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

print(l1.lib2Func()); // from scope_lib2.dart
// ^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

print(counter); // from parts_lib.dart
// ^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

testPart1();
testPart2();
}
31 changes: 31 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A07_t01_part1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024, 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 combined import scope of a Dart file is a chain of the
/// combined import scopes of the file and its parent files, each step adding
/// two scopes: The (unnamed, top-level) import scope of the unprefixed imports
/// and the prefix scope with prefixed imports, each shadowing names further up
/// in the chain.
///
/// @description Check that it is a compile-time error to access an import
/// declared in any of part files.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A07_t01.dart';

import 'scope_lib.dart';
import 'scope_lib2.dart' as l1;

part 'scope_A07_t01_part2.dart';

testPart1() {
print(libVar); // from scope_lib1.dart
print(l1.lib2Func()); // from scope_lib2.dart
print(counter); // from parts_lib.dart
// ^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
25 changes: 25 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A07_t01_part2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024, 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 combined import scope of a Dart file is a chain of the
/// combined import scopes of the file and its parent files, each step adding
/// two scopes: The (unnamed, top-level) import scope of the unprefixed imports
/// and the prefix scope with prefixed imports, each shadowing names further up
/// in the chain.
///
/// @description Check that it is a compile-time error to access an import
/// declared in any of part files.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A07_t01_part1.dart';

import 'parts_lib.dart';

testPart2() {
print(libVar); // from scope_lib1.dart
print(l1.lib2Func()); // from scope_lib2.dart
print(counter); // from parts_lib.dart
}
31 changes: 31 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A08_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024, 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 It’s a compile-time error if any file declares an import prefix
/// with the same base name as a top-level declaration of the library.
///
/// @description Check that it is a compile-time error if a part-file declares
/// an import prefix with the same base name as a top-level declaration.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part 'scope_A08_t01_part1.dart';

int l1 = 1;
int get l2 => 2;
void set l3(int _) {}
int l4() => 4;

class l5 {}
mixin l6 {}
enum l7 {e0;}
class A {}
extension l8 on A {}
extension type l9(int _) {}

main() {
testPart1();
testPart2();
}
Loading

0 comments on commit 8e9beda

Please sign in to comment.