|
12 | 12 | import java.util.Collections; |
13 | 13 | import java.util.Map; |
14 | 14 |
|
| 15 | +import static org.testng.AssertJUnit.assertFalse; |
15 | 16 | import static org.testng.AssertJUnit.assertTrue; |
16 | 17 |
|
17 | 18 | public class JurstTests extends WurstScriptTest { |
@@ -340,6 +341,45 @@ public void testKeepTRVEHooked() throws IOException { |
340 | 341 | assertTrue(output.contains("real myVar")); |
341 | 342 | } |
342 | 343 |
|
| 344 | + @Test |
| 345 | + public void testStringNullCheckStaysNull() throws IOException { |
| 346 | + String jassCode = Utils.string( |
| 347 | + "globals", |
| 348 | + " string array s__SaveCodes", |
| 349 | + " integer PID", |
| 350 | + " integer unitSaveID", |
| 351 | + "endglobals", |
| 352 | + "", |
| 353 | + "function main takes nothing returns nothing", |
| 354 | + " if s__SaveCodes[PID * 19 + unitSaveID] != null then", |
| 355 | + " call BJDebugMsg(\"\")", // could be anything |
| 356 | + " endif", |
| 357 | + "endfunction" |
| 358 | + ); |
| 359 | + |
| 360 | + String jurstCode = Utils.string( |
| 361 | + "package test", |
| 362 | + "endpackage" |
| 363 | + ); |
| 364 | + |
| 365 | + testJurstWithJass(false, true, jassCode, jurstCode); |
| 366 | + |
| 367 | + File out = new File("./test-output/JurstJassTest_inlopt.j"); |
| 368 | + String output = com.google.common.io.Files.toString(out, Charsets.UTF_8); |
| 369 | + |
| 370 | + // Ensure the null check survives as a null check |
| 371 | + assertTrue( |
| 372 | + "Expected string null check to stay != null", |
| 373 | + output.contains("s__SaveCodes[PID * 19 + unitSaveID] != null") |
| 374 | + ); |
| 375 | + |
| 376 | + // And make sure we did NOT silently change it to empty string |
| 377 | + assertFalse( |
| 378 | + "String null check must not become != \"\"", |
| 379 | + output.contains("s__SaveCodes[PID * 19 + unitSaveID] != \"\"") |
| 380 | + ); |
| 381 | + } |
| 382 | + |
343 | 383 | private void testJurstWithJass(boolean executeProg, boolean withStdLib, String jass, String jurst) { |
344 | 384 | Map<String, String> inputs = ImmutableMap.of( |
345 | 385 | "example.j", jass, |
|
0 commit comments