|
31 | 31 |
|
32 | 32 | import static org.junit.Assert.assertEquals; |
33 | 33 | import static org.junit.Assert.assertFalse; |
| 34 | +import static org.junit.Assert.assertNotNull; |
| 35 | +import static org.junit.Assert.assertNull; |
34 | 36 | import static org.junit.Assert.assertSame; |
35 | 37 | import static org.junit.Assert.assertTrue; |
36 | 38 | import static org.junit.Assert.fail; |
@@ -337,6 +339,35 @@ public void testScriptDirective() { |
337 | 339 | assertEquals("bar", info.get("foo")); |
338 | 340 | } |
339 | 341 |
|
| 342 | + /** Tests the {@code language} key of the {@code #@script} directive. */ |
| 343 | + @Test |
| 344 | + public void testScriptDirectiveLanguage() { |
| 345 | + // Use a .txt extension so language is NOT auto-inferred from the path. |
| 346 | + // Confirm it starts out null (no language for .txt). |
| 347 | + final String scriptByName = "#@script(language=\"BindingSizes\")\nWOOT\n"; |
| 348 | + final ScriptInfo infoByName = |
| 349 | + new ScriptInfo(context, "test.txt", new StringReader(scriptByName)); |
| 350 | + assertNull(infoByName.getLanguage()); // no language yet |
| 351 | + infoByName.inputs(); // trigger parsing |
| 352 | + assertNotNull(infoByName.getLanguage()); |
| 353 | + assertTrue(infoByName.getLanguage().getNames().contains("BindingSizes")); |
| 354 | + |
| 355 | + // Also confirm lookup by file extension works. |
| 356 | + final String scriptByExt = "#@script(language=\"bsizes\")\nWOOT\n"; |
| 357 | + final ScriptInfo infoByExt = |
| 358 | + new ScriptInfo(context, "test.txt", new StringReader(scriptByExt)); |
| 359 | + infoByExt.inputs(); |
| 360 | + assertNotNull(infoByExt.getLanguage()); |
| 361 | + assertTrue(infoByExt.getLanguage().getExtensions().contains("bsizes")); |
| 362 | + |
| 363 | + // Unknown language name should leave language unset (null for .txt path). |
| 364 | + final String scriptBogus = "#@script(language=\"no-such-language\")\nWOOT\n"; |
| 365 | + final ScriptInfo infoBogus = |
| 366 | + new ScriptInfo(context, "test.txt", new StringReader(scriptBogus)); |
| 367 | + infoBogus.inputs(); |
| 368 | + assertNull(infoBogus.getLanguage()); |
| 369 | + } |
| 370 | + |
340 | 371 | /** |
341 | 372 | * Ensures the ScriptInfos Reader can be reused for multiple executions of the |
342 | 373 | * script. |
|
0 commit comments