dart-sdk/tests/language/parameter/named_runtime_test.dart
Robert Nystrom 5c1376615e Migrate language_2/parameter to NNBD.
Change-Id: I369916a9edd3a9b38ab2c9ee1e11c4735331142b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150284
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
2020-06-09 10:52:04 +00:00

118 lines
2.6 KiB
Dart

// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// Copyright (c) 2012, 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.
// Dart test program for testing named parameters.
import "package:expect/expect.dart";
class NamedParametersTest {
static int F00() {
return 0;
}
int f11() {
return 0;
}
static int F11(int a) {
return a;
}
int f22(int a) {
return a;
}
static int F10([int b = 20]) {
return b;
}
int f21([int b = 20]) {
return b;
}
static int F21(int a, [int b = 20]) {
return 100 * a + b;
}
int f32(int a, [int b = 20]) {
return 100 * a + b;
}
static int F31(int a, [int b = 20, int c = 30]) {
return 100 * (100 * a + b) + c;
}
int f42(int a, [int b = 20, int c = 30]) {
return 100 * (100 * a + b) + c;
}
static int F41(int a, [int b = 20, int? c, int d = 40]) {
return 100 * (100 * (100 * a + b) + (c == null ? 0 : c)) + d;
}
int f52(int a, [int b = 20, int? c, int d = 40]) {
return 100 * (100 * (100 * a + b) + (c == null ? 0 : c)) + d;
}
static testMain() {
NamedParametersTest np = new NamedParametersTest();
Expect.equals(0, F00());
Expect.equals(0, np.f11());
Expect.equals(10, F11(10));
Expect.equals(10, np.f22(10));
Expect.equals(20, F10());
Expect.equals(20, np.f21());
Expect.equals(20, F10(20));
Expect.equals(20, np.f21(20));
Expect.equals(1020, F21(10));
Expect.equals(1020, np.f32(10));
Expect.equals(1025, F21(10, 25));
Expect.equals(1025, np.f32(10, 25));
Expect.equals(102030, F31(10));
Expect.equals(102030, np.f42(10));
Expect.equals(102530, F31(10, 25));
Expect.equals(102530, np.f42(10, 25));
Expect.equals(102535, F31(10, 25, 35));
Expect.equals(102535, np.f42(10, 25, 35));
Expect.equals(10200040, F41(10));
Expect.equals(10200040, np.f52(10));
}
}
abstract class I {
factory I() = C;
int mul(int a, [int factor]);
}
class C implements I {
int mul(int a, [int factor = 10]) {
return a * factor;
}
}
hello(msg, to, {from}) => '${from} sent ${msg} to ${to}';
message() => hello("gladiolas", "possums", from: "Edna");
main() {
NamedParametersTest.testMain();
var i = new I();
Expect.equals(100, i.mul(10));
Expect.equals(1000, i.mul(10, 100));
var c = new C();
Expect.equals(100, c.mul(10));
Expect.equals(1000, c.mul(10, 100));
Expect.equals("Edna sent gladiolas to possums", message());
}