dart-sdk/tests/lib/mirrors/new_instance_optional_arguments_test.dart
Ryan Macnak 00b2e580a3 [test] Fork mirrors tests.
Bug: https://github.com/dart-lang/sdk/issues/40045
Change-Id: I597259b38684de87016f1e136723d24f4ac05420
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132440
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2020-01-22 18:46:23 +00:00

127 lines
3.6 KiB
Dart

// Copyright (c) 2014, 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.
library mirror_test;
import 'dart:mirrors';
import 'package:expect/expect.dart';
class A {
var req1, opt1, opt2;
A.a0([opt1]) : this.opt1 = opt1;
A.b0([opt1, opt2])
: this.opt1 = opt1,
this.opt2 = opt2;
A.c0([opt1 = 499]) : this.opt1 = opt1;
A.d0([opt1 = 499, opt2 = 42])
: this.opt1 = opt1,
this.opt2 = opt2;
A.a1(req1, [opt1])
: this.req1 = req1,
this.opt1 = opt1;
A.b1(req1, [opt1, opt2])
: this.req1 = req1,
this.opt1 = opt1,
this.opt2 = opt2;
A.c1(req1, [opt1 = 499])
: this.req1 = req1,
this.opt1 = opt1;
A.d1(req1, [opt1 = 499, opt2 = 42])
: this.req1 = req1,
this.opt1 = opt1,
this.opt2 = opt2;
}
main() {
ClassMirror cm = reflectClass(A);
var o;
o = cm.newInstance(#a0, []).reflectee;
Expect.equals(null, o.req1);
Expect.equals(null, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#b0, []).reflectee;
Expect.equals(null, o.req1);
Expect.equals(null, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#c0, []).reflectee;
Expect.equals(null, o.req1);
Expect.equals(499, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#d0, []).reflectee;
Expect.equals(null, o.req1);
Expect.equals(499, o.opt1);
Expect.equals(42, o.opt2);
o = cm.newInstance(#a0, [77]).reflectee;
Expect.equals(null, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#b0, [77]).reflectee;
Expect.equals(null, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#c0, [77]).reflectee;
Expect.equals(null, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#d0, [77]).reflectee;
Expect.equals(null, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(42, o.opt2);
o = cm.newInstance(#b0, [77, 11]).reflectee;
Expect.equals(null, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(11, o.opt2);
o = cm.newInstance(#d0, [77, 11]).reflectee;
Expect.equals(null, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(11, o.opt2);
o = cm.newInstance(#a1, [123]).reflectee;
Expect.equals(123, o.req1);
Expect.equals(null, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#b1, [123]).reflectee;
Expect.equals(123, o.req1);
Expect.equals(null, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#c1, [123]).reflectee;
Expect.equals(123, o.req1);
Expect.equals(499, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#d1, [123]).reflectee;
Expect.equals(123, o.req1);
Expect.equals(499, o.opt1);
Expect.equals(42, o.opt2);
o = cm.newInstance(#a1, [123, 77]).reflectee;
Expect.equals(123, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#b1, [123, 77]).reflectee;
Expect.equals(123, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#c1, [123, 77]).reflectee;
Expect.equals(123, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(null, o.opt2);
o = cm.newInstance(#d1, [123, 77]).reflectee;
Expect.equals(123, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(42, o.opt2);
o = cm.newInstance(#b1, [123, 77, 11]).reflectee;
Expect.equals(123, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(11, o.opt2);
o = cm.newInstance(#d1, [123, 77, 11]).reflectee;
Expect.equals(123, o.req1);
Expect.equals(77, o.opt1);
Expect.equals(11, o.opt2);
}