MCPcopy
hub / github.com/TomWright/dasel / TestRun

Function TestRun

internal/cli/command_test.go:63–456  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestRun(t *testing.T) {
64 t.Run("complex set", func(t *testing.T) {
65 t.Run("set nested with spread", runTest(testCase{
66 args: []string{"-i", "json", "-o", "json", "--root", `user = {user..., name: {"first": $this.user.name, "last": "Doe"}}`},
67 in: []byte(`{"user": {"name": "John"}}`),
68 stdout: []byte(`{
69 "user": {
70 "name": {
71 "first": "John",
72 "last": "Doe"
73 }
74 }
75}
76`),
77 stderr: nil,
78 err: nil,
79 }))
80 t.Run("set nested", runTest(testCase{
81 args: []string{"-i", "json", "-o", "json", "--root", `user.name = {"first": user.name, "last": "Doe"}`},
82 in: []byte(`{"user": {"name": "John"}}`),
83 stdout: []byte(`{
84 "user": {
85 "name": {
86 "first": "John",
87 "last": "Doe"
88 }
89 }
90}
91`),
92 stderr: nil,
93 err: nil,
94 }))
95 t.Run("set nested with localised group", runTest(testCase{
96 args: []string{"-i", "json", "-o", "json", "--root", `user.(name = {"first": name, "last": "Doe"})`},
97 in: []byte(`{"user": {"name": "John"}}`),
98 stdout: []byte(`{
99 "user": {
100 "name": {
101 "first": "John",
102 "last": "Doe"
103 }
104 }
105}
106`),
107 stderr: nil,
108 err: nil,
109 }))
110 t.Run("set recursive descent", func(t *testing.T) {
111
112 t.Run("property", runTest(testCase{
113 args: []string{"-i", "json", "-o", "json", "--root", `$root..x.each($this = $this+1)`},
114 in: []byte(`[{"x":1},{"x":2},{"x":3}]`),
115 stdout: []byte(`[
116 {
117 "x": 2
118 },
119 {
120 "x": 3

Callers

nothing calls this directly

Calls 2

runTestFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected