-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathsymbol_operator_test.dart
73 lines (66 loc) · 2.35 KB
/
symbol_operator_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2013, 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.
// Test of Symbol class for operators..
dynamic $ = new Symbolize();
main() {
testSymbol(#+, $ + $, "+");
testSymbol(#-, $ - $, "-");
testSymbol(#*, $ * $, "*");
testSymbol(#/, $ / $, "/");
testSymbol(#~/, $ ~/ $, "~/");
testSymbol(#%, $ % $, "%");
testSymbol(#<<, $ << $, "<<");
testSymbol(#>>, $ >> $, ">>");
testSymbol(#~, ~$, "~");
testSymbol(#|, $ | $, "|");
testSymbol(#&, $ & $, "&");
testSymbol(#^, $ ^ $, "^");
testSymbol(#<, $ < $, "<");
testSymbol(#<=, $ <= $, "<=");
testSymbol(#>, $ > $, ">");
testSymbol(#>=, $ >= $, ">=");
testSymbol(#==, new Symbol("=="), "=="); // Can't hit noSuchMethod.
testSymbol(#[], $[$], "[]");
testSymbol(#[]=, ($[$] = $).lastMember, "[]=");
testSymbol(Symbol.unaryMinus, -$, "unary-");
testSymbolNotInstanceOperator(">>>");
testSymbolNotInstanceOperator("!");
testSymbolNotInstanceOperator("&&");
testSymbolNotInstanceOperator("||");
testSymbolNotInstanceOperator("?");
testSymbolNotInstanceOperator("?:");
testSymbolNotInstanceOperator("#");
testSymbolNotInstanceOperator("//");
}
void testSymbol(Symbol constSymbol, var mirrorSymbol, String name) {
Symbol dynamicSymbol = new Symbol(name);
if (constSymbol != mirrorSymbol) {
throw "Not equal #$name, \$$name: $constSymbol, $mirrorSymbol";
}
if (constSymbol != dynamicSymbol) {
throw "Not equal #$name, new Symbol('$name'): $constSymbol, $dynamicSymbol";
}
if (mirrorSymbol != dynamicSymbol) {
throw "Not equal \$$name, new Symbol('$name'): "
"$mirrorSymbol, $dynamicSymbol";
}
if (constSymbol.hashCode != mirrorSymbol.hashCode) {
throw "HashCode not equal #$name, \$$name: $constSymbol, $mirrorSymbol";
}
if (constSymbol.hashCode != dynamicSymbol.hashCode) {
throw "HashCode not equal #$name, new Symbol('$name'): "
"$constSymbol, $dynamicSymbol";
}
if (mirrorSymbol.hashCode != dynamicSymbol.hashCode) {
throw "HashCode not equal \$$name, new Symbol('$name'): "
"$mirrorSymbol, $dynamicSymbol";
}
}
void testSymbolNotInstanceOperator(name) {
new Symbol(name);
}
class Symbolize {
Symbol? lastMember;
noSuchMethod(m) => lastMember = m.memberName;
}