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
|
The logical AND and logical OR assignment operators set the left hand side
variable or value to the right hand side expression result depending on
whether the lhs value is truish.
1. The `&&=` operator overwrites the lhs variable or field with the rhs
expression result if the lhs is truish.
-- Expect stdout --
[
null,
false,
"is truish"
]
-- End --
-- Testcase --
{%
x = null;
y = false;
z = true;
x &&= "is truish";
y &&= "is truish";
z &&= "is truish";
printf("%.J\n", [ x, y, z ]);
%}
-- End --
2. The `||=` operator overwrites the lhs variable or field with the rhs
expression result if the lhs is falsy.
-- Expect stdout --
[
"is falsy",
"is falsy",
true
]
-- End --
-- Testcase --
{%
x = null;
y = false;
z = true;
x ||= "is falsy";
y ||= "is falsy";
z ||= "is falsy";
printf("%.J\n", [ x, y, z ]);
%}
-- End --
3. Ensure that the assignment value expression is not evaluated if the
assignment condition is false.
-- Expect stdout --
[
0,
0,
0
]
-- End --
-- Testcase --
{%
a = 0;
b = 0;
c = 0;
x = false;
y = false;
z = true;
x ??= a++;
y &&= b++;
z ||= c++;
printf("%.J\n", [ a, b, c ]);
%}
-- End --
|