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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
The "in" operator allows testing whether a given value is an item of
a specified array or whether a given key is present in a specified
dictionary.
1. The `in` operator returns true if the given element is an item of
the specified array. Strict equality tests are performed.
-- Expect stdout --
[
true,
false,
true,
false,
true,
false,
true,
false
]
-- End --
-- Testcase --
{%
let o = {};
let a = [ o, {}, "", null, false ];
printf("%.J\n", [
o in a,
{} in a,
"" in a,
"test" in a,
null in a,
[] in a,
false in a,
true in a
]);
%}
-- End --
2. Strict equality when testing array membership should rule out implict
type coercion.
-- Expect stdout --
[
true,
false,
false,
false,
true,
false,
false
]
-- End --
-- Testcase --
{%
let a = [ "", true ];
printf("%.J\n", [
"" in a,
0 in a,
false in a,
null in a,
true in a,
1 in a,
1.0 in a
]);
%}
-- End --
3. While there is the rule that `(NaN === NaN) == false`, testing for NaN
in a given array containing NaN should yield `true`.
-- Expect stdout --
[
true
]
-- End --
-- Testcase --
{%
let a = [ NaN ];
printf("%.J\n", [
NaN in a
]);
%}
-- End --
4. When the `in` operator is applied to an object, it tests whether the given
string value is a key of the specified object.
-- Expect stdout --
[
true,
true,
true,
false,
false,
false,
false,
false
]
-- End --
-- Testcase --
{%
let o = {
"1": true,
"test": false,
"empty": null,
"false": 0,
"true": 1,
"[ ]": "array",
"{ }": "object"
};
printf("%.J\n", [
"1" in o,
"test" in o,
"empty" in o,
1 in o, // not implicitly converted to "1"
false in o, // not implicitly converted to "false"
true in o, // not implicitly converted to "true"
[] in o, // not implicitly converted to "[ ]"
{} in o // not implicitly converted to "{ }"
]);
%}
-- End --
|