Skip to content

Commit 1182423

Browse files
committed
Add FortranSymbolTokenizerTest, and fix exposed bug
- FortranXref writeSymbol() should have been called in case-insensitive mode.
1 parent 06a0e69 commit 1182423

File tree

4 files changed

+144
-22
lines changed

4 files changed

+144
-22
lines changed

src/org/opensolaris/opengrok/analysis/fortran/FortranXref.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"0x" [0-9a-fA-F]+ )([udl]+)?
6969

7070
{Identifier} {
7171
String id = yytext();
72-
writeSymbol(id, Consts.kwd, yyline);
72+
writeSymbol(id, Consts.kwd, yyline, false);
7373
}
7474

7575
"<" ({File}|{FPath}) ">" {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
package org.opensolaris.opengrok.analysis.fortran;
26+
27+
import java.io.BufferedReader;
28+
import java.io.InputStream;
29+
import java.io.InputStreamReader;
30+
import java.util.ArrayList;
31+
import java.util.List;
32+
import static org.junit.Assert.assertNotNull;
33+
import org.junit.Test;
34+
import static org.opensolaris.opengrok.util.CustomAssertions.assertSymbolStream;
35+
36+
/**
37+
* Tests the {@link FortranSymbolTokenizer} class.
38+
*/
39+
public class FortranSymbolTokenizerTest {
40+
41+
/**
42+
* Test sample.f v. samplesymbols.txt
43+
* @throws java.lang.Exception thrown on error
44+
*/
45+
@Test
46+
public void testFortranSymbolStream() throws Exception {
47+
InputStream fres = getClass().getClassLoader().getResourceAsStream(
48+
"org/opensolaris/opengrok/analysis/fortran/sample.f");
49+
assertNotNull("despite sample.f as resource,", fres);
50+
InputStream wdsres = getClass().getClassLoader().getResourceAsStream(
51+
"org/opensolaris/opengrok/analysis/fortran/samplesymbols.txt");
52+
assertNotNull("despite samplesymbols.txt as resource,", wdsres);
53+
54+
List<String> expectedSymbols = new ArrayList<>();
55+
try (BufferedReader wdsr = new BufferedReader(new InputStreamReader(
56+
wdsres, "UTF-8"))) {
57+
String line;
58+
while ((line = wdsr.readLine()) != null) {
59+
int hasho = line.indexOf('#');
60+
if (hasho != -1) line = line.substring(0, hasho);
61+
expectedSymbols.add(line.trim());
62+
}
63+
}
64+
65+
assertSymbolStream(FortranSymbolTokenizer.class, fres,
66+
expectedSymbols);
67+
}
68+
}

0 commit comments

Comments
 (0)