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

Function TestBranch

execution/execute_branch_test.go:10–148  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestBranch(t *testing.T) {
11 t.Run("single branch", testCase{
12 s: "branch(1)",
13 outFn: func() *model.Value {
14 r := model.NewSliceValue()
15 r.MarkAsBranch()
16 if err := r.Append(model.NewIntValue(1)); err != nil {
17 t.Fatalf("unexpected error: %v", err)
18 }
19 return r
20 },
21 opts: []execution.ExecuteOptionFn{
22 execution.WithUnstable(),
23 },
24 }.run)
25 t.Run("many branches", testCase{
26 s: "branch(1, 1+1, 3/1, 123)",
27 outFn: func() *model.Value {
28 r := model.NewSliceValue()
29 r.MarkAsBranch()
30 if err := r.Append(model.NewIntValue(1)); err != nil {
31 t.Fatalf("unexpected error: %v", err)
32 }
33 if err := r.Append(model.NewIntValue(2)); err != nil {
34 t.Fatalf("unexpected error: %v", err)
35 }
36 if err := r.Append(model.NewIntValue(3)); err != nil {
37 t.Fatalf("unexpected error: %v", err)
38 }
39 if err := r.Append(model.NewIntValue(123)); err != nil {
40 t.Fatalf("unexpected error: %v", err)
41 }
42 return r
43 },
44 opts: []execution.ExecuteOptionFn{
45 execution.WithUnstable(),
46 },
47 }.run)
48 t.Run("spread into many branches", testCase{
49 s: "[1,2,3].branch(...)",
50 outFn: func() *model.Value {
51 r := model.NewSliceValue()
52 r.MarkAsBranch()
53 if err := r.Append(model.NewIntValue(1)); err != nil {
54 t.Fatalf("unexpected error: %v", err)
55 }
56 if err := r.Append(model.NewIntValue(2)); err != nil {
57 t.Fatalf("unexpected error: %v", err)
58 }
59 if err := r.Append(model.NewIntValue(3)); err != nil {
60 t.Fatalf("unexpected error: %v", err)
61 }
62 return r
63 },
64 opts: []execution.ExecuteOptionFn{
65 execution.WithUnstable(),
66 },
67 }.run)

Callers

nothing calls this directly

Calls 6

NewSliceValueFunction · 0.92
NewIntValueFunction · 0.92
WithUnstableFunction · 0.92
MarkAsBranchMethod · 0.80
AppendMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected