echo \\\"");
// \" should not terminate a string literal
assertXrefLine(ShXref.class, "echo \"\\\"\"",
"echo \"\\\"\"");
// \` should not start a command substitution
assertXrefLine(ShXref.class, "echo \\`", "echo \\`");
// \` should not start command substitution inside a string
assertXrefLine(ShXref.class, "echo \"\\`\"",
"echo \"\\`\"");
// \` should not terminate command substitution
assertXrefLine(ShXref.class, "echo `\\``",
"echo `\\``");
// $# should not start a comment
assertXrefLine(ShXref.class, "$#", "$#");
}
/**
* Helper method that checks that the expected output is produced for a
* line with the specified xref class. Fails if the output is not as
* expected.
*
* @param xrefClass xref class to test
* @param inputLine the source code line to parse
* @param expectedOutput the expected output from the xreffer
*/
private void assertXrefLine(Class extends JFlexXref> xrefClass,
String inputLine, String expectedOutput) throws Exception {
JFlexXref xref = xrefClass.getConstructor(Reader.class).newInstance(
new StringReader(inputLine));
StringWriter output = new StringWriter();
xref.write(output);
assertEquals(FIRST_LINE_PREAMBLE + expectedOutput, output.toString());
}
/**
* Regression test case for bug #16883. Some of the state used to survive
* across invocations in ShXref, so that a syntax error in one file might
* cause broken highlighting in subsequent files. Test that the instance
* is properly reset now.
*/
@Test
public void bug16883() throws Exception {
// Analyze a script with broken syntax (unterminated string literal)
ShXref xref = new ShXref(new StringReader("echo \"xyz"));
StringWriter out = new StringWriter();
xref.write(out);
assertEquals(
FIRST_LINE_PREAMBLE +
"echo \"xyz",
out.toString());
// Reuse the xref and verify that the broken syntax in the previous
// file doesn't cause broken highlighting in the next file
out = new StringWriter();
String contents = "echo \"hello\"";
xref.reInit(contents.toCharArray(), contents.length());
xref.write(out);
assertEquals(
FIRST_LINE_PREAMBLE +
"echo \"hello\"",
out.toString());
}
/**
*
* Test the handling of #include in C and C++. In particular, these issues
* are tested:
*
*
*
*
* -
* Verify that we use breadcrumb path for both #include <x/y.h> and
* #include "x/y.h" in C and C++ (bug #17817)
*
*
* -
* Verify that the link generated for #include <vector> performs a
* path search (bug #17816)
*
*
*
*/
@Test
public void testCXrefInclude() throws Exception {
testCXrefInclude(CXref.class);
testCXrefInclude(CxxXref.class);
}
private void testCXrefInclude(Class extends JFlexXref> klass) throws Exception {
String[][] testData = {
{"#include ", "#include <abc.h>"},
{"#include ", "#include <abc/def.h>"},
{"#include \"abc.h\"", "#include \"abc.h\""},
{"#include \"abc/def.h\"", "#include \"abc/def.h\""},
{"#include ", "#include <vector>"},
};
for (String[] s : testData) {
StringReader in = new StringReader(s[0]);
StringWriter out = new StringWriter();
JFlexXref xref = klass.getConstructor(Reader.class).newInstance(in);
xref.write(out);
assertEquals(FIRST_LINE_PREAMBLE + s[1], out.toString());
}
}
/**
* Verify that ShXref handles here-documents. Bug #18198.
*/
@Test
public void testShXrefHeredoc() throws IOException {
StringReader in = new StringReader(
"cat<'some string'"));
}
/**
* Test that JavaXref handles empty Java comments. Bug #17885.
*/
@Test
public void testEmptyJavaComment() throws IOException {
StringReader in = new StringReader("/**/\nclass xyz { }\n");
JavaXref xref = new JavaXref(in);
StringWriter out = new StringWriter();
xref.write(out);
// Verify that the comment's block is terminated.
assertTrue(out.toString().contains("/**/"));
}
@Test
public void bug18586() throws IOException {
String filename = repository.getSourceRoot() + "/sql/bug18586.sql";
SQLXref xref = new SQLXref(new FileInputStream(filename));
xref.setDefs(ctags.doCtags(filename + "\n"));
// The next call used to fail with an ArrayIndexOutOfBoundsException.
xref.write(new StringWriter());
}
}