dart-sdk/tests/corelib/from_environment_default_value_test.dart
Erik Ernst 7afb23a7d9 Added new tests.
One test verifies that the default values of fromEnvironment
constructors are the values false/0/''.

The other new test verifies that it is allowed to invoke an expression
whose static type is a proper subtype of a function type (X extends F,
where F is a function type), cf.
https://github.com/dart-lang/language/issues/896.

Change-Id: I4ee32df7c5950be07b800027f000a486bf3af61c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141249
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
2020-03-27 19:02:52 +00:00

21 lines
883 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() {
// Verify that the default value is as expected.
Expect.equals(false, const bool.fromEnvironment('UNDEFINED_NAME'));
Expect.equals(0, const int.fromEnvironment('UNDEFINED_NAME'));
Expect.equals('', const String.fromEnvironment('UNDEFINED_NAME'));
// Verify that `defaultValue` is used when passed, not the default values.
Expect.equals(
true, const bool.fromEnvironment('UNDEFINED_NAME', defaultValue: true));
Expect.equals(
1, const int.fromEnvironment('UNDEFINED_NAME', defaultValue: 1));
Expect.equals('qux',
const String.fromEnvironment('UNDEFINED_NAME', defaultValue: 'qux'));
}