dart-sdk/tests/language_2/unsorted/invocation_mirror_empty_arguments_test.dart
Robert Nystrom fc1b1ecc71 Move files under language_2 into subdirectories.
Change-Id: Idbcc965a27e9ffeedf5e0a1068b019de4193070f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127745
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2019-12-11 19:18:00 +00:00

67 lines
1.8 KiB
Dart

// Copyright (c) 2015, 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";
// Validates that positional arguments are an empty immutable list.
void expectEmptyPositionalArguments(Invocation invocation) {
Expect.isTrue(invocation.positionalArguments.isEmpty);
Expect.throwsUnsupportedError(() => invocation.positionalArguments.clear());
}
// Validates that positional arguments are an empty immutable map.
void expectEmptyNamedArguments(Invocation invocation) {
Expect.isTrue(invocation.namedArguments.isEmpty);
Expect.throwsUnsupportedError(() => invocation.namedArguments.clear());
}
class Getter {
get getterThatDoesNotExist;
noSuchMethod(invocation) {
Expect.isTrue(invocation.isGetter);
expectEmptyPositionalArguments(invocation);
expectEmptyNamedArguments(invocation);
}
}
class Setter {
set setterThatDoesNotExist(value);
noSuchMethod(invocation) {
Expect.isTrue(invocation.isSetter);
expectEmptyNamedArguments(invocation);
}
}
class Method {
methodThatDoesNotExist();
noSuchMethod(invocation) {
Expect.isTrue(invocation.isMethod);
expectEmptyPositionalArguments(invocation);
expectEmptyNamedArguments(invocation);
}
}
class Operator {
operator +(other);
noSuchMethod(invocation) {
Expect.isTrue(invocation.isMethod);
expectEmptyNamedArguments(invocation);
}
}
main() {
var g = new Getter();
print(g.getterThatDoesNotExist);
var s = new Setter();
print(s.setterThatDoesNotExist = 42);
var m = new Method();
print(m.methodThatDoesNotExist());
var o = new Operator();
print(o + 42); // Operator that does not exist.
}