Add failed tests.
@@ -94,6 +94,67 @@ func TestComment(t *testing.T) {
v.checkSP(t, 0, 1)
}
+func TestConstantNamespace(t *testing.T) {
+ tests := []struct {
+ input string
+ expected []interface{}
+ }{
+ {`
+ class Foo
+ VAL="Foo's constant value"
+ def foo
+ VAL
+ end
+ end
+ VAL="toplevel constant value"
+ a = [VAL, Foo::VAL, Foo.new.foo]
+ a
+ `, []interface{}{"toplevel constant value", "Foo's constant value", "Foo's constant value"}},
+ {`
+ VAL="toplevel constant value"
+ class Foo
+ VAL="Foo's constant value"
+ def foo
+ VAL
+ end
+ end
+ a = [VAL, Foo::VAL, Foo.new.foo]
+ a
+ `, []interface{}{"toplevel constant value", "Foo's constant value", "Foo's constant value"}},
+ {`
+ class Foo
+ VAL="Foo's constant value"
+ def foo
+ VAL
+ end
+ end
+ class VAL; end
+
+ a = [VAL.name, Foo::VAL, Foo.new.foo]
+ a
+ `, []interface{}{"VAL", "Foo's constant value", "Foo's constant value"}},
+ {`
+ class VAL; end
+ class Foo
+ VAL="Foo's constant value"
+ def foo
+ VAL
+ end
+ end
+ a = [VAL.name, Foo::VAL, Foo.new.foo]
+ a
+ `, []interface{}{"VAL", "Foo's constant value", "Foo's constant value"}},
+ }
+
+ for i, tt := range tests {
+ vm := initTestVM()
+ evaluated := vm.testEval(t, tt.input, getFilename())
+ testArrayObject(t, i, evaluated, tt.expected)
+ vm.checkCFP(t, i, 0)
+ vm.checkSP(t, i, 1)
+ }
+}
+
func TestMethodCall(t *testing.T) {
tests := []struct {
input string
