Skip to content

Commit b60fa14

Browse files
committed
Add tests for operators with symbol operand
1 parent 25fcbe2 commit b60fa14

32 files changed

+536
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/conformance/es6/Symbols/symbolType1.ts(1,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
2+
tests/cases/conformance/es6/Symbols/symbolType1.ts(2,19): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
3+
4+
5+
==== tests/cases/conformance/es6/Symbols/symbolType1.ts (2 errors) ====
6+
Symbol() instanceof Symbol;
7+
~~~~~~~~
8+
!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
9+
Symbol instanceof Symbol();
10+
~~~~~~~~
11+
!!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [symbolType1.ts]
2+
Symbol() instanceof Symbol;
3+
Symbol instanceof Symbol();
4+
5+
//// [symbolType1.js]
6+
Symbol() instanceof Symbol;
7+
Symbol instanceof Symbol();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
tests/cases/conformance/es6/Symbols/symbolType10.ts(2,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
2+
tests/cases/conformance/es6/Symbols/symbolType10.ts(2,5): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
3+
tests/cases/conformance/es6/Symbols/symbolType10.ts(3,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
4+
tests/cases/conformance/es6/Symbols/symbolType10.ts(3,5): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
5+
tests/cases/conformance/es6/Symbols/symbolType10.ts(4,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
6+
tests/cases/conformance/es6/Symbols/symbolType10.ts(4,5): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
7+
tests/cases/conformance/es6/Symbols/symbolType10.ts(6,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
8+
tests/cases/conformance/es6/Symbols/symbolType10.ts(7,5): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
9+
10+
11+
==== tests/cases/conformance/es6/Symbols/symbolType10.ts (8 errors) ====
12+
var s = Symbol.for("bitwise");
13+
s & s;
14+
~
15+
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
16+
~
17+
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
18+
s | s;
19+
~
20+
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
21+
~
22+
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
23+
s ^ s;
24+
~
25+
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
26+
~
27+
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
28+
29+
s & 0;
30+
~
31+
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
32+
0 | s;
33+
~
34+
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [symbolType10.ts]
2+
var s = Symbol.for("bitwise");
3+
s & s;
4+
s | s;
5+
s ^ s;
6+
7+
s & 0;
8+
0 | s;
9+
10+
//// [symbolType10.js]
11+
var s = Symbol.for("bitwise");
12+
s & s;
13+
s | s;
14+
s ^ s;
15+
s & 0;
16+
0 | s;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [symbolType11.ts]
2+
var s = Symbol.for("logical");
3+
s && s;
4+
s && [];
5+
0 && s;
6+
s || s;
7+
s || 1;
8+
({}) || s;
9+
10+
//// [symbolType11.js]
11+
var s = Symbol.for("logical");
12+
s && s;
13+
s && [];
14+
0 && s;
15+
s || s;
16+
s || 1;
17+
({}) || s;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// [symbolType12.ts]
2+
var s = Symbol.for("assign");
3+
var str = "";
4+
s *= s;
5+
s *= 0;
6+
s /= s;
7+
s /= 0;
8+
s %= s;
9+
s %= 0;
10+
s += s;
11+
s += 0;
12+
s += "";
13+
str += s;
14+
s -= s;
15+
s -= 0;
16+
s <<= s;
17+
s <<= 0;
18+
s >>= s;
19+
s >>= 0;
20+
s >>>= s;
21+
s >>>= 0;
22+
s &= s;
23+
s &= 0;
24+
s ^= s;
25+
s ^= 0;
26+
s |= s;
27+
s |= 0;
28+
29+
//// [symbolType12.js]
30+
var s = Symbol.for("assign");
31+
var str = "";
32+
s *= s;
33+
s *= 0;
34+
s /= s;
35+
s /= 0;
36+
s %= s;
37+
s %= 0;
38+
s += s;
39+
s += 0;
40+
s += "";
41+
str += s;
42+
s -= s;
43+
s -= 0;
44+
s <<= s;
45+
s <<= 0;
46+
s >>= s;
47+
s >>= 0;
48+
s >>>= s;
49+
s >>>= 0;
50+
s &= s;
51+
s &= 0;
52+
s ^= s;
53+
s ^= 0;
54+
s |= s;
55+
s |= 0;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [symbolType13.ts]
2+
var s = Symbol();
3+
var x: any;
4+
5+
for (s in {}) { }
6+
for (x in s) { }
7+
for (var y in s) { }
8+
9+
//// [symbolType13.js]
10+
var s = Symbol();
11+
var x;
12+
for (s in {}) {
13+
}
14+
for (x in s) {
15+
}
16+
for (var y in s) {
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [symbolType2.ts]
2+
Symbol.isConcatSpreadable in {};
3+
"" in Symbol.toPrimitive;
4+
5+
//// [symbolType2.js]
6+
Symbol.isConcatSpreadable in {};
7+
"" in Symbol.toPrimitive;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [symbolType3.ts]
2+
var s = Symbol();
3+
delete Symbol.iterator;
4+
void Symbol.toPrimitive;
5+
typeof Symbol.toStringTag;
6+
++s;
7+
--s;
8+
+ Symbol();
9+
- Symbol();
10+
~ Symbol();
11+
! Symbol();
12+
13+
//// [symbolType3.js]
14+
var s = Symbol();
15+
delete Symbol.iterator;
16+
void Symbol.toPrimitive;
17+
typeof Symbol.toStringTag;
18+
++s;
19+
--s;
20+
+Symbol();
21+
-Symbol();
22+
~Symbol();
23+
!Symbol();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests/cases/conformance/es6/Symbols/symbolType4.ts(2,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
2+
tests/cases/conformance/es6/Symbols/symbolType4.ts(3,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
3+
4+
5+
==== tests/cases/conformance/es6/Symbols/symbolType4.ts (2 errors) ====
6+
var s = Symbol.for("postfix");
7+
s++;
8+
~
9+
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
10+
s--;
11+
~
12+
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.

0 commit comments

Comments
 (0)