2013-12-17 12:38:53 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-04-26 17:58:57 +00:00
|
|
|
// @dart = 2.9
|
|
|
|
|
2013-12-17 12:38:53 +00:00
|
|
|
// Test of Symbol class for operators..
|
|
|
|
|
2017-07-23 03:16:40 +00:00
|
|
|
dynamic $ = new Symbolize();
|
2013-12-17 12:38:53 +00:00
|
|
|
|
|
|
|
main() {
|
2017-03-23 19:40:21 +00:00
|
|
|
testSymbol(#+, $ + $, "+");
|
|
|
|
testSymbol(#-, $ - $, "-");
|
|
|
|
testSymbol(#*, $ * $, "*");
|
|
|
|
testSymbol(#/, $ / $, "/");
|
|
|
|
testSymbol(#~/, $ ~/ $, "~/");
|
|
|
|
testSymbol(#%, $ % $, "%");
|
|
|
|
testSymbol(#<<, $ << $, "<<");
|
|
|
|
testSymbol(#>>, $ >> $, ">>");
|
2013-12-17 12:38:53 +00:00
|
|
|
testSymbol(#~, ~$, "~");
|
2017-03-23 19:40:21 +00:00
|
|
|
testSymbol(#|, $ | $, "|");
|
|
|
|
testSymbol(#&, $ & $, "&");
|
|
|
|
testSymbol(#^, $ ^ $, "^");
|
|
|
|
testSymbol(#<, $ < $, "<");
|
|
|
|
testSymbol(#<=, $ <= $, "<=");
|
|
|
|
testSymbol(#>, $ > $, ">");
|
|
|
|
testSymbol(#>=, $ >= $, ">=");
|
|
|
|
testSymbol(#==, new Symbol("=="), "=="); // Can't hit noSuchMethod.
|
2014-06-19 09:29:17 +00:00
|
|
|
testSymbol(#[], $[$], "[]");
|
2017-03-23 19:40:21 +00:00
|
|
|
testSymbol(#[]=, ($[$] = $).lastMember, "[]=");
|
2018-03-08 16:36:07 +00:00
|
|
|
testSymbol(Symbol.unaryMinus, -$, "unary-");
|
2013-12-17 12:38:53 +00:00
|
|
|
|
2017-03-22 00:29:56 +00:00
|
|
|
testSymbolThrows(">>>"); // //# 03: ok
|
|
|
|
testSymbolThrows("!"); // //# 03: continued
|
|
|
|
testSymbolThrows("&&"); // //# 03: continued
|
|
|
|
testSymbolThrows("||"); // //# 03: continued
|
|
|
|
testSymbolThrows("?"); // //# 03: continued
|
|
|
|
testSymbolThrows("?:"); // //# 03: continued
|
|
|
|
testSymbolThrows("#"); // //# 03: continued
|
|
|
|
testSymbolThrows("//"); // //# 03: continued
|
2013-12-17 12:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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'): "
|
2017-03-23 19:40:21 +00:00
|
|
|
"$mirrorSymbol, $dynamicSymbol";
|
2013-12-17 12:38:53 +00:00
|
|
|
}
|
|
|
|
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'): "
|
2017-03-23 19:40:21 +00:00
|
|
|
"$constSymbol, $dynamicSymbol";
|
2013-12-17 12:38:53 +00:00
|
|
|
}
|
|
|
|
if (mirrorSymbol.hashCode != dynamicSymbol.hashCode) {
|
|
|
|
throw "HashCode not equal \$$name, new Symbol('$name'): "
|
2017-03-23 19:40:21 +00:00
|
|
|
"$mirrorSymbol, $dynamicSymbol";
|
2013-12-17 12:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void testSymbolThrows(name) {
|
|
|
|
bool fails = false;
|
|
|
|
try {
|
|
|
|
new Symbol(name);
|
|
|
|
} catch (e) {
|
|
|
|
fails = true;
|
|
|
|
}
|
|
|
|
if (!fails) {
|
|
|
|
throw "Didn't throw: $name";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Symbolize {
|
|
|
|
Symbol lastMember;
|
|
|
|
noSuchMethod(m) => lastMember = m.memberName;
|
|
|
|
}
|