Skip to content

Commit

Permalink
dart-lang#2825. Add import inheritance and grammar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Sep 3, 2024
1 parent e80817a commit 8a6e7e7
Show file tree
Hide file tree
Showing 18 changed files with 425 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LanguageFeatures/Parts-with-imports/grammar_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 a Dart (parent) file with URI P has
/// a `part` directive with a URI U, and the source content for the URI U does
/// not parse as a `<partDirective>`, or if its leading `<partHeader>`'s `<uri>`
/// string, resolved as a URI reference against the URI U, does not denote the
/// library of P. That is, if a Dart file has a part directive, its target must
/// be a part file whose “part of” directive points back to the first Dart file.
/// Nothing new, except that now the parent file may not be a library file.)
///
/// @description Check that it is a compile-time error if a parent file which is
/// not a library file points to a not existing file in its `part` directive.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

part 'grammar_A01_t01_part1.dart';

main() {
}
23 changes: 23 additions & 0 deletions LanguageFeatures/Parts-with-imports/grammar_A01_t01_part1.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 It’s a compile-time error if a Dart (parent) file with URI P has
/// a `part` directive with a URI U, and the source content for the URI U does
/// not parse as a `<partDirective>`, or if its leading `<partHeader>`'s `<uri>`
/// string, resolved as a URI reference against the URI U, does not denote the
/// library of P. That is, if a Dart file has a part directive, its target must
/// be a part file whose “part of” directive points back to the first Dart file.
/// Nothing new, except that now the parent file may not be a library file.)
///
/// @description Check that it is a compile-time error if a parent file which is
/// not a library file points to a not existing file in its `part` directive.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

part of 'grammar_A01_t01.dart';
part 'grammar_A01_t01_part2.dart';
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
22 changes: 22 additions & 0 deletions LanguageFeatures/Parts-with-imports/grammar_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 a Dart (parent) file with URI P has
/// a `part` directive with a URI U, and the source content for the URI U does
/// not parse as a `<partDirective>`, or if its leading `<partHeader>`'s `<uri>`
/// string, resolved as a URI reference against the URI U, does not denote the
/// library of P. That is, if a Dart file has a part directive, its target must
/// be a part file whose “part of” directive points back to the first Dart file.
/// Nothing new, except that now the parent file may not be a library file.)
///
/// @description Check that it is a compile-time error if a parent file which is
/// not a library file points to a part file without `part of` directive.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

part 'grammar_A01_t02_part1.dart';

main() {
}
23 changes: 23 additions & 0 deletions LanguageFeatures/Parts-with-imports/grammar_A01_t02_part1.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 It’s a compile-time error if a Dart (parent) file with URI P has
/// a `part` directive with a URI U, and the source content for the URI U does
/// not parse as a `<partDirective>`, or if its leading `<partHeader>`'s `<uri>`
/// string, resolved as a URI reference against the URI U, does not denote the
/// library of P. That is, if a Dart file has a part directive, its target must
/// be a part file whose “part of” directive points back to the first Dart file.
/// Nothing new, except that now the parent file may not be a library file.)
///
/// @description Check that it is a compile-time error if a parent file which is
/// not a library file points to a part file without `part of` directive.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

part of 'grammar_A01_t02.dart';
part 'grammar_A01_t02_part2.dart';
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
19 changes: 19 additions & 0 deletions LanguageFeatures/Parts-with-imports/grammar_A01_t02_part2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 a Dart (parent) file with URI P has
/// a `part` directive with a URI U, and the source content for the URI U does
/// not parse as a `<partDirective>`, or if its leading `<partHeader>`'s `<uri>`
/// string, resolved as a URI reference against the URI U, does not denote the
/// library of P. That is, if a Dart file has a part directive, its target must
/// be a part file whose “part of” directive points back to the first Dart file.
/// Nothing new, except that now the parent file may not be a library file.)
///
/// @description Check that it is a compile-time error if a parent file which is
/// not a library file points to a part file without `part of` directive.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

foo() {}
23 changes: 23 additions & 0 deletions LanguageFeatures/Parts-with-imports/grammar_A01_t03.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 It’s a compile-time error if a Dart (parent) file with URI P has
/// a `part` directive with a URI U, and the source content for the URI U does
/// not parse as a `<partDirective>`, or if its leading `<partHeader>`'s `<uri>`
/// string, resolved as a URI reference against the URI U, does not denote the
/// library of P. That is, if a Dart file has a part directive, its target must
/// be a part file whose “part of” directive points back to the first Dart file.
/// Nothing new, except that now the parent file may not be a library file.)
///
/// @description Check that it is a compile-time error if a parent file which is
/// not a library file points to a part file with `part of` directive pointing
/// back to another file.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

part 'grammar_A01_t03_part1.dart';

main() {
}
23 changes: 23 additions & 0 deletions LanguageFeatures/Parts-with-imports/grammar_A01_t03_lib.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 It’s a compile-time error if a Dart (parent) file with URI P has
/// a `part` directive with a URI U, and the source content for the URI U does
/// not parse as a `<partDirective>`, or if its leading `<partHeader>`'s `<uri>`
/// string, resolved as a URI reference against the URI U, does not denote the
/// library of P. That is, if a Dart file has a part directive, its target must
/// be a part file whose “part of” directive points back to the first Dart file.
/// Nothing new, except that now the parent file may not be a library file.)
///
/// @description Check that it is a compile-time error if a parent file which is
/// not a library file points to a part file with `part of` directive pointing
/// back to another file.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

part 'grammar_A01_t03_part2.dart';

main() {
}
24 changes: 24 additions & 0 deletions LanguageFeatures/Parts-with-imports/grammar_A01_t03_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 It’s a compile-time error if a Dart (parent) file with URI P has
/// a `part` directive with a URI U, and the source content for the URI U does
/// not parse as a `<partDirective>`, or if its leading `<partHeader>`'s `<uri>`
/// string, resolved as a URI reference against the URI U, does not denote the
/// library of P. That is, if a Dart file has a part directive, its target must
/// be a part file whose “part of” directive points back to the first Dart file.
/// Nothing new, except that now the parent file may not be a library file.)
///
/// @description Check that it is a compile-time error if a parent file which is
/// not a library file points to a part file with `part of` directive pointing
/// back to another file.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

part of 'grammar_A01_t03.dart';
part 'grammar_A01_t03_part2.dart';
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
19 changes: 19 additions & 0 deletions LanguageFeatures/Parts-with-imports/grammar_A01_t03_part2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 a Dart (parent) file with URI P has
/// a `part` directive with a URI U, and the source content for the URI U does
/// not parse as a `<partDirective>`, or if its leading `<partHeader>`'s `<uri>`
/// string, resolved as a URI reference against the URI U, does not denote the
/// library of P. That is, if a Dart file has a part directive, its target must
/// be a part file whose “part of” directive points back to the first Dart file.
/// Nothing new, except that now the parent file may not be a library file.)
///
/// @description Check that it is a compile-time error if a parent file which is
/// not a library file points to a part file without `part of` directive.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

part of 'grammar_A01_t03_lib.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 Import inheritance is a only suggestion: Aka. other files’
/// imports cannot break your code (at least if you’re not depending on them). A
/// part file is never restricted by the imports it inherits from its parent
/// file. It can ignore and override all of them with imports of its own. That
/// allows a file, like a macro generated file, to import all its own
/// dependencies and be completely self-contained when it comes to imports.
///
/// @description Check that for the part file import, inherited from the parent,
/// can be overridden by it's own import.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

import 'parts_lib.dart';
import '../../Utils/expect.dart';

part 'import_inheritance_A01_t01_part1.dart';

main() {
Expect.equals("libVar", libVar);
Expect.equals("LibClass", LibClass.id);
Expect.equals("libGetter", libGetter);
Expect.equals("LibMixin", LibMixin.id);
testPart1();
testPart2();
}
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 Import inheritance is a only suggestion: Aka. other files’
/// imports cannot break your code (at least if you’re not depending on them). A
/// part file is never restricted by the imports it inherits from its parent
/// file. It can ignore and override all of them with imports of its own. That
/// allows a file, like a macro generated file, to import all its own
/// dependencies and be completely self-contained when it comes to imports.
///
/// @description Check that for the part file import, inherited from the parent,
/// can be overridden by it's own import.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

// Overrides parts_lib.dart
String libVar = "libVar lib1";

class LibClass {
static final String id = "LibClass lib1";
}

// Own declarations
String foo() => "foo lib1";

class C {
static final String id = "C lib1";
}
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 Import inheritance is a only suggestion: Aka. other files’
/// imports cannot break your code (at least if you’re not depending on them). A
/// part file is never restricted by the imports it inherits from its parent
/// file. It can ignore and override all of them with imports of its own. That
/// allows a file, like a macro generated file, to import all its own
/// dependencies and be completely self-contained when it comes to imports.
///
/// @description Check that for the part file import, inherited from the parent,
/// can be overridden by it's own import.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

// Overrides parts_lib.dart
String get libGetter => "libGetter lib2";

mixin LibMixin {
static final String id = "LibMixin lib2";
}

// Overrides import_inheritance_A01_t01_lib1.dart
String foo() => "foo lib2";

class C {
static final String id = "C lib2";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 Import inheritance is a only suggestion: Aka. other files’
/// imports cannot break your code (at least if you’re not depending on them). A
/// part file is never restricted by the imports it inherits from its parent
/// file. It can ignore and override all of them with imports of its own. That
/// allows a file, like a macro generated file, to import all its own
/// dependencies and be completely self-contained when it comes to imports.
///
/// @description Check that for the part file import, inherited from the parent,
/// can be overridden by it's own import.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

import 'import_inheritance_A01_t01_lib1.dart';

part of 'import_inheritance_A01_t01.dart';
part 'import_inheritance_A01_t01_part2.dart';

void testPart1() {
Expect.equals("libVar lib1", libVar);
Expect.equals("LibClass lib1", LibClass.id);
Expect.equals("foo lib1", foo());
Expect.equals("C lib1", C.id);
}
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 Import inheritance is a only suggestion: Aka. other files’
/// imports cannot break your code (at least if you’re not depending on them). A
/// part file is never restricted by the imports it inherits from its parent
/// file. It can ignore and override all of them with imports of its own. That
/// allows a file, like a macro generated file, to import all its own
/// dependencies and be completely self-contained when it comes to imports.
///
/// @description Check that for the part file import, inherited from the parent,
/// can be overridden by it's own import.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

import 'import_inheritance_A01_t01_lib2.dart';
part of 'import_inheritance_A01_t01_part1.dart';

void testPart2() {
Expect.equals("libGetter lib2", libGetter);
Expect.equals("LibMixin lib2", LibMixin.id);
Expect.equals("foo lib2", foo());
Expect.equals("C lib2", C.id);
}
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 Import inheritance is a only suggestion: Aka. other files’
/// imports cannot break your code (at least if you’re not depending on them). A
/// part file is never restricted by the imports it inherits from its parent
/// file. It can ignore and override all of them with imports of its own. That
/// allows a file, like a macro generated file, to import all its own
/// dependencies and be completely self-contained when it comes to imports.
///
/// @description Check that for the part file may import its own copy of the
/// library already imported by the parent.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=enhanced-parts

import 'parts_lib.dart';
import '../../Utils/expect.dart';

part 'import_inheritance_A01_t02_part1.dart';

main() {
Expect.equals(0, counter);
testPart1();
testPart2();
}
Loading

0 comments on commit 8a6e7e7

Please sign in to comment.