@@ -5,108 +5,155 @@ import (
5
5
6
6
. "github.com/onsi/ginkgo/v2"
7
7
. "github.com/onsi/gomega"
8
- v1 "ocm.software/ocm/api/ocm/refhints"
8
+
9
+ "ocm.software/ocm/api/ocm/refhints"
9
10
)
10
11
11
12
var _ = Describe ("Hints Test Environment" , func () {
12
13
Context ("hint" , func () {
13
14
It ("single attr" , func () {
14
- CheckHint ("test" , v1 .New ("" , "test" ))
15
- CheckHint (`te\st` , v1 .New ("" , "te\\ st" ))
16
- CheckHint (`"test"` , v1 .New ("" , "test" ))
17
- CheckHint (`"te;st"` , v1 .New ("" , "te;st" ))
18
- CheckHint (`"te,st"` , v1 .New ("" , "te,st" ))
19
- CheckHint ("typ::te\\ st" , v1 .New ("typ" , "te\\ st" ))
20
- CheckHint ("typ::test" , v1 .New ("typ" , "test" ))
21
- CheckHint (`typ::"te\"st"` , v1 .New ("typ" , `te"st` ))
22
- CheckHint (`typ::te\st` , v1 .New ("typ" , `te\st` ))
23
- CheckHint (`typ::x="te\\;st"` , v1.DefaultReferenceHint {
24
- v1 .HINT_TYPE : "typ" ,
25
- "x" : `te\;st` ,
15
+ CheckHint ("test" , refhints .New ("" , "test" ))
16
+ CheckHint (`te\st` , refhints .New ("" , "te\\ st" ))
17
+ CheckHint (`"test"` , refhints .New ("" , "test" ))
18
+ CheckHint (`"te;st"` , refhints .New ("" , "te;st" ))
19
+ CheckHint (`"te,st"` , refhints .New ("" , "te,st" ))
20
+ CheckHint ("typ::te\\ st" , refhints .New ("typ" , "te\\ st" ))
21
+ CheckHint ("typ::test" , refhints .New ("typ" , "test" ))
22
+ CheckHint (`typ::"te\"st"` , refhints .New ("typ" , `te"st` ))
23
+ CheckHint (`typ::te\st` , refhints .New ("typ" , `te\st` ))
24
+ CheckHint (`typ::x="te\\;st"` , refhints.DefaultReferenceHint {
25
+ refhints .HINT_TYPE : "typ" ,
26
+ "x" : `te\;st` ,
27
+ })
28
+ CheckHint (`typ::x=test` , refhints.DefaultReferenceHint {
29
+ refhints .HINT_TYPE : "typ" ,
30
+ "x" : `test` ,
31
+ })
32
+ CheckHint (`typ::xy=test` , refhints.DefaultReferenceHint {
33
+ refhints .HINT_TYPE : "typ" ,
34
+ "xy" : `test` ,
35
+ })
36
+ CheckHint (`typ::x,=test` , refhints.DefaultReferenceHint {
37
+ refhints .HINT_TYPE : "typ" ,
38
+ "x," : `test` ,
26
39
})
27
- CheckHint (`typ::x =test` , v1 .DefaultReferenceHint {
28
- v1 . HINT_TYPE : "typ " ,
29
- "x" : `test` ,
40
+ CheckHint ("ref =test,x=y" , refhints .DefaultReferenceHint {
41
+ "ref" : "test " ,
42
+ "x" : "y" ,
30
43
})
31
- CheckHint (`typ::xy=test` , v1.DefaultReferenceHint {
32
- v1 .HINT_TYPE : "typ" ,
33
- "xy" : `test` ,
44
+ CheckHint (`"test,x=y"` , refhints.DefaultReferenceHint {
45
+ refhints .HINT_REFERENCE : "test,x=y" ,
34
46
})
35
- CheckHint ( `typ::x, =test` , v1 .DefaultReferenceHint {
36
- v1 . HINT_TYPE : "typ " ,
37
- "x, " : `test` ,
47
+ CheckHint2 ( "test,x=y" , "reference =test,x=y" , refhints .DefaultReferenceHint {
48
+ refhints . HINT_REFERENCE : "test " ,
49
+ "x" : "y" ,
38
50
})
39
51
})
40
52
41
53
It ("multi attr" , func () {
42
- CheckHint (`typ::x=te\st,xy=test` , v1 .DefaultReferenceHint {
43
- v1 .HINT_TYPE : "typ" ,
44
- "x" : `te\st` ,
45
- "xy" : "test" ,
54
+ CheckHint (`typ::x=te\st,xy=test` , refhints .DefaultReferenceHint {
55
+ refhints .HINT_TYPE : "typ" ,
56
+ "x" : `te\st` ,
57
+ "xy" : "test" ,
46
58
})
47
59
})
48
60
})
49
61
50
62
Context ("hints" , func () {
51
63
It ("regular" , func () {
52
64
CheckHint ("x::y;test" ,
53
- v1 .New ("x" , `y` ),
54
- v1 .New ("" , "test" ))
65
+ refhints .New ("x" , `y` ),
66
+ refhints .New ("" , "test" ))
55
67
CheckHint ("x::y;typ::test" ,
56
- v1 .New ("x" , `y` ),
57
- v1 .New ("typ" , "test" ))
68
+ refhints .New ("x" , `y` ),
69
+ refhints .New ("typ" , "test" ))
58
70
CheckHint (`x::y;typ::"te\"st"` ,
59
- v1 .New ("x" , `y` ),
60
- v1 .New ("typ" , `te"st` ))
71
+ refhints .New ("x" , `y` ),
72
+ refhints .New ("typ" , `te"st` ))
61
73
CheckHint (`x::y;typ::"te;st"` ,
62
- v1 .New ("x" , `y` ),
63
- v1 .New ("typ" , `te;st` ))
74
+ refhints .New ("x" , `y` ),
75
+ refhints .New ("typ" , `te;st` ))
64
76
CheckHint (`x::y;typ::"te,st"` ,
65
- v1 .New ("x" , `y` ),
66
- v1 .New ("typ" , `te,st` ))
77
+ refhints .New ("x" , `y` ),
78
+ refhints .New ("typ" , `te,st` ))
67
79
CheckHint (`x::y;typ::te\st` ,
68
- v1 .New ("x" , `y` ),
69
- v1 .New ("typ" , `te\st` ))
80
+ refhints .New ("x" , `y` ),
81
+ refhints .New ("typ" , `te\st` ))
70
82
CheckHint (`x::y;typ::x=te\st` ,
71
- v1 .New ("x" , `y` ),
72
- v1 .DefaultReferenceHint {
73
- v1 .HINT_TYPE : "typ" ,
74
- "x" : `te\st` ,
83
+ refhints .New ("x" , `y` ),
84
+ refhints .DefaultReferenceHint {
85
+ refhints .HINT_TYPE : "typ" ,
86
+ "x" : `te\st` ,
75
87
})
76
88
CheckHint (`x::y;typ::x=test` ,
77
- v1 .New ("x" , `y` ),
78
- v1 .DefaultReferenceHint {
79
- v1 .HINT_TYPE : "typ" ,
80
- "x" : `test` ,
89
+ refhints .New ("x" , `y` ),
90
+ refhints .DefaultReferenceHint {
91
+ refhints .HINT_TYPE : "typ" ,
92
+ "x" : `test` ,
81
93
})
82
94
CheckHint (`x::y;typ::xy=test` ,
83
- v1 .New ("x" , `y` ),
84
- v1 .DefaultReferenceHint {
85
- v1 .HINT_TYPE : "typ" ,
86
- "xy" : `test` ,
95
+ refhints .New ("x" , `y` ),
96
+ refhints .DefaultReferenceHint {
97
+ refhints .HINT_TYPE : "typ" ,
98
+ "xy" : `test` ,
87
99
})
88
100
CheckHint (`x::y;typ::x,=test` ,
89
- v1 .New ("x" , `y` ),
90
- v1.DefaultReferenceHint {
91
- v1 .HINT_TYPE : "typ" ,
92
- "x," : `test` ,
101
+ refhints .New ("x" , `y` ),
102
+ refhints.DefaultReferenceHint {
103
+ refhints .HINT_TYPE : "typ" ,
104
+ "x," : `test` ,
105
+ })
106
+ CheckHint (`xy;typ::x,=test` ,
107
+ refhints .New ("" , `xy` ),
108
+ refhints.DefaultReferenceHint {
109
+ refhints .HINT_TYPE : "typ" ,
110
+ "x," : `test` ,
111
+ })
112
+ CheckHint (`"x;y";typ::x,=test` ,
113
+ refhints .New ("" , `x;y` ),
114
+ refhints.DefaultReferenceHint {
115
+ refhints .HINT_TYPE : "typ" ,
116
+ "x," : `test` ,
93
117
})
94
118
})
95
119
96
120
It ("special" , func () {
97
121
CheckHint (`typ::x;=test` ,
98
- v1 .New ("typ" , "x" ),
99
- v1 .New ("" , "=test" ),
122
+ refhints .New ("typ" , "x" ),
123
+ refhints.DefaultReferenceHint {
124
+ "" : "test" ,
125
+ },
100
126
)
101
127
})
102
128
})
129
+
130
+ Context ("implicit" , func () {
131
+ It ("regular" , func () {
132
+ CheckHintImplicit ("" , "test" , "implicit=true,reference=test" )
133
+ CheckHintImplicit ("typ" , "test" , "typ::implicit=true,reference=test" )
134
+ })
135
+ })
103
136
})
104
137
105
- func CheckHint (s string , h ... v1 .ReferenceHint ) {
106
- r := v1 .ParseHints (s )
138
+ func CheckHint (s string , h ... refhints .ReferenceHint ) {
139
+ r := refhints .ParseHints (s )
107
140
if strings .HasPrefix (s , "\" " ) && ! strings .ContainsAny (s , ",;" ) {
108
141
s = s [1 : len (s )- 1 ]
109
142
}
110
- ExpectWithOffset (1 , r ).To (Equal (v1 .ReferenceHints (h )))
143
+ ExpectWithOffset (1 , r ).To (Equal (refhints .ReferenceHints (h )))
111
144
ExpectWithOffset (1 , r .Serialize ()).To (Equal (s ))
112
145
}
146
+
147
+ func CheckHint2 (s string , ser string , h ... refhints.ReferenceHint ) {
148
+ r := refhints .ParseHints (s )
149
+ ExpectWithOffset (1 , r ).To (Equal (refhints .ReferenceHints (h )))
150
+ ExpectWithOffset (1 , r .Serialize ()).To (Equal (ser ))
151
+ }
152
+
153
+ func CheckHintImplicit (typ , ref , ser string ) {
154
+ h := refhints .New (typ , ref , true )
155
+ s := h .Serialize (true )
156
+ ExpectWithOffset (1 , h .Serialize (true )).To (Equal (ser ))
157
+ r := refhints .ParseHints (s )
158
+ ExpectWithOffset (1 , r ).To (Equal (refhints.ReferenceHints {h }))
159
+ }
0 commit comments