Debian Codegraph @

parsing/csv/csv_test.go

raw symbols SCIP
1 package csv
2
3 import (
4 "github.com/tomwright/dasel/v3/model"
5 "testing"
6 )
7
8 func TestValueToString(t *testing.T) {
9 tests := []struct {
10 desc string
11 in func() (*model.Value, error)
12 exp string
13 }{
14 {
15 desc: "basic string",
16 in: func() (*model.Value, error) {
17 return model.NewStringValue("hello"), nil
18 },
19 exp: "hello",
20 },
21 {
22 desc: "string",
23 in: func() (*model.Value, error) {
24 return model.NewStringValue("hello, there!!"), nil
25 },
26 exp: "hello, there!!",
27 },
28 {
29 desc: "int",
30 in: func() (*model.Value, error) {
31 return model.NewIntValue(123), nil
32 },
33 exp: "123",
34 },
35 {
36 desc: "float",
37 in: func() (*model.Value, error) {
38 return model.NewFloatValue(1.234), nil
39 },
40 exp: "1.234",
41 },
42 {
43 desc: "null",
44 in: func() (*model.Value, error) {
45 return model.NewNullValue(), nil
46 },
47 exp: "",
48 },
49 {
50 desc: "bool true",
51 in: func() (*model.Value, error) {
52 return model.NewBoolValue(true), nil
53 },
54 exp: "true",
55 },
56 {
57 desc: "bool false",
58 in: func() (*model.Value, error) {
59 return model.NewBoolValue(false), nil
60 },
61 exp: "false",
62 },
63 }
64
65 for _, testCase := range tests {
66 tc := testCase
67 t.Run(tc.desc, func(t *testing.T) {
68 in, err := tc.in()
69 if err != nil {
70 t.Fatalf("unexpected error: %v", err)
71 }
72 got, err := valueToString(in)
73 if err != nil {
74 t.Fatalf("unexpected error: %v", err)
75 }
76 if got != tc.exp {
77 t.Errorf("expected '%s' but got '%s'", tc.exp, got)
78 }
79 })
80 }
81 }