Skip to content

Commit

Permalink
#2559. Add tests for augment libraries visibility (#2561)
Browse files Browse the repository at this point in the history
Add tests for augment libraries visibility{
  • Loading branch information
sgrekhov authored Apr 9, 2024
1 parent 1d318c2 commit 425e7ef
Show file tree
Hide file tree
Showing 19 changed files with 556 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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 Declarations in any library augmentation or the augmented library
/// are visible to all of the others, including private ones.
///
/// @description Checks that declarations in an augmentation are visible in a
/// main library
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import '../../Utils/expect.dart';
import augment 'defining_augmentation_A01_t01_lib.dart';

extension on C1 {
String get z => "z";
}

extension on _C2 {
String get _z => "_z";
}

extension type ET1(C1 id) {}
extension type ET2(_C2 id) {}

class MA1 = Object with M1;
class MA2 = Object with _M2;

main() {
Expect.equals("y", C1().y);
Expect.equals("z", C1().z);
Expect.equals("m", MA1().m);
Expect.equals("_y", _C2()._y);
Expect.equals("_z", _C2()._z);
Expect.equals("_m", MA2()._m);
Expect.equals("y", ET1(C1()).id.y);
Expect.equals("_y", ET2(_C2()).id._y);
Expect.equals(E1.e, E1.e.instance);
Expect.equals(_E2.e, _E2.e._instance);
Expect.equals(42, x1);
Expect.equals(42, _x2);
Expect.equals(0, foo1());
Expect.equals(0, _foo2());
Expect.equals("bar", [].bar);
Expect.equals("bar", MyList([]).bar);
Expect.equals("_baz", [].baz);
Expect.equals("_baz", _MyList([]).baz);
Expect.equals(42, MyInt(42));
Expect.equals(42, _MyInt(42));
Expect.isTrue((Foo1 as dynamic) is Type);
Expect.isTrue((_Foo2 as dynamic) is Type);
Expect.isTrue((C1Alias as dynamic) is Type);
Expect.isTrue((_C2Alias as dynamic) is Type);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 Declarations in any library augmentation or the augmented library
/// are visible to all of the others, including private ones.
///
/// @description Checks that declarations in an augmentation are visible in a
/// main library
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

augment library 'defining_augmentation_A01_t01.dart';

class C1 {
String get y => "y";
}

mixin M1 {
String get m => "m";
}

enum E1 {
e;

E1 get instance => e;
}

var x1 = 42;

int foo1() => 0;

extension MyList on List {
String get bar => "bar";
}

extension type MyInt(int id) {}

typedef void Foo1();

typedef C1Alias = C1;

class _C2 {
String get _y => "_y";
}

mixin _M2 {
String get _m => "_m";
}

enum _E2 {
e;

_E2 get _instance => e;
}

var _x2 = 42;

int _foo2() => 0;

extension _MyList on List {
String get baz => "_baz";
}

extension type _MyInt(int id2) {}

typedef void _Foo2();

typedef _C2Alias = _C2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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 Declarations in any library augmentation or the augmented library
/// are visible to all of the others, including private ones.
///
/// @description Checks that declarations in a main library are visible in an
/// augmentation library
/// @author [email protected]
/// @issue 55103
// SharedOptions=--enable-experiment=macros

import augment 'defining_augmentation_A01_t02_lib.dart';

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

class C1 {
String get y => "y";
}

mixin M1 {
String get m => "m";
}

enum E1 {
e;

E1 get instance => e;
}

var x1 = 42;

int foo1() => 0;

extension MyList on List {
String get bar => "bar";
}

extension type MyInt(int id) {}

typedef void Foo1();

typedef C1Alias = C1;

class _C2 {
String get _y => "_y";
}

mixin _M2 {
String get _m => "_m";
}

enum _E2 {
e;

_E2 get _instance => e;
}

var _x2 = 42;

int _foo2() => 0;

extension _MyList on List {
String get baz => "_baz";
}

extension type _MyInt(int id2) {}

typedef void _Foo2();

typedef _C2Alias = _C2;

main() {
test();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 Declarations in any library augmentation or the augmented library
/// are visible to all of the others, including private ones.
///
/// @description Checks that declarations in a main library are visible in an
/// augmentation library
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

augment library 'defining_augmentation_A01_t02.dart';

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

extension on C1 {
String get z => "z";
}

extension on _C2 {
String get _z => "_z";
}

extension type ET1(C1 id) {}
extension type ET2(_C2 id) {}

class MA1 = Object with M1;
class MA2 = Object with _M2;

test() {
Expect.equals("y", C1().y);
Expect.equals("z", C1().z);
Expect.equals("m", MA1().m);
Expect.equals("_y", _C2()._y);
Expect.equals("_z", _C2()._z);
Expect.equals("_m", MA2()._m);
Expect.equals("y", ET1(C1()).id.y);
Expect.equals("_y", ET2(_C2()).id._y);
Expect.equals(E1.e, E1.e.instance);
Expect.equals(_E2.e, _E2.e._instance);
Expect.equals(42, x1);
Expect.equals(42, _x2);
Expect.equals(0, foo1());
Expect.equals(0, _foo2());
Expect.equals("bar", [].bar);
Expect.equals("bar", MyList([]).bar);
Expect.equals("_baz", [].baz);
Expect.equals("_baz", _MyList([]).baz);
Expect.equals(42, MyInt(42));
Expect.equals(42, _MyInt(42));
Expect.isTrue((Foo1 as dynamic) is Type);
Expect.isTrue((_Foo2 as dynamic) is Type);
Expect.isTrue((C1Alias as dynamic) is Type);
Expect.isTrue((_C2Alias as dynamic) is Type);
}
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 Augmentations do not share an import scope with the main library
/// or each other. The libraries one augmentation imports are visible only to
/// that file.
///
/// @description Checks that imports in an augmentation library are not visible
/// in a main library
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import augment 'defining_augmentation_A02_t01_lib.dart';

main() {
print(AL);
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}
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 Augmentations do not share an import scope with the main library
/// or each other. The libraries one augmentation imports are visible only to
/// that file.
///
/// @description Checks that imports in an augmentation library are not visible
/// in a main library
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

augment library 'defining_augmentation_A02_t01.dart';

import 'augmentation_libraries_lib.dart';

class C implements AL {}
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 Augmentations do not share an import scope with the main library
/// or each other. The libraries one augmentation imports are visible only to
/// that file.
///
/// @description Checks that imports in an augmentation library are not visible
/// in a main library even if an augmentation library exports it
/// @author [email protected]
/// @issue 55112
// SharedOptions=--enable-experiment=macros

import augment 'defining_augmentation_A02_t02_lib.dart';

main() {
print(AL);
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 Augmentations do not share an import scope with the main library
/// or each other. The libraries one augmentation imports are visible only to
/// that file.
///
/// @description Checks that imports in an augmentation library are not visible
/// in a main library even if an augmentation library exports it
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

augment library 'defining_augmentation_A02_t02.dart';

import 'augmentation_libraries_lib.dart';
export 'augmentation_libraries_lib.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 Augmentations do not share an import scope with the main library
/// or each other. The libraries one augmentation imports are visible only to
/// that file.
///
/// @description Checks that imports in an augmentation library are not visible
/// in another augmentation library
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import augment 'defining_augmentation_A02_t03_lib1.dart';
import augment 'defining_augmentation_A02_t03_lib2.dart';

main() {
test();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 Augmentations do not share an import scope with the main library
/// or each other. The libraries one augmentation imports are visible only to
/// that file.
///
/// @description Checks that imports in an augmentation library are not visible
/// in another augmentation library
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

augment library 'defining_augmentation_A02_t03.dart';

import 'augmentation_libraries_lib.dart';
Loading

0 comments on commit 425e7ef

Please sign in to comment.