$print {++/-- operator tests...}
scope {
/* PREFIX ++/-- on identifiers... */
var i = 0
assert 1 === ++i
assert 2 === ++i
assert 1 === --i
const x = 0
assert [catch{++x}.codeString] === {CWAL_RC_ACCESS}
}
scope {
/* PREFIX ++/-- on object.property... */
var o = object{ a: 3, b: null }
assert 1 === ++o.b /* converts existing values to int if needed */
assert {CWAL_RC_NOT_FOUND} === [catch{++o.c}.codeString] /*
but it won't create new properties */
assert 0 === --o.b
assert 2 === --o.a
assert 3 === ++o.a
}
scope {
/* POSTFIX ++/-- on identifiers */
var i = 5
assert 5 === i--
assert 4 === i
assert 4 === i++
assert 5 === i
assert catch{++i--;}.codeString() === {CWAL_SCR_CANNOT_CONSUME} /*bug: non-EOF-like end of expr currently needed to trigger that */
const x = 0
assert [catch{x++}.codeString] === {CWAL_RC_ACCESS}
}
scope {
/* POSTFIX ++/-- on object.property */
var o = object{a:5}
assert 5 === o.a--
assert 4 === o.a
assert 4 === o.a++
assert 5 === o.a
assert {CWAL_RC_NOT_FOUND} === [catch{o.b++}.codeString]
assert ![o.hasOwnProperty 'b']
assert {CWAL_SCR_CANNOT_CONSUME} [catch{++o.a--;}.codeString] /*bug: non-EOF-like end of expr currently needed to trigger that */
}
scope {
/* Make sure 'this' resolution is working in eval blocks... */
var o = object{a:object{b:1}}
assert 1 === eval{o.a.b++}
assert 2 === eval{o.a.b}
assert 3 === eval{++o.a.b}
var x = 1
assert 1 === eval {x++}
assert 3 === eval {x++; x}
}