}
private void assertContextualRewriting(String expectedOutput, String... inputs)
throws SoyAutoescapeException {
SoyFileSetNode soyTree = SharedTestUtils.parseSoyFiles(inputs);
new CheckEscapingSanityVisitor().exec(soyTree);
String source = rewrittenSource(soyTree);
assertEquals(expectedOutput, source.trim());
// Make sure that the transformation is idempotent.
if (!source.contains("__C")) { // Skip if there are extern extra templates.
assertEquals(expectedOutput, rewrittenSource(soyTree).trim());
}
// And idempotent from a normalized input if the templates are not autoescape="contextual".
String input = join(inputs);
String inputWithoutAutoescape = input
.replaceAll("\\s+autoescape\\s*=\\s*\"(contextual|strict)\"", "")
.replaceAll("\\s+kind\\s*=\\s*\"([a-z]*)\"", "");
SoyFileSetNode soyTree2 = SharedTestUtils.parseSoyFiles(inputWithoutAutoescape);
String original = soyTree2.getChild(0).toSourceString();
assertEquals(original, rewrittenSource(soyTree2));
}