Skip to content

Commit

Permalink
#2825. Add enhanced parts tests for top-level declarations and owners…
Browse files Browse the repository at this point in the history
…hip (#2842)

Add enhanced parts tests for top-level declarations and ownership. Note that a `part of` directive followed by a `part` directive is currently a syntax error. This will be corrected.
  • Loading branch information
sgrekhov authored Sep 2, 2024
1 parent 410a74e commit 36ad405
Show file tree
Hide file tree
Showing 13 changed files with 676 additions and 0 deletions.
38 changes: 38 additions & 0 deletions LanguageFeatures/Parts-with-imports/ownership_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 unit of ownership is the library. It’s quite possible for one
/// part file to introduce a conflict with another part file. It always was, but
/// there are new ways too. If that happens, the library owner, who most likely
/// introduced the problem, is expected to fix it. There is no attempt to hide
/// name conflicts between declarations in separate tree-branches of the library
/// structure.
///
/// @description Check that it is a compile-time error if different part files
/// have non-augmenting declarations with the same name.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part 'ownership_A01_t01_part1.dart';

String variable = "variable main";
String get getter => "getter main";
String function() => "function main";

class C {}
mixin M {}
class A {}
extension Ext on A {}
extension type ET(int _) {}

main() {
print(variable);
print(getter);
print(function);
print(C);
print(M);
print(A);
print(ET);
}
43 changes: 43 additions & 0 deletions LanguageFeatures/Parts-with-imports/ownership_A01_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 The unit of ownership is the library. It’s quite possible for one
/// part file to introduce a conflict with another part file. It always was, but
/// there are new ways too. If that happens, the library owner, who most likely
/// introduced the problem, is expected to fix it. There is no attempt to hide
/// name conflicts between declarations in separate tree-branches of the library
/// structure.
///
/// @description Check that it is a compile-time error if different part files
/// have non-augmenting declarations with the same name.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'ownership_A01_t01.dart';
part 'ownership_A01_t01_part2.dart';

String variable = "variable part1";
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
String get getter => "getter part1";
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

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

void set setter(String _) {}

enum E {
e0;
}
45 changes: 45 additions & 0 deletions LanguageFeatures/Parts-with-imports/ownership_A01_t01_part2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 unit of ownership is the library. It’s quite possible for one
/// part file to introduce a conflict with another part file. It always was, but
/// there are new ways too. If that happens, the library owner, who most likely
/// introduced the problem, is expected to fix it. There is no attempt to hide
/// name conflicts between declarations in separate tree-branches of the library
/// structure.
///
/// @description Check that it is a compile-time error if different part files
/// have non-augmenting declarations with the same name.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'ownership_A01_t01_part1.dart';

String function() => "function part2";
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

void set setter(String _) {}
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

extension Ext on A {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

enum E {
// ^
// [analyzer] unspecified
// [cfe] unspecified
e0;
}

extension type ET(int _) {}
// ^^
// [analyzer] unspecified
// [cfe] unspecified
39 changes: 39 additions & 0 deletions LanguageFeatures/Parts-with-imports/parts_lib.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 Common library for "Parts with imports" tests.
///
/// @description Common library for "Parts with imports" tests.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

library parts_lib;

String log = "";

String libVar = "libVar";
String get libGetter => "libGetter";
void set libSetter(String _) {
log = "libSetter";
}
String libFunc() => "libFunc";

class LibClass {
static final String id = "LibClass";
}
mixin LibMixin {
static final String id = "LibMixin";
}
enum LibEnum {
e0;
static final String id = "LibEnum";
}
class A {}
extension LibExt on A {
static final String id = "LibExt";
}
extension type LibET(int _) {
static final String id = "LibET";
}
71 changes: 71 additions & 0 deletions LanguageFeatures/Parts-with-imports/top_level_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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 Library member declarations are library-global: All top-level
/// declarations in the library file and all transitive part files are equal,
/// and are all in scope in every file. They introduce declarations into the
/// library’s declaration scope, which is the most significant scope in all
/// files of the library. If there is any conflict with imported names,
/// top-level declarations win!
///
/// @description Check that all top-level declarations in the library file and
/// all transitive part files are all in scope in every file.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

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

String mainVar = "mainVar";
String get mainGetter => "mainGetter";
void set mainSetter(String _) {}
String mainFunc() => "mainFunc";

class MainClass {
static final id = "MainClass";
}

mixin MainMixin {
static final id = "MainMixin";
}

enum MainEnum {
e0;
static final id = "MainEnum";
}

class A {}

extension MainExt on A {
static final id = "MainExt";
}

extension type MainET(int _) {
static final id = "MainET";
}

main() {
Expect.equals("part1Var", part1Var);
Expect.equals("part1Getter", part1Getter);
part1Setter = "x";
Expect.equals("part1Func", part1Func);
Expect.equals("Part1Class", Part1Class.id);
Expect.equals("Part1Mixin", Part1Mixin.id);
Expect.equals("Part1Enum", Part1Enum.id);
Expect.equals("Part1Ext", Part1Ext.id);
Expect.equals("Part1ET", Part1ET.id);

Expect.equals("part2Var", part2Var);
Expect.equals("part2Getter", part2Getter);
part2Setter = "x";
Expect.equals("part2Func", part2Func);
Expect.equals("Part2Class", Part2Class.id);
Expect.equals("Part2Mixin", Part2Mixin.id);
Expect.equals("Part2Enum", Part2Enum.id);
Expect.equals("Part2Ext", Part2Ext.id);
Expect.equals("Part2ET", Part2ET.id);
testPart1();
testPart2();
}
67 changes: 67 additions & 0 deletions LanguageFeatures/Parts-with-imports/top_level_A01_t01_part1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 Library member declarations are library-global: All top-level
/// declarations in the library file and all transitive part files are equal,
/// and are all in scope in every file. They introduce declarations into the
/// library’s declaration scope, which is the most significant scope in all
/// files of the library. If there is any conflict with imported names,
/// top-level declarations win!
///
/// @description Check that all top-level declarations in the library file and
/// all transitive part files are all in scope in every file.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'top_level_A01_t01.dart';
part 'top_level_A01_t01_part2.dart';

String part1Var = "part1Var";
String get part1Getter => "part1Getter";
void set part1Setter(String _) {}
String part1Func() => "part1Func";

class Part1Class {
static final id = "Part1Class";
}

mixin Part1Mixin {
static final id = "Part1Mixin";
}

enum Part1Enum {
e0;
static final id = "Part1Enum";
}

extension Part1Ext on A {
static final id = "Part1Ext";
}

extension type Part1ET(int _) {
static final id = "Part1ET";
}

testPart1() {
Expect.equals("mainVar", mainVar);
Expect.equals("mainGetter", mainGetter);
mainSetter = "x";
Expect.equals("mainFunc", mainFunc);
Expect.equals("MainClass", MainClass.id);
Expect.equals("MainMixin", MainMixin.id);
Expect.equals("MainEnum", MainEnum.id);
Expect.equals("MainExt", MainExt.id);
Expect.equals("MainET", MainET.id);

Expect.equals("part2Var", part2Var);
Expect.equals("part2Getter", part2Getter);
part2Setter = "x";
Expect.equals("part2Func", part2Func);
Expect.equals("Part2Class", Part2Class.id);
Expect.equals("Part2Mixin", Part2Mixin.id);
Expect.equals("Part2Enum", Part2Enum.id);
Expect.equals("Part2Ext", Part2Ext.id);
Expect.equals("Part2ET", Part2ET.id);
}
66 changes: 66 additions & 0 deletions LanguageFeatures/Parts-with-imports/top_level_A01_t01_part2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 Library member declarations are library-global: All top-level
/// declarations in the library file and all transitive part files are equal,
/// and are all in scope in every file. They introduce declarations into the
/// library’s declaration scope, which is the most significant scope in all
/// files of the library. If there is any conflict with imported names,
/// top-level declarations win!
///
/// @description Check that all top-level declarations in the library file and
/// all transitive part files are all in scope in every file.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-parts

part of 'top_level_A01_t01_part1.dart';

String part2Var = "part2Var";
String get part2Getter => "part2Getter";
void set part2Setter(String _) {}
String part2Func() => "part2Func";

class Part2Class {
static final id = "Part2Class";
}

mixin Part2Mixin {
static final id = "Part2Mixin";
}

enum Part2Enum {
e0;
static final id = "Part2Enum";
}

extension Part2Ext on A {
static final id = "Part2Ext";
}

extension type Part2ET(int _) {
static final id = "Part2ET";
}

testPart2() {
Expect.equals("mainVar", mainVar);
Expect.equals("mainGetter", mainGetter);
mainSetter = "x";
Expect.equals("mainFunc", mainFunc);
Expect.equals("MainClass", MainClass.id);
Expect.equals("MainMixin", MainMixin.id);
Expect.equals("MainEnum", MainEnum.id);
Expect.equals("MainExt", MainExt.id);
Expect.equals("MainET", MainET.id);

Expect.equals("part1Var", part1Var);
Expect.equals("part1Getter", part1Getter);
part1Setter = "x";
Expect.equals("part1Func", part1Func);
Expect.equals("Part1Class", Part1Class.id);
Expect.equals("Part1Mixin", Part1Mixin.id);
Expect.equals("Part1Enum", Part1Enum.id);
Expect.equals("Part1Ext", Part1Ext.id);
Expect.equals("Part1ET", Part1ET.id);
}
Loading

0 comments on commit 36ad405

Please sign in to comment.