Search in sources :

Example 1 with ShXref

use of org.opensolaris.opengrok.analysis.sh.ShXref in project OpenGrok by OpenGrok.

the class JFlexXrefTest method testBug15890LineCount.

/**
     * Regression test case for bug #15890. Check that we get the expected the
     * expected line count from input with some special characters that used
     * to cause trouble.
     */
@Test
public void testBug15890LineCount() throws Exception {
    String fileContents = "line 1\n" + "line 2\n" + "line 3\n" + "line 4 with  char\n" + "line 5 with  char\n" + "line 6 with … char\n" + "line 7 with 
 char\n" + "line 8 with 
 char\n" + "line 9\n";
    bug15890LineCount(new CXref(new StringReader(fileContents)));
    bug15890LineCount(new CxxXref(new StringReader(fileContents)));
    bug15890LineCount(new LispXref(new StringReader(fileContents)));
    bug15890LineCount(new JavaXref(new StringReader(fileContents)));
    bug15890LineCount(new ScalaXref(new StringReader(fileContents)));
    bug15890LineCount(new FortranXref(new StringReader(fileContents)));
    bug15890LineCount(new HaskellXref(new StringReader(fileContents)));
    bug15890LineCount(new XMLXref(new StringReader(fileContents)));
    bug15890LineCount(new ShXref(new StringReader(fileContents)));
    bug15890LineCount(new TclXref(new StringReader(fileContents)));
    bug15890LineCount(new SQLXref(new StringReader(fileContents)));
    bug15890LineCount(new TroffXref(new StringReader(fileContents)));
    bug15890LineCount(new PlainXref(new StringReader(fileContents)));
    bug15890LineCount(new PerlXref(new StringReader(fileContents)));
}
Also used : CXref(org.opensolaris.opengrok.analysis.c.CXref) PlainXref(org.opensolaris.opengrok.analysis.plain.PlainXref) FortranXref(org.opensolaris.opengrok.analysis.fortran.FortranXref) LispXref(org.opensolaris.opengrok.analysis.lisp.LispXref) ScalaXref(org.opensolaris.opengrok.analysis.scala.ScalaXref) TclXref(org.opensolaris.opengrok.analysis.tcl.TclXref) TroffXref(org.opensolaris.opengrok.analysis.document.TroffXref) XMLXref(org.opensolaris.opengrok.analysis.plain.XMLXref) HaskellXref(org.opensolaris.opengrok.analysis.haskell.HaskellXref) JavaXref(org.opensolaris.opengrok.analysis.java.JavaXref) CxxXref(org.opensolaris.opengrok.analysis.c.CxxXref) ShXref(org.opensolaris.opengrok.analysis.sh.ShXref) StringReader(java.io.StringReader) PerlXref(org.opensolaris.opengrok.analysis.perl.PerlXref) SQLXref(org.opensolaris.opengrok.analysis.sql.SQLXref) Test(org.junit.Test)

Example 2 with ShXref

use of org.opensolaris.opengrok.analysis.sh.ShXref in project OpenGrok by OpenGrok.

the class JFlexXrefTest method unterminatedHeredoc.

/**
     * Test that unterminated heredocs don't cause infinite loop in ShXref.
     * This originally became a problem after upgrade to JFlex 1.5.0.
     */
@Test
public void unterminatedHeredoc() throws IOException {
    ShXref xref = new ShXref(new StringReader("cat << EOF\nunterminated heredoc"));
    StringWriter out = new StringWriter();
    // The next call used to loop forever.
    xref.write(out);
    assertEquals("<a class=\"l\" name=\"1\" href=\"#1\">1</a>" + "<a href=\"/source/s?defs=cat\" class=\"intelliWindow-symbol\" data-definition-place=\"undefined-in-file\">cat</a> &lt;&lt; EOF" + "<span class=\"s\">\n" + "<a class=\"l\" name=\"2\" href=\"#2\">2</a>" + "unterminated heredoc</span>", out.toString());
}
Also used : StringWriter(java.io.StringWriter) ShXref(org.opensolaris.opengrok.analysis.sh.ShXref) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 3 with ShXref

use of org.opensolaris.opengrok.analysis.sh.ShXref in project OpenGrok by OpenGrok.

the class JFlexXrefTest method testShXrefHeredoc.

/**
     * Verify that ShXref handles here-documents. Bug #18198.
     */
@Test
public void testShXrefHeredoc() throws IOException {
    StringReader in = new StringReader("cat<<EOF\n" + "This shouldn't cause any problem.\n" + "EOF\n" + "var='some string'\n");
    ShXref xref = new ShXref(in);
    StringWriter out = new StringWriter();
    xref.write(out);
    String[] result = out.toString().split("\n");
    // The single-quote on line 2 shouldn't start a string literal.
    assertTrue(result[1].endsWith("This shouldn't cause any problem."));
    // The string literal on line 4 should be recognized as one.
    assertTrue(result[3].endsWith("=<span class=\"s\">'some string'</span>"));
}
Also used : StringWriter(java.io.StringWriter) ShXref(org.opensolaris.opengrok.analysis.sh.ShXref) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 4 with ShXref

use of org.opensolaris.opengrok.analysis.sh.ShXref in project OpenGrok by OpenGrok.

the class JFlexXrefTest method bug16883.

/**
     * 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 + "<b>echo</b> <span class=\"s\">\"xyz</span>", 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 + "<b>echo</b> <span class=\"s\">\"hello\"</span>", out.toString());
}
Also used : StringWriter(java.io.StringWriter) ShXref(org.opensolaris.opengrok.analysis.sh.ShXref) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

StringReader (java.io.StringReader)4 Test (org.junit.Test)4 ShXref (org.opensolaris.opengrok.analysis.sh.ShXref)4 StringWriter (java.io.StringWriter)3 CXref (org.opensolaris.opengrok.analysis.c.CXref)1 CxxXref (org.opensolaris.opengrok.analysis.c.CxxXref)1 TroffXref (org.opensolaris.opengrok.analysis.document.TroffXref)1 FortranXref (org.opensolaris.opengrok.analysis.fortran.FortranXref)1 HaskellXref (org.opensolaris.opengrok.analysis.haskell.HaskellXref)1 JavaXref (org.opensolaris.opengrok.analysis.java.JavaXref)1 LispXref (org.opensolaris.opengrok.analysis.lisp.LispXref)1 PerlXref (org.opensolaris.opengrok.analysis.perl.PerlXref)1 PlainXref (org.opensolaris.opengrok.analysis.plain.PlainXref)1 XMLXref (org.opensolaris.opengrok.analysis.plain.XMLXref)1 ScalaXref (org.opensolaris.opengrok.analysis.scala.ScalaXref)1 SQLXref (org.opensolaris.opengrok.analysis.sql.SQLXref)1 TclXref (org.opensolaris.opengrok.analysis.tcl.TclXref)1