From e72123b6cb44ece1db98ca60c441c57bd40b1499 Mon Sep 17 00:00:00 2001 From: Flipez Date: Mon, 27 Dec 2021 22:41:12 +0100 Subject: [PATCH] sourround strings in inspect with quotes Signed-off-by: Flipez --- object/hash_test.go | 6 +++--- object/return_value_test.go | 2 +- object/string.go | 10 +++++----- object/string_test.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/object/hash_test.go b/object/hash_test.go index 849ccf6..3b42d3d 100644 --- a/object/hash_test.go +++ b/object/hash_test.go @@ -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"}, @@ -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 { diff --git a/object/return_value_test.go b/object/return_value_test.go index 6879dec..44ef89c 100644 --- a/object/return_value_test.go +++ b/object/return_value_test.go @@ -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") } } diff --git a/object/string.go b/object/string.go index 7d516ed..ea20666 100644 --- a/object/string.go +++ b/object/string.go @@ -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))} }, }, @@ -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))} }, }, @@ -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)} }, }, @@ -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) } diff --git a/object/string_test.go b/object/string_test.go index 6bb1aa3..1b09783 100644 --- a/object/string_test.go +++ b/object/string_test.go @@ -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"},