Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 444 lines (378 sloc) 11.697 kb
dffedf5f » mguillem
2007-02-01 GROOVY-1690
1 package groovy
2
9cd140ba » jstrachan
2004-01-16 Added support for the creation of non-primitive type arrays
3 class ArrayTest extends GroovyTestCase {
4
5 void testFixedSize() {
b25c8875 » blackdrag
2005-04-14 a first try to implement some simple scope checks and some modified t…
6 def array = new String[10]
9cd140ba » jstrachan
2004-01-16 Added support for the creation of non-primitive type arrays
7 assert array.size() == 10
8 array[0] = "Hello"
9 assert array[0] == "Hello"
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
10 }
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
11
9cd140ba » jstrachan
2004-01-16 Added support for the creation of non-primitive type arrays
12 void testArrayWithInitializer() {
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
13 String[] array = ["nice", "cheese", "gromit"]
9cd140ba » jstrachan
2004-01-16 Added support for the creation of non-primitive type arrays
14 assert array.size() == 3
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
15 assert array[0] == "nice", array.inspect()
9cd140ba » jstrachan
2004-01-16 Added support for the creation of non-primitive type arrays
16 assert array[1] == "cheese"
17 assert array[2] == "gromit"
18 }
19
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
20 void testCharArrayCreate() {
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
21 def array = new char[3]
22 assert array.size() == 3
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
23 }
24
09df618b » jimwhite
2008-11-23 GROOVY-3165: Test case and interim fix.
25 void testCharArrayAssignToElement() {
26 char[] ca = new char[1]
27
28 // Assignments statements.
29 ca[0] = 'b' as char
30 assert ca[0] == 'b'
31
32 ca[0] = '\u00A1' as char
33 assert ca[0] == '\u00A1'
34
35 ca[0] = 'a'
36 assert ca[0] == 'a'
37
38 ca[0] = '\u00A0'
39 assert ca[0] == '\u00A0'
40
41 def foo = 'z'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
42
09df618b » jimwhite
2008-11-23 GROOVY-3165: Test case and interim fix.
43 ca[0] = "$foo"
44 assert ca[0] == 'z'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
45
09df618b » jimwhite
2008-11-23 GROOVY-3165: Test case and interim fix.
46 // Assignment in value context.
47 assert (ca[0] = 'b' as char) == 'b'
48 assert ca[0] == 'b'
49
50 assert (ca[0] = '\u00A1' as char) == '\u00A1'
51 assert ca[0] == '\u00A1'
52
53 assert (ca[0] = 'a') == 'a'
54 assert ca[0] == 'a'
55
56 assert (ca[0] = '\u00A0') == '\u00A0'
57 assert ca[0] == '\u00A0'
58
59 assert (ca[0] = "$foo") == 'z'
60 assert ca[0] == 'z'
61 }
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
62
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
63 void testCharArrayWithInitializer() {
09df618b » jimwhite
2008-11-23 GROOVY-3165: Test case and interim fix.
64 def bar = 'c'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
65 char[] array = ['a', 'b', "$bar"]
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
66 assert array.size() == 3
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
67 assert array[0] == 'a', array.inspect()
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
68 assert array[1] == 'b'
69 assert array[2] == 'c'
70 }
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
71
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
72 void testByteArrayCreate() {
b25c8875 » blackdrag
2005-04-14 a first try to implement some simple scope checks and some modified t…
73 def array = new byte[100]
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
74 assert array.size() == 100;
75 }
76
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
77 void testByteArrayWithInitializer() {
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
78 byte[] array = [0, 1, 2, 3]
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
79 assert array.size() == 4
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
80 assert array[0] == 0, array.inspect()
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
81 assert array[1] == 1
82 assert array[2] == 2
83 assert array[3] == 3
84 }
85
86 void testByteArrayWithInitializerAndAssignmentOfNumber() {
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
87 byte[] array = [2, 4]
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
88 assert array.size() == 2
89 assert array[0] == 2
90 assert array[1] == 4
91
92 array[0] = 76
93 array[1] = 32
94 assert array[0] == 76
95 assert array[1] == 32
96
97 array.putAt(0, 45)
98 array.putAt(1, 67)
99 assert array[0] == 45
100 assert array[1] == 67
101 }
102
493cdd72 » paulk-asert
2008-03-16 GROOVY-644: New Groovy JDK methods - to improve consistency (eachByte…
103 void testEachByteForByteArray() {
104 byte[] array1 = [2, 4]
105 def sum = 0
106 array1.eachByte { sum += it }
107 assert sum == 6
108 Byte[] array2 = [2, 4]
109 def result = 1
110 array2.eachByte { result *= it }
111 assert result == 8
112 }
113
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
114 void testDoubleArrayCreate() {
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
115 def array = new double[3]
116 assert array.size() == 3
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
117 }
118
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
119 void testDoubleArrayWithInitializer() {
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
120 double[] array = [1.3, 3.14, 2.7]
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
121 assert array.size() == 3
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
122 assert array[0] == 1.3, array.inspect()
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
123 assert array[1] == 3.14
124 assert array[2] == 2.7
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
125 }
126
9cd140ba » jstrachan
2004-01-16 Added support for the creation of non-primitive type arrays
127 void testIntArrayCreate() {
b25c8875 » blackdrag
2005-04-14 a first try to implement some simple scope checks and some modified t…
128 def array = new int[5]
9cd140ba » jstrachan
2004-01-16 Added support for the creation of non-primitive type arrays
129 assert array.size() == 5
130 }
85c4c250 » jstrachan
2004-03-07 applied Chris's changes to the parser for triple quoted strings and t…
131
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
132 void testIntArrayWithInitializer() {
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
133 int[] array = [42, -5, 360]
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
134 assert array.size() == 3
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
135 assert array[0] == 42, array.inspect()
35345b49 » jstrachan
2004-05-12 Applied patch from Arjun Nayyar for GROOVY-119
136 assert array[1] == -5
137 assert array[2] == 360
138 }
1d7ebd67 » jstrachan
2005-03-02 updated the test cases to use JSR parser syntax
139
85c4c250 » jstrachan
2004-03-07 applied Chris's changes to the parser for triple quoted strings and t…
140 void testArrayDeclaration() {
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
141 String[] array = ["a", "b", "c"]
e4c3e74b » paulk-asert
2008-01-22 GROOVY-2527: Unexpected Array conversion on variable assignment
142 assert array.class == String[].class
85c4c250 » jstrachan
2004-03-07 applied Chris's changes to the parser for triple quoted strings and t…
143 assert array.size() == 3
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
144 assert array[0] == "a"
145 assert array[1] == "b"
146 assert array[2] == "c"
85c4c250 » jstrachan
2004-03-07 applied Chris's changes to the parser for triple quoted strings and t…
147 }
148
e4c3e74b » paulk-asert
2008-01-22 GROOVY-2527: Unexpected Array conversion on variable assignment
149 void testArrayAssignmentShouldHonorInheritance() {
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
150 String[] array = ["a", "b", "c"]
e4c3e74b » paulk-asert
2008-01-22 GROOVY-2527: Unexpected Array conversion on variable assignment
151 Object[] other = array
152 assert other.class == String[].class
153 assert other.hashCode() == array.hashCode()
154 }
155
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
156 void testSimpleArrayEquals() {
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
157 Integer[] arr1 = [1, 2, 3, 4]
158 Integer[] arr2 = [1, 2, 3, 4]
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
159 assert arr1 == arr2
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
160 int[] primarr1 = [1, 2, 3, 4]
161 int[] primarr2 = [1, 2, 3, 4]
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
162 assert primarr1 == primarr2
163 assert primarr1 == arr2
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
164 double[] primarr3 = [1, 2, 3, 4]
165 long[] primarr4 = [1, 2, 3, 4]
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
166 assert primarr3 == primarr4
167 assert primarr3 == primarr1
168 assert primarr2 == primarr4
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
169 def list1 = [1, 2, 3, 4]
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
170 assert list1 == arr1
171 assert arr1 == list1
172 assert list1 == primarr1
173 assert primarr1 == list1
26af9a8c » paulk-asert
2007-10-09 GROOVY-1549: Array equality is not treated same as List equality
174 boolean[] bools1 = [true, true, false]
175 boolean[] bools2 = [true, true, false]
176 assert bools1 == bools2
177 assert bools1 == [true, true, false] as boolean[]
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
178 }
85c4c250 » jstrachan
2004-03-07 applied Chris's changes to the parser for triple quoted strings and t…
179
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
180 void testComplexArrayEquals() {
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
181 def a = [1, 2] as Integer[]
182 def b = [1, 2]
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
183 assert a == b
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
184 assert [[1, 2], [3, 4]] == [[1, 2], [3, 4]]
185 def x = [[1, 2] as Integer[]]
186 Object[] y = [[1, 2]]
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
187 assert y == x
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
188 assert [[1, 2], [3, 4]] as int[][] == [[1, 2], [3, 4]] as int[][]
189 assert [[[5, 6], [7, 8]]] as int[][][] == [[[5, 6], [7, 8]]] as Long[][][]
190 assert [[1, 2], [3, 4]] as long[][] == [[1, 2], [3, 4]] as long[][]
191 assert [[1, 2], [3, 4]] as long[][] == [[1, 2], [3, 4]] as Long[][]
192 assert [[1, 2], [3, 4]] as long[][] == [[1, 2], [3, 4]]
193 assert [[1, 2], [3, 4]] as long[][] == [[1, 2] as short[], [3, 4] as short[]]
194 int[][] intsA = [[1, 2], [3, 4]]
195 assert intsA == [[1, 2], [3, 4]] as int[][]
196 int[][] intsB = [[1, 2], [3, 4]]
26af9a8c » paulk-asert
2007-10-09 GROOVY-1549: Array equality is not treated same as List equality
197 assert intsA == intsB
198 boolean[][] boolsA = [[true, true], [false, true], [false]]
199 boolean[][] boolsB = [[true, true], [false, true], [false]]
200 assert boolsA == boolsB
85c4c250 » jstrachan
2004-03-07 applied Chris's changes to the parser for triple quoted strings and t…
201 }
59604972 » paulk-asert
2007-02-24 Initial fix for GROOVY-1549: handles e.g. Integer[] and int[] but not…
202
8df43bd3 » roshandawrani
2008-12-05 GROOVY-3167
203 void testNumberWrapperArrayAssignToElement() {
204 Byte[] bytes = [1, 2]
205 bytes[0] = (byte) 20
206 bytes[1] = 50
207 assertEquals 20, bytes[0]
208 assertEquals 50, bytes[1]
209
210 Short[] shorts = [1, 2]
211 shorts[1] = 50
212 assertEquals 50, shorts[1]
213
214 Float[] floats = [1.0f, 2.0f]
215 floats[1] = 50.0d
216 assertEquals 50.0d, floats[1]
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
217
8df43bd3 » roshandawrani
2008-12-05 GROOVY-3167
218 Double[] doubles = [1.0d, 2.0d]
219 doubles[0] = new BigDecimal(100)
220 doubles[1] = 50
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
221
8df43bd3 » roshandawrani
2008-12-05 GROOVY-3167
222 assertEquals 100, doubles[0]
223 assertEquals 50, doubles[1]
224 }
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
225
7e3a29d0 » roshandawrani
2008-12-20 GROOVY-3173
226 void testCharacterArrayElementAssignments() {
227 Character[] ca = new Character[1]
228
229 // Assignments statements.
230 ca[0] = 'b' as char
231 assert ca[0] == 'b'
232
233 ca[0] = '\u00A1' as char
234 assert ca[0] == '\u00A1'
235
236 ca[0] = 'a'
237 assert ca[0] == 'a'
238
239 ca[0] = '\u00A0'
240 assert ca[0] == '\u00A0'
241
242 def foo = 'z'
243
244 ca[0] = "$foo"
245 assert ca[0] == 'z'
246 }
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
247
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
248 void testAssignmentOfSingleCharStringToNumberArrays() {
249 def x = 'x'
250 def gx = "$x"
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
251
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
252 Short[] sa = new Short[1]
253 sa[0] = 'c' as char
254 assert sa[0] == 99
255 sa[0] = 'd'
256 assert sa[0] == 100
257 sa[0] = gx
258 assert sa[0] == 120
259 shouldFail {
260 sa[0] = 'zz'
261 }
262
263 Integer[] ca = new Integer[1]
264 ca[0] = 'c' as char
265 assert ca[0] == 99
266 ca[0] = 'd'
267 assert ca[0] == 100
268 ca[0] = gx
269 assert ca[0] == 120
270 shouldFail {
271 ca[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
272 }
273
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
274 Long[] la = new Long[1]
275 la[0] = 'c' as char
276 assert la[0] == 99
277 la[0] = 'd'
278 assert la[0] == 100
279 la[0] = gx
280 assert la[0] == 120
281 shouldFail {
282 la[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
283 }
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
284
285 Float[] fa = new Float[1]
286 fa[0] = 'c' as char
287 assert fa[0] == 99.0f
288 fa[0] = 'd'
289 assert fa[0] == 100.0f
290 fa[0] = gx
291 assert fa[0] == 120.0f
292 shouldFail {
293 fa[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
294 }
295
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
296 Double[] da = new Double[1]
297 da[0] = 'c' as char
298 assert da[0] == 99.0d
299 da[0] = 'd'
300 assert da[0] == 100.0d
301 da[0] = gx
302 assert da[0] == 120.0d
303 shouldFail {
304 da[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
305 }
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
306
307 BigInteger[] bia = new BigInteger[1]
308 bia[0] = 'c' as char
309 assert bia[0] == new BigInteger("99")
310 bia[0] = 'd'
311 assert bia[0] == new BigInteger("100")
312 bia[0] = gx
313 assert bia[0] == new BigInteger("120")
314 shouldFail {
315 bia[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
316 }
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
317
318 BigDecimal[] bda = new BigDecimal[1]
319 bda[0] = 'c' as char
320 assert bda[0] == new BigDecimal("99")
321 bda[0] = 'd'
322 assert bda[0] == new BigDecimal("100")
323 bda[0] = gx
324 assert bda[0] == new BigDecimal("120")
325 shouldFail {
326 bda[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
327 }
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
328
329 short[] sap = new short[1]
330 sap[0] = 'c' as char
331 assert sap[0] == 99
332 sap[0] = 'd'
333 assert sap[0] == 100
334 sap[0] = gx
335 assert sap[0] == 120
336 shouldFail {
337 sap[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
338 }
339
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
340 int[] iap = new int[1]
341 iap[0] = 'c' as char
342 assert iap[0] == 99
343 iap[0] = 'd'
344 assert iap[0] == 100
345 iap[0] = gx
346 assert iap[0] == 120
347 shouldFail {
348 iap[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
349 }
350
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
351 long[] lap = new long[1]
352 lap[0] = 'c' as char
353 assert lap[0] == 99
354 lap[0] = 'd'
355 assert lap[0] == 100
356 lap[0] = gx
357 assert lap[0] == 120
358 shouldFail {
359 lap[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
360 }
361
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
362 float[] fap = new float[1]
363 fap[0] = 'c' as char
364 assert fap[0] == 99.0f
365 fap[0] = 'd'
366 assert fap[0] == 100.0f
367 fap[0] = gx
368 assert fap[0] == 120.0f
369 shouldFail {
370 fap[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
371 }
372
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
373 double[] dap = new double[1]
374 dap[0] = 'c' as char
375 assert dap[0] == 99.0d
376 dap[0] = 'd'
377 assert dap[0] == 100.0d
378 dap[0] = gx
379 assert dap[0] == 120.0d
380 shouldFail {
381 dap[0] = 'zz'
220e824c » paulk-asert
2008-12-27 GROOVY-2904: [ [a:1, b:2, c:3] ].flatten() -> [ 1, 2, 3 ], but should…
382 }
383 }
384
385 void testFlattenArray() {
386 def orig = "onetwo".toList().toArray()
387 def flat = orig.flatten()
388 assert flat == ["o", "n", "e", "t", "w", "o"]
389 }
390
391 void testFlattenArrayOfLists() {
392 def orig = ["one".toList(), "two".toList()] as Object[]
393 def flat = orig.flatten()
394 assert flat == ["o", "n", "e", "t", "w", "o"]
395 }
396
397 void testFlattenArrayOfArrays() {
398 def orig = ["one".toList().toArray(), "two".toList().toArray()] as Object[]
399 def flat = orig.flatten()
400 assert flat == ["o", "n", "e", "t", "w", "o"]
401 }
402
403 void testFlattenPrimitiveArray() {
404 def orig = [1, 2, 3] as int[]
405 def flat = orig.flatten()
406 assert flat == [1, 2, 3]
407 }
408
409 void testFlattenArrayOfPrimitiveArrays() {
410 def orig = [[1, 2, 3] as int[], [4, 5, 6] as int[]] as int[][]
411 def flat = orig.flatten()
412 assert flat == [1, 2, 3, 4, 5, 6]
4f28fa9a » roshandawrani
2008-12-21 GROOVY-3173
413 }
0a7d04a1 » timyates
2012-04-10 Added functionality and tests
414
415 void testGroovy5402ArrayPlus() {
416 Integer[] a = [ 1, 2, 3 ]
417 Integer[] b = [ 3, 4, 5 ]
418 def result = a + b
419 assert result == [ 1, 2, 3, 3, 4, 5 ]
420 assert result.class.isArray()
7f883f10 » paulk-asert
2012-04-11 GROOVY-5402: Provide a DGM plus() method for arrays
421 // check the originals are untouched
422 assert a == [ 1, 2, 3 ]
423 assert b == [ 3, 4, 5 ]
0a7d04a1 » timyates
2012-04-10 Added functionality and tests
424
425 result = a + 4
426 assert result == [ 1, 2, 3, 4 ]
427 assert result.class.isArray()
428
429 result = a + [ 4, 5 ]
430 assert result == [ 1, 2, 3, 4, 5 ]
431 assert result.class.isArray()
432 }
15a22fec » blackdrag
2012-08-29 GROOVY-5662: (primopts) add type transformation for mixed type binary…
433
434 void doSomething(long[] values){
435 values[1] += 5
436 }
437
438 void testLongArrayIncrement() {
439 long[] l = [1l,0l]
440 doSomething(l)
441 assert l[0]==1
442 assert l[1]==5
443 }
85c4c250 » jstrachan
2004-03-07 applied Chris's changes to the parser for triple quoted strings and t…
444 }
Something went wrong with that request. Please try again.