Skip to content

Commit

Permalink
#2825. Add scope tests. Part 2. (#2847)
Browse files Browse the repository at this point in the history
Add scope tests. Part 2
  • Loading branch information
sgrekhov authored Sep 9, 2024
1 parent 2494f09 commit e4193ef
Show file tree
Hide file tree
Showing 21 changed files with 689 additions and 0 deletions.
25 changes: 25 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A02_t06.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’s introduce importsOf(S), where S is a set of `import`
/// directives from a single Dart file, to refer to that computation, which
/// introduces a scope containing the declarations introduced by all the
/// `import`s (the declarations of the export scope of each imported library,
/// minus those hidden by a `show` or `hide` operator, combined such that a name
/// conflicts of different declarations is not an error, but the name is marked
/// as conflicted in the scope, and then referencing it is an error.)
///
/// @description Check that unprefixed import scope contains all top-level
/// declarations introduced by all the `import` directives. Test `import`
/// directives with `export`.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

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

main() {
testPart1();
}
30 changes: 30 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A02_t06_part1.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’s introduce importsOf(S), where S is a set of `import`
/// directives from a single Dart file, to refer to that computation, which
/// introduces a scope containing the declarations introduced by all the
/// `import`s (the declarations of the export scope of each imported library,
/// minus those hidden by a `show` or `hide` operator, combined such that a name
/// conflicts of different declarations is not an error, but the name is marked
/// as conflicted in the scope, and then referencing it is an error.)
///
/// @description Check that unprefixed import scope contains all top-level
/// declarations introduced by all the `import` directives. Test `import`
/// directives with `export`.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A02_t06.dart';

import 'scope_lib3.dart';

testPart1() {
// From scope_lib2.dart
Expect.equals("scope_lib2", libId);
Expect.equals("scope_lib2 lib2Func", lib2Func());
// From scope_lib3.dart
Expect.equals("scope_lib3 lib3Func", lib3Func());
}
23 changes: 23 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A02_t07.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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’s introduce importsOf(S), where S is a set of `import`
/// directives from a single Dart file, to refer to that computation, which
/// introduces a scope containing the declarations introduced by all the
/// `import`s (the declarations of the export scope of each imported library,
/// minus those hidden by a `show` or `hide` operator, combined such that a name
/// conflicts of different declarations is not an error, but the name is marked
/// as conflicted in the scope, and then referencing it is an error.)
///
/// @description Check that it is a compile-time error to access exported
/// members hidden by `hide` and `show`.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part 'scope_A02_t07_part1.dart';

main() {
testPart1();
}
68 changes: 68 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A02_t07_part1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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’s introduce importsOf(S), where S is a set of `import`
/// directives from a single Dart file, to refer to that computation, which
/// introduces a scope containing the declarations introduced by all the
/// `import`s (the declarations of the export scope of each imported library,
/// minus those hidden by a `show` or `hide` operator, combined such that a name
/// conflicts of different declarations is not an error, but the name is marked
/// as conflicted in the scope, and then referencing it is an error.)
///
/// @description Check that it is a compile-time error to access exported
/// members hidden by `hide` and `show`.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A02_t07.dart';

import 'scope_lib4.dart';

testPart1() {
// From scope_lib1.dart
print(libVar);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
print(libGetter);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
libSetter = "";
//^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
print(libFunc);
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
print(LibClass); // Ok
print(LibMixin);
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
print(LibEnum);
// ^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
print(LibExt.id);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
print(LibET);
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

// From scope_lib2.dart
print(libId); // Ok
print(lib2Func());
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

// From scope_lib4.dart
print(lib4Func()); // Ok
}
27 changes: 27 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A03_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.
/// - The P scope contains an entry for each name where the current file has an
/// `import` directive with that name as prefix, `as name`. (If an import is
/// `deferred`, it’s a compile-time error if more than one `import` directive
/// in the same file has that prefix name, as usual. It’s not an error if two
/// import deferred prefixes have the same name if they occur in different
/// files, other file’s imports are only suggestions.)
///
/// @description Check that a prefix scope contains an entry for each name where
/// the current file has an `import` directive with that name as prefix,
/// `as name`.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

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

main() {
testPart1();
testPart2();
}
43 changes: 43 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A03_t01_part1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.
/// - The P scope contains an entry for each name where the current file has an
/// `import` directive with that name as prefix, `as name`. (If an import is
/// `deferred`, it’s a compile-time error if more than one `import` directive
/// in the same file has that prefix name, as usual. It’s not an error if two
/// import deferred prefixes have the same name if they occur in different
/// files, other file’s imports are only suggestions.)
///
/// @description Check that a prefix scope contains an entry for each name where
/// the current file has an `import` directive with that name as prefix,
/// `as name`.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A03_t01.dart';

import 'scope_lib1.dart' as l1;
import 'scope_lib2.dart' as l2;

part 'scope_A03_t01_part2.dart';

testPart1() {
// From scope_lib1.dart
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);

// From scope_lib2.dart
Expect.equals("scope_lib2", l2.libId);
Expect.equals("scope_lib2 lib2Func", l2.lib2Func());
}
55 changes: 55 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A03_t01_part2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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.
/// - The P scope contains an entry for each name where the current file has an
/// `import` directive with that name as prefix, `as name`. (If an import is
/// `deferred`, it’s a compile-time error if more than one `import` directive
/// in the same file has that prefix name, as usual. It’s not an error if two
/// import deferred prefixes have the same name if they occur in different
/// files, other file’s imports are only suggestions.)
///
/// @description Check that a prefix scope contains an entry for each name where
/// the current file has an `import` directive with that name as prefix,
/// `as name`.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A03_t01_part1.dart';

import 'scope_lib1.dart' as l3;
import 'scope_lib2.dart' as l4;

part 'scope_A03_t01_part2.dart';

testPart2() {
// From scope_lib1.dart
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);

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

// From scope_lib2.dart
Expect.equals("scope_lib2", l2.libId);
Expect.equals("scope_lib2 lib2Func", l2.lib2Func());
Expect.equals("scope_lib2", l4.libId);
Expect.equals("scope_lib2 lib2Func", l4.lib2Func());
}
25 changes: 25 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A03_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.
/// - The P scope contains an entry for each name where the current file has an
/// `import` directive with that name as prefix, `as name`. (If an import is
/// `deferred`, it’s a compile-time error if more than one `import` directive
/// in the same file has that prefix name, as usual. It’s not an error if two
/// import deferred prefixes have the same name if they occur in different
/// files, other file’s imports are only suggestions.)
///
/// @description Check that it’s a compile-time error if two deferred `import`
/// directives in the same part file have the same prefix name.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part 'scope_A03_t02_part1.dart';

main() {
testPart1();
testPart2();
}
32 changes: 32 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A03_t02_part1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.
/// - The P scope contains an entry for each name where the current file has an
/// `import` directive with that name as prefix, `as name`. (If an import is
/// `deferred`, it’s a compile-time error if more than one `import` directive
/// in the same file has that prefix name, as usual. It’s not an error if two
/// import deferred prefixes have the same name if they occur in different
/// files, other file’s imports are only suggestions.)
///
/// @description Check that it’s a compile-time error if two deferred `import`
/// directives in the same part file have the same prefix name.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A03_t02.dart';

import 'scope_lib1.dart' deferred as d;
import 'scope_lib2.dart' deferred as d;
// ^
// [analyzer] unspecified
// [cfe] unspecified

part 'scope_A03_t02_part2.dart'

testPart1() {
print("Part 1");
}
30 changes: 30 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A03_t02_part2.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.
/// - The P scope contains an entry for each name where the current file has an
/// `import` directive with that name as prefix, `as name`. (If an import is
/// `deferred`, it’s a compile-time error if more than one `import` directive
/// in the same file has that prefix name, as usual. It’s not an error if two
/// import deferred prefixes have the same name if they occur in different
/// files, other file’s imports are only suggestions.)
///
/// @description Check that it’s a compile-time error if two deferred `import`
/// directives in the same part file have the same prefix name.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'scope_A03_t02_part1.dart';

import 'scope_lib1.dart' deferred as d;
import 'scope_lib2.dart' deferred as d;
// ^
// [analyzer] unspecified
// [cfe] unspecified

testPart2() {
print("Part 2");
}
26 changes: 26 additions & 0 deletions LanguageFeatures/Parts-with-imports/scope_A03_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.
/// - The P scope contains an entry for each name where the current file has an
/// `import` directive with that name as prefix, `as name`. (If an import is
/// `deferred`, it’s a compile-time error if more than one `import` directive
/// in the same file has that prefix name, as usual. It’s not an error if two
/// import deferred prefixes have the same name if they occur in different
/// files, other file’s imports are only suggestions.)
///
/// @description Check that it is not an error if two deferred `import`
/// directives have the same prefix name but occurs in a different files.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

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

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

0 comments on commit e4193ef

Please sign in to comment.