@@ -8,118 +8,120 @@ import (
8
8
)
9
9
10
10
var _ = Describe ("ArrayIndex" , func () {
11
+ dummyPath := MustNewPointerFromString ("" )
12
+
11
13
Describe ("Concrete" , func () {
12
14
It ("returns positive index" , func () {
13
- idx := ArrayIndex {Index : 0 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }}
15
+ idx := ArrayIndex {Index : 0 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
14
16
Expect (idx .Concrete ()).To (Equal (0 ))
15
17
16
- idx = ArrayIndex {Index : 1 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }}
18
+ idx = ArrayIndex {Index : 1 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
17
19
Expect (idx .Concrete ()).To (Equal (1 ))
18
20
19
- idx = ArrayIndex {Index : 2 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }}
21
+ idx = ArrayIndex {Index : 2 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
20
22
Expect (idx .Concrete ()).To (Equal (2 ))
21
23
})
22
24
23
25
It ("wraps around negative index one time" , func () {
24
- idx := ArrayIndex {Index : - 0 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }}
26
+ idx := ArrayIndex {Index : - 0 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
25
27
Expect (idx .Concrete ()).To (Equal (0 ))
26
28
27
- idx = ArrayIndex {Index : - 1 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }}
29
+ idx = ArrayIndex {Index : - 1 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
28
30
Expect (idx .Concrete ()).To (Equal (2 ))
29
31
30
- idx = ArrayIndex {Index : - 2 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }}
32
+ idx = ArrayIndex {Index : - 2 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
31
33
Expect (idx .Concrete ()).To (Equal (1 ))
32
34
33
- idx = ArrayIndex {Index : - 3 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }}
35
+ idx = ArrayIndex {Index : - 3 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
34
36
Expect (idx .Concrete ()).To (Equal (0 ))
35
37
})
36
38
37
39
It ("does not work with empty arrays" , func () {
38
- idx := ArrayIndex {Index : 0 , Modifiers : nil , Array : []interface {}{}}
40
+ idx := ArrayIndex {Index : 0 , Modifiers : nil , Array : []interface {}{}, Path : dummyPath }
39
41
_ , err := idx .Concrete ()
40
- Expect (err ).To (Equal (OpMissingIndexErr {0 , []interface {}{}}))
42
+ Expect (err ).To (Equal (OpMissingIndexErr {0 , []interface {}{}, dummyPath }))
41
43
42
44
p := PrevModifier {}
43
45
n := NextModifier {}
44
46
45
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {p , n }, Array : []interface {}{}}
47
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {p , n }, Array : []interface {}{}, Path : dummyPath }
46
48
_ , err = idx .Concrete ()
47
- Expect (err ).To (Equal (OpMissingIndexErr {0 , []interface {}{}}))
49
+ Expect (err ).To (Equal (OpMissingIndexErr {0 , []interface {}{}, dummyPath }))
48
50
})
49
51
50
52
It ("does not work with index out of bounds" , func () {
51
- idx := ArrayIndex {Index : 3 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }}
53
+ idx := ArrayIndex {Index : 3 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
52
54
_ , err := idx .Concrete ()
53
- Expect (err ).To (Equal (OpMissingIndexErr {3 , []interface {}{1 , 2 , 3 }}))
55
+ Expect (err ).To (Equal (OpMissingIndexErr {3 , []interface {}{1 , 2 , 3 }, dummyPath }))
54
56
55
- idx = ArrayIndex {Index : - 4 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }}
57
+ idx = ArrayIndex {Index : - 4 , Modifiers : nil , Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
56
58
_ , err = idx .Concrete ()
57
- Expect (err ).To (Equal (OpMissingIndexErr {- 4 , []interface {}{1 , 2 , 3 }}))
59
+ Expect (err ).To (Equal (OpMissingIndexErr {- 4 , []interface {}{1 , 2 , 3 }, dummyPath }))
58
60
})
59
61
60
62
It ("returns previous item when previous modifier is used" , func () {
61
63
p := PrevModifier {}
62
64
63
- idx := ArrayIndex {Index : 0 , Modifiers : []Modifier {p }, Array : []interface {}{1 , 2 , 3 }}
65
+ idx := ArrayIndex {Index : 0 , Modifiers : []Modifier {p }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
64
66
Expect (idx .Concrete ()).To (Equal (2 ))
65
67
66
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {p , p }, Array : []interface {}{1 , 2 , 3 }}
68
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {p , p }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
67
69
Expect (idx .Concrete ()).To (Equal (1 ))
68
70
69
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {p , p , p }, Array : []interface {}{1 , 2 , 3 }}
71
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {p , p , p }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
70
72
Expect (idx .Concrete ()).To (Equal (0 ))
71
73
72
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {p , p , p , p }, Array : []interface {}{1 , 2 , 3 }}
74
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {p , p , p , p }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
73
75
_ , err := idx .Concrete ()
74
- Expect (err ).To (Equal (OpMissingIndexErr {- 4 , []interface {}{1 , 2 , 3 }}))
76
+ Expect (err ).To (Equal (OpMissingIndexErr {- 4 , []interface {}{1 , 2 , 3 }, dummyPath }))
75
77
76
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {p , p , p , p , p }, Array : []interface {}{1 , 2 , 3 }}
78
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {p , p , p , p , p }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
77
79
_ , err = idx .Concrete ()
78
- Expect (err ).To (Equal (OpMissingIndexErr {- 5 , []interface {}{1 , 2 , 3 }}))
80
+ Expect (err ).To (Equal (OpMissingIndexErr {- 5 , []interface {}{1 , 2 , 3 }, dummyPath }))
79
81
80
- idx = ArrayIndex {Index : 2 , Modifiers : []Modifier {p , p }, Array : []interface {}{1 , 2 , 3 }}
82
+ idx = ArrayIndex {Index : 2 , Modifiers : []Modifier {p , p }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
81
83
Expect (idx .Concrete ()).To (Equal (0 ))
82
84
})
83
85
84
86
It ("returns next item when next modifier is used" , func () {
85
87
n := NextModifier {}
86
88
87
- idx := ArrayIndex {Index : 0 , Modifiers : []Modifier {n }, Array : []interface {}{1 , 2 , 3 }}
89
+ idx := ArrayIndex {Index : 0 , Modifiers : []Modifier {n }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
88
90
Expect (idx .Concrete ()).To (Equal (1 ))
89
91
90
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , n }, Array : []interface {}{1 , 2 , 3 }}
92
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , n }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
91
93
Expect (idx .Concrete ()).To (Equal (2 ))
92
94
93
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , n , n }, Array : []interface {}{1 , 2 , 3 }}
95
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , n , n }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
94
96
_ , err := idx .Concrete ()
95
- Expect (err ).To (Equal (OpMissingIndexErr {3 , []interface {}{1 , 2 , 3 }}))
97
+ Expect (err ).To (Equal (OpMissingIndexErr {3 , []interface {}{1 , 2 , 3 }, dummyPath }))
96
98
97
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , n , n , n }, Array : []interface {}{1 , 2 , 3 }}
99
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , n , n , n }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
98
100
_ , err = idx .Concrete ()
99
- Expect (err ).To (Equal (OpMissingIndexErr {4 , []interface {}{1 , 2 , 3 }}))
101
+ Expect (err ).To (Equal (OpMissingIndexErr {4 , []interface {}{1 , 2 , 3 }, dummyPath }))
100
102
})
101
103
102
104
It ("works with multiple previous and next modifiers" , func () {
103
105
p := PrevModifier {}
104
106
n := NextModifier {}
105
107
106
- idx := ArrayIndex {Index : 0 , Modifiers : []Modifier {p , n }, Array : []interface {}{1 , 2 , 3 }}
108
+ idx := ArrayIndex {Index : 0 , Modifiers : []Modifier {p , n }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
107
109
Expect (idx .Concrete ()).To (Equal (0 ))
108
110
109
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , p }, Array : []interface {}{1 , 2 , 3 }}
111
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , p }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
110
112
Expect (idx .Concrete ()).To (Equal (0 ))
111
113
112
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , n , p }, Array : []interface {}{1 , 2 , 3 }}
114
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , n , p }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
113
115
Expect (idx .Concrete ()).To (Equal (1 ))
114
116
115
- idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , n , n , p }, Array : []interface {}{1 , 2 , 3 }}
117
+ idx = ArrayIndex {Index : 0 , Modifiers : []Modifier {n , n , n , p }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
116
118
Expect (idx .Concrete ()).To (Equal (2 ))
117
119
})
118
120
119
121
It ("does not support any other modifier except previous and next" , func () {
120
122
b := BeforeModifier {}
121
123
122
- idx := ArrayIndex {Index : 0 , Modifiers : []Modifier {b }, Array : []interface {}{1 , 2 , 3 }}
124
+ idx := ArrayIndex {Index : 0 , Modifiers : []Modifier {b }, Array : []interface {}{1 , 2 , 3 }, Path : dummyPath }
123
125
_ , err := idx .Concrete ()
124
126
Expect (err .Error ()).To (Equal ("Expected to find one of the following modifiers: 'prev', 'next', but found modifier 'patch.BeforeModifier'" ))
125
127
})
0 commit comments