Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static JassExpr translate(ImNull e, ImToJassTranslator translator) {
} else if (typename.equals("boolean") || typename.equals("bool")) {
return JassExprBoolVal(false);
} else if (typename.equals("string")) {
return JassExprStringVal("");
return JassExprNull();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Collections;
import java.util.Map;

import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;

public class JurstTests extends WurstScriptTest {
Expand Down Expand Up @@ -340,6 +341,45 @@ public void testKeepTRVEHooked() throws IOException {
assertTrue(output.contains("real myVar"));
}

@Test
public void testStringNullCheckStaysNull() throws IOException {
String jassCode = Utils.string(
"globals",
" string array s__SaveCodes",
" integer PID",
" integer unitSaveID",
"endglobals",
"",
"function main takes nothing returns nothing",
" if s__SaveCodes[PID * 19 + unitSaveID] != null then",
" call BJDebugMsg(\"\")", // could be anything
" endif",
"endfunction"
);

String jurstCode = Utils.string(
"package test",
"endpackage"
);

testJurstWithJass(false, true, jassCode, jurstCode);

File out = new File("./test-output/JurstJassTest_inlopt.j");
String output = com.google.common.io.Files.toString(out, Charsets.UTF_8);

// Ensure the null check survives as a null check
assertTrue(
"Expected string null check to stay != null",
output.contains("s__SaveCodes[PID * 19 + unitSaveID] != null")
);

// And make sure we did NOT silently change it to empty string
assertFalse(
"String null check must not become != \"\"",
output.contains("s__SaveCodes[PID * 19 + unitSaveID] != \"\"")
);
}

private void testJurstWithJass(boolean executeProg, boolean withStdLib, String jass, String jurst) {
Map<String, String> inputs = ImmutableMap.of(
"example.j", jass,
Expand Down
Loading