dart-sdk/tests/language/nnbd/constant_null_safety_mode_test.dart
Erik Ernst 3a7eeb6315 Rename is{Strong,Weak}Mode to has{Sound,Unsound}NullSafety
Change-Id: If3912d75c5f89a741299b2fae4299d01ac928eec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170424
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
2020-11-05 14:26:53 +00:00

25 lines
862 B
Dart

// 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';
main() {
const trueInNoSoundMode = <Null>[] is List<int>;
Expect.equals(hasUnsoundNullSafety, trueInNoSoundMode);
// The following tests use the Uri.pathSegments() to access a constant list
// that is defined in the SDK and verify the type associated with it does not
// allow null when running with sound null safety.
var emptyUri = Uri(pathSegments: []);
dynamic stringList = emptyUri.pathSegments.toList();
if (hasSoundNullSafety) {
Expect.throwsTypeError(() {
stringList.add(null);
});
} else {
stringList.add(null);
Expect.listEquals([null], stringList);
}
}