forked from google/starlark-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
value_test.go
46 lines (40 loc) · 1.1 KB
/
value_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)
}
}