Cannot capture UpdateExpression like ++foo
falsandtru opened this issue · 2 comments
falsandtru commented
class C {
count_ = {};
count() {
return this.count_;
}
}
var counter = new C();
assert(++counter.count_ === counter.count());
expected:
assert(++counter.count_ === counter.count())
| | | | | |
| | | | | Object{}
| | | | C{count_:#Object#}
| | | false
| | Object{}
| C{count_:#Object#}
NaN
actual:
assert(++counter.count_ === counter.count())
| | | |
| | | NaN
| | C{count_:NaN}
NaN false
other:
assert(+counter.count_ === counter.count())
|| | | | |
|| | | | Object{}
|| | | C{count_:#Object#}
|| | false
|| Object{}
|C{count_:#Object#}
NaN
twada commented
Hi, thank you for reporting.
Unfortunately, it's a limitation of power-assert. I cannot support UpdateExpression
since it causes ReferenceError
.
Let me explain. Given example.js
,
'use strict';
function capt (val) {
return val;
}
var counter = {
count: 0
};
console.log(++counter.count); // => 1
console.log(capt(++capt(capt(counter).count))); // => ReferenceError
results in ReferenceError
when executed.
$ node example.js
1
~/src/github.com/power-assert-js/power-assert/example.js:12
console.log(capt(++capt(capt(counter).count)));
^
ReferenceError: Invalid left-hand side expression in prefix operation
at Object.<anonymous> (~/src/github.com/power-assert-js/power-assert/example.js:12:20)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
$
capt
function is what power-assert is doing internally, so when I tried to capture UpdateExpression
like ++foo
, it always result in ReferenceError
.
Since test tool should not change behavior of SUT (System Under Test), I gave up supporting UpdateExpression
.
Sorry for inconvenience. I'll write about this limitation to FAQ section in REAME. Thanks!
falsandtru commented
I understand, thanks!