mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:01:42 +00:00
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>
This commit is contained in:
parent
7a2c8b3f90
commit
7afb23a7d9
20
tests/corelib/from_environment_default_value_test.dart
Normal file
20
tests/corelib/from_environment_default_value_test.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.
|
||||
|
||||
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'));
|
||||
}
|
20
tests/corelib_2/from_environment_default_value_test.dart
Normal file
20
tests/corelib_2/from_environment_default_value_test.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.
|
||||
|
||||
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'));
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
// 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";
|
||||
|
||||
// Test that it is possible to invoke an object whose type is a proper subtype
|
||||
// of a function type (that is, its type is 'function-type bounded', and we
|
||||
// get to call it as if its type had been that bound).
|
||||
|
||||
class A<X, Y extends X Function(X)> {
|
||||
final Y f;
|
||||
A(this.f);
|
||||
X m(X value) => f(value);
|
||||
}
|
||||
|
||||
class B extends A<String, String Function(String, {int i})> {
|
||||
B(String Function(String, {int i}) f) : super(f);
|
||||
String m(String value) => f(value, i: 42);
|
||||
}
|
||||
|
||||
void main() {
|
||||
B b = B((String s, {int i}) => "$s and $i");
|
||||
Expect.equals('24 and 42', b.m('24'));
|
||||
}
|
Loading…
Reference in a new issue