"&&" operator.

This commit is contained in:
Bob Nystrom
2013-11-19 07:35:25 -08:00
parent e614e092ed
commit 6b87a8400f
5 changed files with 90 additions and 12 deletions
+20
View File
@@ -0,0 +1,20 @@
// Note: These tests implicitly depend on ints being truthy.
// Also rely on io.write() returning its argument.
// Return the first non-true argument.
io.write(false && 1) // expect: false
io.write(true && 1) // expect: 1
io.write(1 && 2 && false) // expect: false
// Return the last argument if all are true.
io.write(1 && true) // expect: true
io.write(1 && 2 && 3) // expect: 3
// Short-circuit at the first false argument.
io.write(true) && // expect: true
io.write(false) && // expect: false
io.write(false) // should not print
// Swallow a trailing newline.
io.write(true &&
true) // expect: true