|
21 | 21 | * questions. |
22 | 22 | */ |
23 | 23 |
|
| 24 | +import static jdk.internal.util.OperatingSystem.WINDOWS; |
24 | 25 | import static jdk.jpackage.test.HelloApp.configureAndExecute; |
25 | 26 |
|
26 | 27 | import java.io.IOException; |
27 | 28 | import java.nio.file.Files; |
28 | 29 | import java.nio.file.Path; |
| 30 | +import java.util.ArrayList; |
29 | 31 | import java.util.Collection; |
30 | | -import java.util.HashMap; |
| 32 | +import java.util.LinkedHashMap; |
| 33 | +import java.util.List; |
31 | 34 | import java.util.Map; |
32 | 35 | import java.util.Objects; |
33 | 36 | import java.util.Optional; |
@@ -79,7 +82,7 @@ TestSpec create() { |
79 | 82 |
|
80 | 83 | private String str; |
81 | 84 | private String expectedStr; |
82 | | - private Map<String, String> env = new HashMap<>(); |
| 85 | + private Map<String, String> env = new LinkedHashMap<>(); |
83 | 86 | } |
84 | 87 |
|
85 | 88 | public TestSpec { |
@@ -115,6 +118,8 @@ public String toString() { |
115 | 118 |
|
116 | 119 | @Test |
117 | 120 | @ParameterSupplier |
| 121 | + @ParameterSupplier(value = "testCaseSensitive", ifNotOS = WINDOWS) |
| 122 | + @ParameterSupplier(value = "testCaseInsensitive", ifOS = WINDOWS) |
118 | 123 | public static void test(TestSpec spec) throws IOException { |
119 | 124 | final var cmd = JPackageCommand.helloAppImage(TEST_APP_JAVA + "*Hello") |
120 | 125 | .ignoreFakeRuntime() |
@@ -161,6 +166,84 @@ public static Collection<Object[]> test() { |
161 | 166 | }).toList(); |
162 | 167 | } |
163 | 168 |
|
| 169 | + public static Collection<Object[]> testCaseSensitive() { |
| 170 | + final List<TestSpec> testCases = new ArrayList<>(); |
| 171 | + for (final var token : PredefinedToken.values()) { |
| 172 | + testCases.addAll(token.createTestCases(true)); |
| 173 | + } |
| 174 | + |
| 175 | + testCases.addAll(Stream.of( |
| 176 | + testSpec("$ALPHA $alpha").expect("A a").var("ALPHA", "A").var("alpha", "a"), |
| 177 | + testSpec("$ALPHA $alpha").expect("$ALPHA a").var("alpha", "a"), |
| 178 | + testSpec("$ALPHA $alpha").expect("A $alpha").var("ALPHA", "A") |
| 179 | + ).map(TestSpec.Builder::create).toList()); |
| 180 | + |
| 181 | + return testCases.stream().map(v -> { |
| 182 | + return new Object[] {v}; |
| 183 | + }).toList(); |
| 184 | + } |
| 185 | + |
| 186 | + public static Collection<Object[]> testCaseInsensitive() { |
| 187 | + final List<TestSpec> testCases = new ArrayList<>(); |
| 188 | + for (final var token : PredefinedToken.values()) { |
| 189 | + testCases.addAll(token.createTestCases(false)); |
| 190 | + } |
| 191 | + |
| 192 | + testCases.addAll(Stream.of( |
| 193 | + testSpec("$ALPHA $alpha").expect("A A").var("AlphA", "A"), |
| 194 | + testSpec("$ALPHA $alpha").expect("a a").var("alpha", "a"), |
| 195 | + testSpec("$ALPHA $alpha").expect("A A").var("ALPHA", "A") |
| 196 | + ).map(TestSpec.Builder::create).toList()); |
| 197 | + |
| 198 | + return testCases.stream().map(v -> { |
| 199 | + return new Object[] {v}; |
| 200 | + }).toList(); |
| 201 | + } |
| 202 | + |
| 203 | + private enum PredefinedToken { |
| 204 | + APPDIR, |
| 205 | + BINDIR, |
| 206 | + ROOTDIR; |
| 207 | + |
| 208 | + List<TestSpec> createTestCases(boolean caseSensitive) { |
| 209 | + final var name = name(); |
| 210 | + final var name2 = name.transform(str -> { |
| 211 | + final var chars = name.toCharArray(); |
| 212 | + for (int i = 0; i < chars.length; i += 2) { |
| 213 | + chars[i] = Character.toLowerCase(chars[i]); |
| 214 | + } |
| 215 | + return new String(chars); |
| 216 | + }); |
| 217 | + |
| 218 | + if (name.equals(name2)) { |
| 219 | + throw new UnsupportedOperationException(); |
| 220 | + } |
| 221 | + |
| 222 | + final var testSpec = testSpec(String.format("${%s}${%s}", name, name2)).var(name, "A").var(name2, "[foo]"); |
| 223 | + if (caseSensitive) { |
| 224 | + testSpec.expect(String.format("@@%s@@[foo]", name, name2)); |
| 225 | + } else { |
| 226 | + testSpec.expect(String.format("@@%s@@@@%s@@", name, name)); |
| 227 | + } |
| 228 | + |
| 229 | + final var testSpec2 = testSpec(String.format("${%s}${%s}", name, name2)).var(name, "A"); |
| 230 | + if (caseSensitive) { |
| 231 | + testSpec2.expect(String.format("@@%s@@${%s}", name, name2)); |
| 232 | + } else { |
| 233 | + testSpec2.expect(String.format("@@%s@@@@%s@@", name, name)); |
| 234 | + } |
| 235 | + |
| 236 | + final var testSpec3 = testSpec(String.format("${%s}${%s}", name, name2)); |
| 237 | + if (caseSensitive) { |
| 238 | + testSpec3.expect(String.format("@@%s@@${%s}", name, name2)); |
| 239 | + } else { |
| 240 | + testSpec3.expect(String.format("@@%s@@@@%s@@", name, name)); |
| 241 | + } |
| 242 | + |
| 243 | + return Stream.of(testSpec, testSpec2).map(TestSpec.Builder::create).toList(); |
| 244 | + } |
| 245 | + } |
| 246 | + |
164 | 247 | private static TestSpec.Builder testSpec(String str) { |
165 | 248 | return new TestSpec.Builder().str(str); |
166 | 249 | } |
|
0 commit comments