Skip to content

Commit 7f9a560

Browse files
committed
Add JsonSymbolTokenizerTest, and fix number bug
1 parent a2b7fb3 commit 7f9a560

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

src/org/opensolaris/opengrok/analysis/json/JsonSymbolTokenizer.lex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ super(in);
4747
/* TODO : add unicode support */
4848
Identifier = [a-zA-Z_$] [a-zA-Z0-9_$]*
4949

50+
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?
51+
5052
%state STRING
5153

5254
%%
@@ -59,6 +61,9 @@ Identifier = [a-zA-Z_$] [a-zA-Z0-9_$]*
5961
setAttribs(id, yychar, yychar + yylength());
6062
return yystate(); }
6163
}
64+
65+
{Number} {}
66+
6267
\" { yybegin(STRING); }
6368
}
6469

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.json;
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 JsonSymbolTokenizer} class.
38+
*/
39+
public class JsonSymbolTokenizerTest {
40+
41+
/**
42+
* Test sample.json v. samplesymbols.txt
43+
* @throws java.lang.Exception thrown on error
44+
*/
45+
@Test
46+
public void testJsonSymbolStream() throws Exception {
47+
InputStream jres = getClass().getClassLoader().getResourceAsStream(
48+
"org/opensolaris/opengrok/analysis/json/sample.json");
49+
assertNotNull("despite sample.json as resource,", jres);
50+
InputStream symres = getClass().getClassLoader().getResourceAsStream(
51+
"org/opensolaris/opengrok/analysis/json/samplesymbols.txt");
52+
assertNotNull("despite samplesymbols.txt as resource,", symres);
53+
54+
List<String> expectedSymbols = new ArrayList<>();
55+
try (BufferedReader wdsr = new BufferedReader(new InputStreamReader(
56+
symres, "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(JsonSymbolTokenizer.class, jres, expectedSymbols);
66+
}
67+
}

test/org/opensolaris/opengrok/analysis/json/samplesymbols.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)