Skip to content

Commit

Permalink
#2846. Add unquoted imports tests for parts (#2890)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov authored Sep 25, 2024
1 parent ab4d8e4 commit 45fb6ba
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LanguageFeatures/Unquoted-imports/lib/co19_unquoted_imports.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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 We make a breaking change and remove support for the
/// long-deprecated library name syntax from `part of` directives. An unquoted
/// series of identifiers after `part of` then gets unambiguously interpreted as
/// this proposal's semantics. In other words, `part of foo.bar;` is part of the
/// library at `package:foo/bar.dart`, not part of the library with name
/// `foo.bar`.
///
/// @description Checks that unquoted syntax can be used in `part` and `part of`
/// directives.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports,enhanced-parts

part of co19_unquoted_imports/part_A01_t02;
part co19_unquoted_imports/co19_unquoted_imports_part;

String partId = "co19_unquoted_imports.dart";
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 We make a breaking change and remove support for the
/// long-deprecated library name syntax from `part of` directives. An unquoted
/// series of identifiers after `part of` then gets unambiguously interpreted as
/// this proposal's semantics. In other words, `part of foo.bar;` is part of the
/// library at `package:foo/bar.dart`, not part of the library with name
/// `foo.bar`.
///
/// @description Checks that unquoted syntax can be used in `part` and `part of`
/// directives.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports,enhanced-parts

part of co19_unquoted_imports;

String partId2 = "co19_unquoted_imports_part.dart";
24 changes: 24 additions & 0 deletions LanguageFeatures/Unquoted-imports/lib/part_A01_t01.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 We make a breaking change and remove support for the
/// long-deprecated library name syntax from `part of` directives. An unquoted
/// series of identifiers after `part of` then gets unambiguously interpreted as
/// this proposal's semantics. In other words, `part of foo.bar;` is part of the
/// library at `package:foo/bar.dart`, not part of the library with name
/// `foo.bar`.
///
/// @description Checks that unquoted syntax can be used in `part` and `part of`
/// directives.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports

part co19_unquoted_imports/part_A01_t01_part;

main() {
if (partId != "part_A01_t01_part.dart") { // Cannot use expect.dart here
throw "Wrong part '$partId'";
}
}
20 changes: 20 additions & 0 deletions LanguageFeatures/Unquoted-imports/lib/part_A01_t01_part.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 We make a breaking change and remove support for the
/// long-deprecated library name syntax from `part of` directives. An unquoted
/// series of identifiers after `part of` then gets unambiguously interpreted as
/// this proposal's semantics. In other words, `part of foo.bar;` is part of the
/// library at `package:foo/bar.dart`, not part of the library with name
/// `foo.bar`.
///
/// @description Checks that unquoted syntax can be used in `part` and `part of`
/// directives.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports

part of co19_unquoted_imports/part_A01_t01;

String partId = "part_A01_t01_part.dart";
27 changes: 27 additions & 0 deletions LanguageFeatures/Unquoted-imports/lib/part_A01_t02.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 We make a breaking change and remove support for the
/// long-deprecated library name syntax from `part of` directives. An unquoted
/// series of identifiers after `part of` then gets unambiguously interpreted as
/// this proposal's semantics. In other words, `part of foo.bar;` is part of the
/// library at `package:foo/bar.dart`, not part of the library with name
/// `foo.bar`.
///
/// @description Checks that unquoted syntax can be used in `part` and `part of`
/// directives.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports,enhanced-parts

part co19_unquoted_imports;

main() {
if (partId != "co19_unquoted_imports.dart") { // Cannot use expect.dart here
throw "Wrong part '$partId'";
}
if (partId2 != "co19_unquoted_imports_part.dart") {
throw "Wrong part '$partId2'";
}
}
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 There are two directives for working with part files, `part` and
/// `part of`. This means that when the parser sees `part of`, it doesn't
/// immediately know if it is looking at a `part` directive followed by an
/// unquoted identifier like `part of`; or `part of.some/other.thing;` versus a
/// `part of` directive like `part of thing;` or `part of 'uri.dart';` It must
/// lookahead past the of identifier to see if the next token is `;`, `.`, `/`,
/// or another identifier.
///
/// @description Checks that `part of.parts.test` is parsed like a
/// `part 'package:of.parts.test/test.dart';`.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports

part of.parts.test;

main() {
if (partId != "test") { // Cannot use expect.dart here
throw "Wrong part '$partId'";
}
}
21 changes: 21 additions & 0 deletions LanguageFeatures/Unquoted-imports/of.parts.test/lib/test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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 There are two directives for working with part files, `part` and
/// `part of`. This means that when the parser sees `part of`, it doesn't
/// immediately know if it is looking at a `part` directive followed by an
/// unquoted identifier like `part of`; or `part of.some/other.thing;` versus a
/// `part of` directive like `part of thing;` or `part of 'uri.dart';` It must
/// lookahead past the of identifier to see if the next token is `;`, `.`, `/`,
/// or another identifier.
///
/// @description Checks that `part of.parts.test` is parsed like a
/// `part 'package:of.parts.test/test.dart';`.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports

part of of.parts.test/part_A02_t01;

String partId = "test";
8 changes: 8 additions & 0 deletions LanguageFeatures/Unquoted-imports/of.parts.test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: of.parts.test
description: Internal package used by co19 tests for Unquoted imports feature

# This tests isn't intended for publishing on pub.dev.
publish_to: none

environment:
sdk: '>=3.6.0-255.0.dev'

0 comments on commit 45fb6ba

Please sign in to comment.