Skip to content

Commit 017cfed

Browse files
committed
Add (non-passing) test showing unclosed span...
... to be fixed by using disjointSpan() in the next commit Also: - just restructure test class to add more tests
1 parent e57b0ca commit 017cfed

File tree

5 files changed

+99
-22
lines changed

5 files changed

+99
-22
lines changed

test/org/opensolaris/opengrok/analysis/perl/PerlXrefTest.java

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,31 @@ public class PerlXrefTest {
4646

4747
@Test
4848
public void sampleTest() throws IOException {
49+
writeAndCompare("org/opensolaris/opengrok/analysis/perl/sample.pl",
50+
"org/opensolaris/opengrok/analysis/perl/samplexrefres.html");
51+
}
52+
53+
@Test
54+
public void shouldCloseTruncateStringSpan() throws IOException {
55+
writeAndCompare("org/opensolaris/opengrok/analysis/perl/truncated.pl",
56+
"org/opensolaris/opengrok/analysis/perl/truncated_xrefres.html");
57+
}
58+
59+
private void writeAndCompare(String sourceResource, String resultResource)
60+
throws IOException {
61+
4962
ByteArrayOutputStream baos = new ByteArrayOutputStream();
5063
ByteArrayOutputStream baosExp = new ByteArrayOutputStream();
5164

5265
InputStream res = getClass().getClassLoader().getResourceAsStream(
53-
"org/opensolaris/opengrok/analysis/perl/sample.pl");
54-
assertNotNull("sample.pl should get-as-stream", res);
66+
sourceResource);
67+
assertNotNull(sourceResource + " should get-as-stream", res);
5568
writePerlXref(res, new PrintStream(baos));
5669
res.close();
5770

5871
InputStream exp = getClass().getClassLoader().getResourceAsStream(
59-
"org/opensolaris/opengrok/analysis/perl/samplexrefres.html");
60-
assertNotNull("samplexrefres.html should get-as-stream", exp);
72+
resultResource);
73+
assertNotNull(resultResource + " should get-as-stream", exp);
6174
copyStream(exp, baosExp);
6275
exp.close();
6376
baosExp.close();
@@ -68,11 +81,10 @@ public void sampleTest() throws IOException {
6881
assertLinesEqual("Perl xref", estr, ostr);
6982
}
7083

71-
private void writePerlXref(InputStream iss, PrintStream oss) throws IOException {
72-
InputStream begin = getClass().getClassLoader().getResourceAsStream(
73-
"org/opensolaris/opengrok/analysis/perl/samplebeginhtml.txt");
74-
assertNotNull("samplebeginhtml.txt should get-as-stream", begin);
75-
copyStream(begin, oss);
84+
private void writePerlXref(InputStream iss, PrintStream oss)
85+
throws IOException {
86+
87+
oss.print(getHtmlBegin());
7688

7789
Writer sw = new StringWriter();
7890
PerlAnalyzerFactory fac = new PerlAnalyzerFactory();
@@ -81,10 +93,7 @@ private void writePerlXref(InputStream iss, PrintStream oss) throws IOException
8193
new InputStreamReader(iss, "UTF-8"), sw));
8294
oss.print(sw.toString());
8395

84-
InputStream end = getClass().getClassLoader().getResourceAsStream(
85-
"org/opensolaris/opengrok/analysis/perl/sampleendhtml.txt");
86-
assertNotNull("sampleendhtml.txt should get-as-stream", end);
87-
copyStream(end, oss);
96+
oss.print(getHtmlEnd());
8897
}
8998

9099
private void copyStream(InputStream iss, OutputStream oss) throws IOException {
@@ -97,4 +106,21 @@ private void copyStream(InputStream iss, OutputStream oss) throws IOException {
97106
}
98107
} while (read >= 0);
99108
}
109+
110+
private static String getHtmlBegin() {
111+
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
112+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n" +
113+
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" +
114+
"<html xmlns=\"http://www.w3.org/1999/xhtml\"" +
115+
" xml:lang=\"en\" lang=\"en\"\n" +
116+
" class=\"xref\">\n" +
117+
"<head>\n" +
118+
"<title>sampleTest.pl - OpenGrok cross reference" +
119+
" for /sampleTest.pl</title></head><body>\n";
120+
}
121+
122+
private static String getHtmlEnd() {
123+
return "</body>\n" +
124+
"</html>\n";
125+
}
100126
}

test/org/opensolaris/opengrok/analysis/perl/samplebeginhtml.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/org/opensolaris/opengrok/analysis/perl/sampleendhtml.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/perl
2+
3+
#
4+
# CDDL HEADER START
5+
#
6+
# The contents of this file are subject to the terms of the
7+
# Common Development and Distribution License (the "License").
8+
# You may not use this file except in compliance with the License.
9+
#
10+
# See LICENSE.txt included in this distribution for the specific
11+
# language governing permissions and limitations under the License.
12+
#
13+
# When distributing Covered Code, include this CDDL HEADER in each
14+
# file and include the License file at LICENSE.txt.
15+
# If applicable, add the following below this CDDL HEADER, with the
16+
# fields enclosed by brackets "[]" replaced with your own identifying
17+
# information: Portions Copyright [yyyy] [name of copyright owner]
18+
#
19+
# CDDL HEADER END
20+
#
21+
22+
#
23+
# Copyright (c) 2017, Chris Fraire <[email protected]>.
24+
#
25+
26+
print "Testing 1-2-3 oops this file is truncated in a string
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
5+
class="xref">
6+
<head>
7+
<title>sampleTest.pl - OpenGrok cross reference for /sampleTest.pl</title></head><body>
8+
<a class="l" name="1" href="#1">1</a><span class="c">#!/<a href="/source/s?path=/usr/">usr</a>/<a href="/source/s?path=/usr/bin/">bin</a>/<a href="/source/s?path=/usr/bin/perl">perl</a></span>
9+
<a class="l" name="2" href="#2">2</a>
10+
<a class="l" name="3" href="#3">3</a><span class="c">#</span>
11+
<a class="l" name="4" href="#4">4</a><span class="c"># CDDL HEADER START</span>
12+
<a class="l" name="5" href="#5">5</a><span class="c">#</span>
13+
<a class="l" name="6" href="#6">6</a><span class="c"># The contents of this file are subject to the terms of the</span>
14+
<a class="l" name="7" href="#7">7</a><span class="c"># Common Development and Distribution License (the &quot;License&quot;).</span>
15+
<a class="l" name="8" href="#8">8</a><span class="c"># You may not use this file except in compliance with the License.</span>
16+
<a class="l" name="9" href="#9">9</a><span class="c">#</span>
17+
<a class="hl" name="10" href="#10">10</a><span class="c"># See <a href="/source/s?path=LICENSE.txt">LICENSE.txt</a> included in this distribution for the specific</span>
18+
<a class="l" name="11" href="#11">11</a><span class="c"># language governing permissions and limitations under the License.</span>
19+
<a class="l" name="12" href="#12">12</a><span class="c">#</span>
20+
<a class="l" name="13" href="#13">13</a><span class="c"># When distributing Covered Code, include this CDDL HEADER in each</span>
21+
<a class="l" name="14" href="#14">14</a><span class="c"># file and include the License file at <a href="/source/s?path=LICENSE.txt">LICENSE.txt</a>.</span>
22+
<a class="l" name="15" href="#15">15</a><span class="c"># If applicable, add the following below this CDDL HEADER, with the</span>
23+
<a class="l" name="16" href="#16">16</a><span class="c"># fields enclosed by brackets &quot;[]&quot; replaced with your own identifying</span>
24+
<a class="l" name="17" href="#17">17</a><span class="c"># information: Portions Copyright [yyyy] [name of copyright owner]</span>
25+
<a class="l" name="18" href="#18">18</a><span class="c">#</span>
26+
<a class="l" name="19" href="#19">19</a><span class="c"># CDDL HEADER END</span>
27+
<a class="hl" name="20" href="#20">20</a><span class="c">#</span>
28+
<a class="l" name="21" href="#21">21</a>
29+
<a class="l" name="22" href="#22">22</a><span class="c">#</span>
30+
<a class="l" name="23" href="#23">23</a><span class="c"># Copyright (c) 2017, Chris Fraire &lt;[email protected]&gt;.</span>
31+
<a class="l" name="24" href="#24">24</a><span class="c">#</span>
32+
<a class="l" name="25" href="#25">25</a>
33+
<a class="l" name="26" href="#26">26</a><b>print</b> <span class="s">&quot;Testing 1-2-3 oops this file is truncated in a string</span></body>
34+
</html>

0 commit comments

Comments
 (0)