-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgvalstrings_test.go
57 lines (51 loc) · 1.12 KB
/
gvalstrings_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
47
48
49
50
51
52
53
54
55
56
57
package gvalstrings
import (
"fmt"
"reflect"
"strings"
"testing"
"github.com/PaesslerAG/gval"
)
func TestSingleQuoted(t *testing.T) {
tests := []struct {
expression string
want interface{}
wantError string
}{
{
expression: `'Hello World'`,
want: `Hello World`,
},
{
expression: `'Hello World' + 10`,
want: `Hello World10`,
},
{
expression: `'Hello' World'`,
wantError: `unexpected Ident while scanning operator`,
},
}
for _, tt := range tests {
t.Run(tt.expression, func(t *testing.T) {
got, err := gval.Evaluate(tt.expression, nil, SingleQuoted())
if tt.wantError != "" {
if err == nil || !strings.Contains(err.Error(), tt.wantError) {
t.Errorf("got error %v, want error %v", err, tt.wantError)
}
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("gval.Evaluate(%s, SingleQuoted()) = %v, %v, want %v", tt.expression, got, err, tt.want)
}
})
}
}
func ExampleSingleQuoted() {
value, err := gval.Evaluate(`'Hello `+"World!", nil, SingleQuoted())
if err != nil {
panic(err)
}
fmt.Println(value)
// Output
// Hello World!
}