01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.jjs.test;
17:
18: import com.google.gwt.junit.client.GWTTestCase;
19:
20: import java.util.Arrays;
21: import java.util.List;
22: import java.util.ArrayList;
23:
24: /**
25: * Tests the new JDK 1.5 enhanced for loop.
26: */
27: public class EnhancedForLoopTest extends GWTTestCase {
28:
29: public String getModuleName() {
30: return "com.google.gwt.dev.jjs.CompilerSuite";
31: }
32:
33: public void testArray() {
34: String[] items = new String[] { "1", "2", "3", "4", "5" };
35: List<String> out = new ArrayList<String>();
36: for (String i : items) {
37: out.add(i);
38: }
39: assertTrue(out.equals(Arrays.asList(items)));
40: }
41:
42: public void testBoxing() {
43: List<Integer> items = Arrays.asList(1, 2, 3, 4, 5);
44: List<Integer> out = new ArrayList<Integer>();
45: for (int i : items) {
46: out.add(i);
47: }
48: assertTrue(out.equals(items));
49:
50: int[] unboxedItems = new int[] { 1, 2, 3, 4, 5 };
51: out.clear();
52:
53: for (Integer i : unboxedItems) {
54: out.add(i);
55: }
56:
57: for (int i = 0; i < 5; ++i) {
58: assertTrue(out.get(i).intValue() == unboxedItems[i]);
59: }
60: }
61:
62: public void testIterable() {
63: Iterable<Integer> it = Arrays.asList(1, 2, 3, 4, 5);
64: List<Integer> out = new ArrayList<Integer>();
65: for (Integer i : it) {
66: out.add(i);
67: }
68: assertTrue(it.equals(out));
69: }
70:
71: public void testList() {
72: List<String> items = Arrays.asList("1", "2", "3", "4", "5");
73: List<String> out = new ArrayList<String>();
74: for (String i : items) {
75: out.add(i);
76: }
77: assertTrue(out.equals(items));
78: }
79: }
|