Debian Codegraph @

parsing/csv/writer_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 TestCsvWriter_Writescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/csv_test`/TestCsvWriter_Write().(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 expBytes := []byte(`name,age,city
12 Alice,30,New York
13 Bob,25,Los Angeles
14 Charlie,35,Chicago
15 `)
16
17 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..NewWriterscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Format#NewWriter().(parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/.DefaultWriterOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/DefaultWriterOptions().())
18 if err != nil {
19 t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("unexpected error: %v", err)
20 }
21
22 rows := 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().()
23 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().()
24 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 {
25 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
26 }
27 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 {
28 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
29 }
30 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 {
31 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
32 }
33 if err := rows.Appendscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Append().(row1); err != nil {
34 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
35 }
36 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().()
37 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 {
38 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
39 }
40 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 {
41 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
42 }
43 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 {
44 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
45 }
46 if err := rows.Appendscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Append().(row2); err != nil {
47 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
48 }
49 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().()
50 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 {
51 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
52 }
53 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 {
54 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
55 }
56 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 {
57 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
58 }
59 if err := rows.Appendscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Append().(row3); err != nil {
60 t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err)
61 }
62
63 got, err := r.Writescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Writer#Write.(rows)
64 if err != nil {
65 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("unexpected error: %v", err)
66 return
67 }
68
69 if string(expBytes) != string(got) {
70 t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected:\n%s\ngot:\n%s", string(expBytes), string(got))
71 }
72 }