Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sourround strings in inspect with quotes #25

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions object/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestHashObjectMethods(t *testing.T) {
tests := []inputTestCase{
{`{"a": 2}.keys()`, "[a]"},
{`{"a": 2}.keys()`, `["a"]`},
{`{}.nope()`, "Failed to invoke method: nope"},
{`({}.wat().lines().size() == {}.methods().size() + 1).plz_s()`, "true"},
{`{}.type()`, "HASH"},
Expand All @@ -24,8 +24,8 @@ func TestHashObjectMethods(t *testing.T) {
func TestHashInspect(t *testing.T) {
tests := []inputTestCase{
{"{}", "{}"},
{`{"a": 1}`, "{a: 1}"},
{`{true: "a"}`, "{true: a}"},
{`{"a": 1}`, `{"a": 1}`},
{`{true: "a"}`, `{true: "a"}`},
}

for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion object/return_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestReturnValue(t *testing.T) {
if rv.Type() != object.RETURN_VALUE_OBJ {
t.Errorf("returnValue.Type() returns wrong type")
}
if rv.Inspect() != "a" {
if rv.Inspect() != `"a"` {
t.Errorf("returnValue.Inspect() returns wrong type")
}
}
10 changes: 5 additions & 5 deletions object/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
},
method: func(o Object, args []Object) Object {
s := o.(*String)
arg := args[0].Inspect()
arg := args[0].(*String).Value
return &Integer{Value: int64(strings.Count(s.Value, arg))}
},
},
Expand All @@ -50,7 +50,7 @@ func init() {
},
method: func(o Object, args []Object) Object {
s := o.(*String)
arg := args[0].Inspect()
arg := args[0].(*String).Value
return &Integer{Value: int64(strings.Index(s.Value, arg))}
},
},
Expand Down Expand Up @@ -119,8 +119,8 @@ func init() {
},
method: func(o Object, args []Object) Object {
s := o.(*String)
oldS := args[0].Inspect()
newS := args[1].Inspect()
oldS := args[0].(*String).Value
newS := args[1].(*String).Value
return &String{Value: strings.Replace(s.Value, oldS, newS, -1)}
},
},
Expand Down Expand Up @@ -312,7 +312,7 @@ func init() {
}

func (s *String) Type() ObjectType { return STRING_OBJ }
func (s *String) Inspect() string { return s.Value }
func (s *String) Inspect() string { return `"` + s.Value + `"` }
func (s *String) InvokeMethod(method string, env Environment, args ...Object) Object {
return objectMethodLookup(s, method, args)
}
Expand Down
4 changes: 2 additions & 2 deletions object/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestStringObjectMethods(t *testing.T) {
{`"test".replace()`, "To few arguments: want=2, got=0"},
{`"test".replace("e")`, "To few arguments: want=2, got=1"},
{`"test".reverse()`, "tset"},
{`"test test1".split()`, `[test, test1]`},
{`"test test1".split(",")`, `[test test1]`},
{`"test test1".split()`, `["test", "test1"]`},
{`"test test1".split(",")`, `["test test1"]`},
{`"test test1".split(",", "x")`, `To many arguments: want=1, got=2`},
{`"test".split(1)`, `Wrong argument type on position 0: got=INTEGER, want=STRING`},
{`"test ".strip()`, "test"},
Expand Down