diff options
Diffstat (limited to 'starlark/value_test.go')
-rw-r--r-- | starlark/value_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/starlark/value_test.go b/starlark/value_test.go new file mode 100644 index 0000000..6420a95 --- /dev/null +++ b/starlark/value_test.go @@ -0,0 +1,46 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package starlark_test + +// This file defines tests of the Value API. + +import ( + "fmt" + "testing" + + "go.starlark.net/starlark" +) + +func TestStringMethod(t *testing.T) { + s := starlark.String("hello") + for i, test := range [][2]string{ + // quoted string: + {s.String(), `"hello"`}, + {fmt.Sprintf("%s", s), `"hello"`}, + {fmt.Sprintf("%+s", s), `"hello"`}, + {fmt.Sprintf("%v", s), `"hello"`}, + {fmt.Sprintf("%+v", s), `"hello"`}, + // unquoted: + {s.GoString(), `hello`}, + {fmt.Sprintf("%#v", s), `hello`}, + } { + got, want := test[0], test[1] + if got != want { + t.Errorf("#%d: got <<%s>>, want <<%s>>", i, got, want) + } + } +} + +func TestListAppend(t *testing.T) { + l := starlark.NewList(nil) + l.Append(starlark.String("hello")) + res, ok := starlark.AsString(l.Index(0)) + if !ok { + t.Errorf("failed list.Append() got: %s, want: starlark.String", l.Index(0).Type()) + } + if res != "hello" { + t.Errorf("failed list.Append() got: %+v, want: hello", res) + } +} |