Debian Codegraph @

parsing/csv/reader_test.go

raw symbols SCIP
1 package csv_testscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/csv_test`/
2
3 import (
4 "github.com/tomwright/dasel/v3/modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/"
5 "github.com/tomwright/dasel/v3/parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/"
6 "github.com/tomwright/dasel/v3/parsing/csvscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/csv`/"
7 "testingscip-go gomod github.com/golang/go/src go1.25 testing/"
8 )
9
10 func TestCsvReader_Readscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/csv_test`/TestCsvReader_Read().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) {
11 inputBytes := []byte(`name,age,city
12 Alice,30,New York
13 Bob,25,Los Angeles
14 Charlie,35,Chicago`)
15
16 r, err := csvscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/csv`/.CSVscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/csv`/CSV..NewReaderscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Format#NewReader().(parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/.DefaultReaderOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/DefaultReaderOptions().())
17 if err != nil {
18 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("unexpected error: %v", err)
19 }
20
21 got, err := r.Readscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Reader#Read.(inputBytes)
22 if err != nil {
23 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("unexpected error: %v", err)
24 return
25 }
26
27 exp := modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewSliceValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewSliceValue().()
28 row1 := modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewMapValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewMapValue().()
29 if err := row1.SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().("name", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewStringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewStringValue().("Alice")); err != nil {
30 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
31 }
32 if err := row1.SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().("age", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewStringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewStringValue().("30")); err != nil {
33 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
34 }
35 if err := row1.SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().("city", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewStringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewStringValue().("New York")); err != nil {
36 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
37 }
38 if err := exp.Appendscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Append().(row1); err != nil {
39 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
40 }
41 row2 := modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewMapValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewMapValue().()
42 if err := row2.SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().("name", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewStringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewStringValue().("Bob")); err != nil {
43 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
44 }
45 if err := row2.SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().("age", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewStringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewStringValue().("25")); err != nil {
46 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
47 }
48 if err := row2.SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().("city", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewStringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewStringValue().("Los Angeles")); err != nil {
49 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
50 }
51 if err := exp.Appendscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Append().(row2); err != nil {
52 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
53 }
54 row3 := modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewMapValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewMapValue().()
55 if err := row3.SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().("name", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewStringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewStringValue().("Charlie")); err != nil {
56 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
57 }
58 if err := row3.SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().("age", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewStringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewStringValue().("35")); err != nil {
59 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
60 }
61 if err := row3.SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().("city", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewStringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewStringValue().("Chicago")); err != nil {
62 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
63 }
64 if err := exp.Appendscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Append().(row3); err != nil {
65 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
66 }
67 matchRes, err := got.Equalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Equal().(exp)
68 if err != nil {
69 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("error comparing values: %v", err)
70 }
71 match, err := matchRes.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
72 if err != nil {
73 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("error getting bool value: %v", err)
74 }
75 if !match {
76 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected %v, got %v", exp, got)
77 }
78 }