### Question:
MacroParser { @Nullable public String parse(@Nullable String str) throws InvalidMacroException { if (str == null) { return null; } return replaceEscapedSyntax(parse(str, 0)); } MacroParser(MacroEvaluator macroEvaluator);  MacroParser(MacroEvaluator macroEvaluator, MacroParserOptions options); @Nullable String parse(@Nullable String str);  }### Answer:
@Test public void testNoEscape() { MacroEvaluator evaluator = new TestMacroEvaluator(ImmutableMap.of("\\a\\b\\c\\", "123", "x", "xyz"), ImmutableMap.of("xyz", "321")); MacroParser parser = new MacroParser(evaluator, MacroParserOptions.builder().setEscaping(false).build()); Assert.assertEquals("123", parser.parse("${\\a\\b\\c\\}")); Assert.assertEquals("321", parser.parse("${test(${x})}")); Assert.assertEquals("\\321", parser.parse("\\${test(xyz)}")); }
@Test public void testDisableLookups() { MacroEvaluator evaluator = new TestMacroEvaluator(Collections.emptyMap(), Collections.emptyMap()); MacroParser parser = new MacroParser(evaluator, MacroParserOptions.builder().disableLookups().build()); Assert.assertEquals("${key}", parser.parse("${key}")); }
@Test public void testDisableFunctions() { MacroEvaluator evaluator = new TestMacroEvaluator(Collections.emptyMap(), Collections.emptyMap()); MacroParser parser = new MacroParser(evaluator, MacroParserOptions.builder().disableFunctions().build()); Assert.assertEquals("${test(key)}", parser.parse("${test(key)}")); }
@Test public void testFunctionWhitelist() { MacroEvaluator evaluator = new TestMacroEvaluator(Collections.emptyMap(), ImmutableMap.of("key", "val")); MacroParser parser = new MacroParser(evaluator, MacroParserOptions.builder().setFunctionWhitelist("t").build()); Assert.assertEquals("${test(key)}val", parser.parse("${test(key)}${t(key)}")); Assert.assertEquals("val${test(key)}", parser.parse("${t(key)}${test(key)}")); Assert.assertEquals("${test(val)}", parser.parse("${test(${t(key)})}")); }
@Test public void testSkipInvalidMacros() { MacroEvaluator evaluator = new TestMacroEvaluator(Collections.emptyMap(), Collections.emptyMap()); MacroParser parser = new MacroParser(evaluator, MacroParserOptions.builder().skipInvalidMacros().build()); Assert.assertEquals("${k1}", parser.parse("${k1}")); Assert.assertEquals("${test(key)}", parser.parse("${test(key)}")); Assert.assertEquals("abc${123}", parser.parse("abc${123}")); }