Debian Codegraph @

test_suite/slice.sugar.jsonnet.fmt.golden

raw
1 /*
2 Copyright 2015 Google Inc. All rights reserved.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 local arr = std.range(0, 5);
18 local str = '012345';
19 local a = 2;
20 local b = 4;
21
22 local arrCases = [
23 {
24 input: arr[2:4],
25 output: [2, 3],
26 },
27 {
28 input: arr[2:4:1],
29 output: [2, 3],
30 },
31 {
32 input: arr[:4],
33 output: [0, 1, 2, 3],
34 },
35 {
36 input: arr[2:],
37 output: [2, 3, 4, 5],
38 },
39 {
40 input: arr[:],
41 output: arr,
42 },
43 {
44 input: arr[:1000],
45 output: arr,
46 },
47 {
48 input: arr[:],
49 output: arr,
50 },
51 {
52 input: arr[1:],
53 output: [1, 2, 3, 4, 5],
54 },
55 {
56 input: arr[(1):],
57 output: [1, 2, 3, 4, 5],
58 },
59 {
60 input: arr[1::2],
61 output: [1, 3, 5],
62 },
63 {
64 input: arr[(1)::2],
65 output: [1, 3, 5],
66 },
67 {
68 input: arr[::2],
69 output: [0, 2, 4],
70 },
71 {
72 input: arr[:0],
73 output: [],
74 },
75 {
76 input: arr[:(0)],
77 output: [],
78 },
79 {
80 input: arr[a:b],
81 output: [2, 3],
82 },
83 {
84 input: arr[a:b + 1],
85 output: [2, 3, 4],
86 },
87 {
88 input: arr[2:1000],
89 output: [2, 3, 4, 5],
90 },
91 {
92 input: (arr)[2:1000],
93 output: [2, 3, 4, 5],
94 },
95 {
96 input: arr[-2:],
97 output: [4, 5],
98 },
99 {
100 input: arr[:-3],
101 output: [0, 1, 2],
102 },
103 {
104 input: arr[-3:-1],
105 output: [3, 4],
106 },
107 {
108 input: arr[-1:-1],
109 output: [],
110 },
111 {
112 input: arr[-6:3],
113 output: [0, 1, 2],
114 },
115 {
116 input: arr[-100:3],
117 output: [0, 1, 2],
118 },
119 {
120 input: arr[-100:-90],
121 output: [],
122 },
123 ];
124
125 local strCases = [
126 {
127 input: str[2:4],
128 output: '23',
129 },
130 {
131 input: str[2:4:1],
132 output: '23',
133 },
134 {
135 input: str[:4],
136 output: '0123',
137 },
138 {
139 input: str[2:],
140 output: '2345',
141 },
142 {
143 input: str[:],
144 output: str,
145 },
146 {
147 input: str[:1000],
148 output: str,
149 },
150 {
151 input: str[:],
152 output: str,
153 },
154 {
155 input: str[1:],
156 output: '12345',
157 },
158 {
159 input: str[(1):],
160 output: '12345',
161 },
162 {
163 input: str[1::2],
164 output: '135',
165 },
166 {
167 input: str[(1)::2],
168 output: '135',
169 },
170 {
171 input: str[::2],
172 output: '024',
173 },
174 {
175 input: str[:0],
176 output: '',
177 },
178 {
179 input: str[:(0)],
180 output: '',
181 },
182 {
183 input: str[a:b],
184 output: '23',
185 },
186 {
187 input: str[a:b + 1],
188 output: '234',
189 },
190 {
191 input: str[2:1000],
192 output: '2345',
193 },
194 {
195 input: (str)[2:1000],
196 output: '2345',
197 },
198 {
199 input: str[-2:],
200 output: '45',
201 },
202 {
203 input: str[:-3],
204 output: '012',
205 },
206 {
207 input: str[-3:-1],
208 output: '34',
209 },
210 {
211 input: str[-1:-1],
212 output: '',
213 },
214 {
215 input: str[-6:3],
216 output: '012',
217 },
218 {
219 input: str[-100:3],
220 output: '012',
221 },
222 {
223 input: str[-100:-90],
224 output: '',
225 },
226 ];
227
228 std.foldl(
229 function(bool, case)
230 bool && std.assertEqual(case.input, case.output),
231 arrCases + strCases,
232 true,
233 )