Update the VM interpreter to treat null as falsey alongside false in if, while, for, and logical AND/OR operations. Remove the TODO comment and adjust short-circuit logic in OP_JUMP_IF and OP_JUMP_IF_NOT branches. Refactor existing test files into subdirectories (if/, logical_operator/, while/) and add dedicated truthiness tests for each construct. Remove old test/if.wren and update and/or tests to exclude null/0/"" truthiness checks now that null is falsey.
21 lines
625 B
Plaintext
21 lines
625 B
Plaintext
// Note: These tests implicitly depend on ints being truthy.
|
|
// Also rely on IO.print() returning its argument.
|
|
|
|
// Return the first non-true argument.
|
|
IO.print(false && 1) // expect: false
|
|
IO.print(true && 1) // expect: 1
|
|
IO.print(1 && 2 && false) // expect: false
|
|
|
|
// Return the last argument if all are true.
|
|
IO.print(1 && true) // expect: true
|
|
IO.print(1 && 2 && 3) // expect: 3
|
|
|
|
// Short-circuit at the first false argument.
|
|
IO.print(true) && // expect: true
|
|
IO.print(false) && // expect: false
|
|
IO.print(false) // should not print
|
|
|
|
// Swallow a trailing newline.
|
|
IO.print(true &&
|
|
true) // expect: true
|