}
// Map the tokens from the generated source back to the
// input source and ensure that the map is correct.
for (Token token : resultTokens.values()) {
OriginalMapping mapping = reader.getMappingForLine(
token.position.getLine() + 1,
token.position.getColumn() + 1);
assertNotNull(mapping);
// Find the associated token in the input source.
Token inputToken = originalTokens.get(token.tokenName);
assertNotNull(inputToken);
assertEquals(mapping.getOriginalFile(), inputToken.inputName);
// Ensure that the map correctly points to the token (we add 1
// to normalize versus the Rhino line number indexing scheme).
assertEquals(mapping.getLineNumber(),
inputToken.position.getLine() + 1);
int start = inputToken.position.getColumn() + 1;
if (inputToken.tokenName.startsWith("STR")) {
// include the preceding quote.
start--;
}
if (validateColumns) {
assertEquals(start, mapping.getColumnPosition());
}
// Ensure that if the token name does not being with an 'STR' (meaning a
// string) it has an original name.
if (!inputToken.tokenName.startsWith("STR")) {
assertFalse("missing name for " + inputToken.tokenName, mapping.getIdentifier().isEmpty());
}
// Ensure that if the mapping has a name, it matches the token.
if (!mapping.getIdentifier().isEmpty()) {
assertEquals(mapping.getIdentifier(),
"__" + inputToken.tokenName + "__");
}
}
}