Skip to content

Commit

Permalink
sourround strings in inspect with quotes
Browse files Browse the repository at this point in the history
Signed-off-by: Flipez <[email protected]>
  • Loading branch information
Flipez committed Dec 27, 2021
1 parent 3bb79bc commit e72123b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
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

0 comments on commit e72123b

Please sign in to comment.