add equality tests
This commit is contained in:
parent
b638f0db87
commit
52922512e5
1 changed files with 50 additions and 0 deletions
50
vm/vm_equality_test.go
Normal file
50
vm/vm_equality_test.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package vm_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEquality(t *testing.T) {
|
||||
testEquality(t, `1`, `1`, true)
|
||||
testEquality(t, `1`, `2`, false)
|
||||
|
||||
testEquality(t, `1.0`, `1.0`, true)
|
||||
testEquality(t, `1.0`, `1.1`, false)
|
||||
|
||||
testEquality(t, `true`, `true`, true)
|
||||
testEquality(t, `true`, `false`, false)
|
||||
|
||||
testEquality(t, `"foo"`, `"foo"`, true)
|
||||
testEquality(t, `"foo"`, `"bar"`, false)
|
||||
|
||||
testEquality(t, `'f'`, `'f'`, true)
|
||||
testEquality(t, `'f'`, `'b'`, false)
|
||||
|
||||
testEquality(t, `[]`, `[]`, true)
|
||||
testEquality(t, `[1]`, `[1]`, true)
|
||||
testEquality(t, `[1]`, `[1, 2]`, false)
|
||||
testEquality(t, `["foo", "bar"]`, `["foo", "bar"]`, true)
|
||||
testEquality(t, `["foo", "bar"]`, `["bar", "foo"]`, false)
|
||||
|
||||
testEquality(t, `{}`, `{}`, true)
|
||||
testEquality(t, `{a: 1, b: 2}`, `{b: 2, a: 1}`, true)
|
||||
testEquality(t, `{a: 1, b: 2}`, `{b: 2}`, false)
|
||||
testEquality(t, `{a: 1, b: {}}`, `{b: {}, a: 1}`, true)
|
||||
|
||||
testEquality(t, `1`, `"foo"`, false)
|
||||
testEquality(t, `1`, `true`, false)
|
||||
testEquality(t, `[1]`, `["1"]`, false)
|
||||
testEquality(t, `[1, [2]]`, `[1, ["2"]]`, false)
|
||||
testEquality(t, `{a: 1}`, `{a: "1"}`, false)
|
||||
testEquality(t, `{a: 1, b: {c: 2}}`, `{a: 1, b: {c: "2"}}`, false)
|
||||
}
|
||||
|
||||
func testEquality(t *testing.T, lhs, rhs string, expected bool) {
|
||||
// 1. equality is commutative
|
||||
// 2. equality and inequality must be always opposite
|
||||
expect(t, fmt.Sprintf("out = %s == %s", lhs, rhs), expected)
|
||||
expect(t, fmt.Sprintf("out = %s == %s", rhs, lhs), expected)
|
||||
expect(t, fmt.Sprintf("out = %s != %s", lhs, rhs), !expected)
|
||||
expect(t, fmt.Sprintf("out = %s != %s", rhs, lhs), !expected)
|
||||
}
|
Loading…
Reference in a new issue