xgo/runtime/vm_logic_test.go
Daniel 61890b15cb
module refactor (#148)
* wip

* move print and JSON functions to modules

* builtin functions are not replacable now

* builtin functions are added for default nil symbol table

* importables: builtin modules and source modules

* refactoring runtime tests

* fix tests

* update documentation

* cleanup

* clean up cli

* fix REPL prints
2019-03-18 08:15:26 -07:00

41 lines
1.9 KiB
Go

package runtime_test
import "testing"
func TestLogical(t *testing.T) {
expect(t, `out = true && true`, nil, true)
expect(t, `out = true && false`, nil, false)
expect(t, `out = false && true`, nil, false)
expect(t, `out = false && false`, nil, false)
expect(t, `out = !true && true`, nil, false)
expect(t, `out = !true && false`, nil, false)
expect(t, `out = !false && true`, nil, true)
expect(t, `out = !false && false`, nil, false)
expect(t, `out = true || true`, nil, true)
expect(t, `out = true || false`, nil, true)
expect(t, `out = false || true`, nil, true)
expect(t, `out = false || false`, nil, false)
expect(t, `out = !true || true`, nil, true)
expect(t, `out = !true || false`, nil, false)
expect(t, `out = !false || true`, nil, true)
expect(t, `out = !false || false`, nil, true)
expect(t, `out = 1 && 2`, nil, 2)
expect(t, `out = 1 || 2`, nil, 1)
expect(t, `out = 1 && 0`, nil, 0)
expect(t, `out = 1 || 0`, nil, 1)
expect(t, `out = 1 && (0 || 2)`, nil, 2)
expect(t, `out = 0 || (0 || 2)`, nil, 2)
expect(t, `out = 0 || (0 && 2)`, nil, 0)
expect(t, `out = 0 || (2 && 0)`, nil, 0)
expect(t, `t:=func() {out = 3; return true}; f:=func() {out = 7; return false}; t() && f()`, nil, 7)
expect(t, `t:=func() {out = 3; return true}; f:=func() {out = 7; return false}; f() && t()`, nil, 7)
expect(t, `t:=func() {out = 3; return true}; f:=func() {out = 7; return false}; f() || t()`, nil, 3)
expect(t, `t:=func() {out = 3; return true}; f:=func() {out = 7; return false}; t() || f()`, nil, 3)
expect(t, `t:=func() {out = 3; return true}; f:=func() {out = 7; return false}; !t() && f()`, nil, 3)
expect(t, `t:=func() {out = 3; return true}; f:=func() {out = 7; return false}; !f() && t()`, nil, 3)
expect(t, `t:=func() {out = 3; return true}; f:=func() {out = 7; return false}; !f() || t()`, nil, 7)
expect(t, `t:=func() {out = 3; return true}; f:=func() {out = 7; return false}; !t() || f()`, nil, 7)
}