mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:29:48 +00:00
[tests] Create null is T
tests in legacy and null safe libraries
Change-Id: I2054b6da8b66e7c6de81d9fb18fdc1c264db376c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132420 Commit-Queue: Nicholas Shahan <nshahan@google.com> Reviewed-by: Leaf Petersen <leafp@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
This commit is contained in:
parent
b01eb17669
commit
703bc0086d
20
tests/language/nnbd/is_type_test/legacy_library.dart
Normal file
20
tests/language/nnbd/is_type_test/legacy_library.dart
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
// Opt out of Null Safety:
|
||||
// @dart = 2.6
|
||||
|
||||
import 'null_safe_library.dart';
|
||||
|
||||
/// Performs the type test [value] is [T] in a legacy library.
|
||||
///
|
||||
/// NOTE: The [T] here is in a legacy library and will become `T*` which might
|
||||
/// be normalized away depending on the value of `T`.
|
||||
bool legacyIs<T>(Object value) => value is T;
|
||||
|
||||
/// Performs the type test [value] is [T] in a null safe library.
|
||||
///
|
||||
/// NOTE: The [T] here is in a legacy library and will become `T*` which might
|
||||
/// be normalized away depending on the value of `T`.
|
||||
bool nullSafeIsLegacy<T>(Object value) => nullSafeIs<T>(value);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
// Opt out of Null Safety:
|
||||
// @dart = 2.6
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'null_safe_library.dart';
|
||||
|
||||
// Type tests (is checks) located in a legacy library.
|
||||
main() {
|
||||
// `null is Never*`
|
||||
Expect.isTrue(null is Never);
|
||||
// `null is Never?`
|
||||
Expect.isTrue(legacyIsNullable<Never>(null));
|
||||
Expect.isTrue(null is Null);
|
||||
// `null is int*`
|
||||
Expect.isFalse(null is int);
|
||||
// `null is int?`
|
||||
Expect.isTrue(legacyIsNullable<int>(null));
|
||||
// `null is Object*`
|
||||
Expect.isTrue(null is Object);
|
||||
// `null is Object?`
|
||||
Expect.isTrue(legacyIsNullable<Object>(null));
|
||||
Expect.isTrue(null is dynamic);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'legacy_library.dart';
|
||||
|
||||
// Type tests (is checks) located in a null safe library.
|
||||
main() {
|
||||
Expect.isFalse(null is Never);
|
||||
// `null is Never*`
|
||||
Expect.isTrue(nullSafeIsLegacy<Never>(null));
|
||||
Expect.isTrue(null is Never?);
|
||||
Expect.isTrue(null is Null);
|
||||
Expect.isFalse(null is int);
|
||||
// `null is int*`
|
||||
Expect.isFalse(nullSafeIsLegacy<int>(null));
|
||||
Expect.isTrue(null is int?);
|
||||
Expect.isFalse(null is Object);
|
||||
// `null is Object*`
|
||||
Expect.isTrue(nullSafeIsLegacy<Object>(null));
|
||||
Expect.isTrue(null is Object?);
|
||||
Expect.isTrue(null is dynamic);
|
||||
}
|
11
tests/language/nnbd/is_type_test/null_safe_library.dart
Normal file
11
tests/language/nnbd/is_type_test/null_safe_library.dart
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
import 'legacy_library.dart';
|
||||
|
||||
/// Performs the type test [value] is [T] in a null safe library.
|
||||
bool nullSafeIs<T>(Object? value) => value is T;
|
||||
|
||||
/// Performs the type test [value] is `T?` in a legacy library.
|
||||
bool legacyIsNullable<T>(Object? value) => legacyIs<T?>(value);
|
Loading…
Reference in a new issue