Skip to content

Commit 60e6c60

Browse files
committed
Add GolangSymbolTokenizerTest, and fix number bug
1 parent f85a4f1 commit 60e6c60

File tree

5 files changed

+297
-4
lines changed

5 files changed

+297
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
Identifier = [a-zA-Z_] [a-zA-Z0-9_\']*
26+
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9][0-9_]*)([eE][+-]?[0-9]+)?

src/org/opensolaris/opengrok/analysis/golang/GolangSymbolTokenizer.lex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ super(in);
4545
%include CommonTokenizer.lexh
4646
%char
4747

48-
Identifier = [a-zA-Z_] [a-zA-Z0-9_']*
49-
5048
%state STRING COMMENT SCOMMENT QSTRING
5149

50+
%include Golang.lexh
5251
%%
5352

5453
<YYINITIAL> {
@@ -59,6 +58,7 @@ Identifier = [a-zA-Z_] [a-zA-Z0-9_']*
5958
return yystate();
6059
}
6160
}
61+
{Number} {}
6262
\" { yybegin(STRING); }
6363
\' { yybegin(QSTRING); }
6464
"/*" { yybegin(COMMENT); }

src/org/opensolaris/opengrok/analysis/golang/GolangXref.lex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@ import org.opensolaris.opengrok.web.Util;
5050
protected void setLineNumber(int x) { yyline = x; }
5151
%}
5252

53-
Identifier = [a-zA-Z_] [a-zA-Z0-9_']*
5453
File = [a-zA-Z]{FNameChar}* "." ("go"|"txt"|"htm"|"html"|"diff"|"patch")
55-
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9][0-9_]*)([eE][+-]?[0-9]+)?
5654

5755
%state STRING COMMENT SCOMMENT QSTRING
5856

5957
%include Common.lexh
6058
%include CommonURI.lexh
6159
%include CommonPath.lexh
60+
%include Golang.lexh
6261
%%
6362
<YYINITIAL> {
6463
{Identifier} {
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.golang;
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 GolangSymbolTokenizer} class.
38+
*/
39+
public class GolangSymbolTokenizerTest {
40+
41+
/**
42+
* Test sample.go v. samplesymbols.txt
43+
* @throws java.lang.Exception thrown on error
44+
*/
45+
@Test
46+
public void testGolangSymbolStream() throws Exception {
47+
InputStream gores = getClass().getClassLoader().getResourceAsStream(
48+
"org/opensolaris/opengrok/analysis/golang/sample.go");
49+
assertNotNull("despite sample.go as resource,", gores);
50+
InputStream symres = getClass().getClassLoader().getResourceAsStream(
51+
"org/opensolaris/opengrok/analysis/golang/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(GolangSymbolTokenizer.class, gores,
66+
expectedSymbols);
67+
}
68+
}
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
fzf # 23:package fzf
2+
Reader # 36:type Reader
3+
pusher
4+
byte
5+
bool
6+
eventBox
7+
util
8+
EventBox
9+
delimNil
10+
bool
11+
event
12+
int32
13+
NewReader # 44:func NewReader(
14+
pusher
15+
byte
16+
bool
17+
eventBox
18+
util
19+
EventBox
20+
delimNil
21+
bool
22+
Reader
23+
Reader
24+
pusher
25+
eventBox
26+
delimNil
27+
int32
28+
EvtReady
29+
r # 48:func (r
30+
Reader
31+
startEventPoller
32+
ptr
33+
r
34+
event
35+
pollInterval
36+
readerPollIntervalMin
37+
atomic
38+
CompareAndSwapInt32
39+
ptr
40+
int32
41+
EvtReadNew
42+
int32
43+
EvtReady
44+
r
45+
eventBox
46+
Set
47+
EvtReadNew
48+
true
49+
pollInterval
50+
readerPollIntervalMin
51+
atomic
52+
LoadInt32
53+
ptr
54+
int32
55+
EvtReadFin
56+
pollInterval
57+
readerPollIntervalStep
58+
pollInterval
59+
readerPollIntervalMax
60+
pollInterval
61+
readerPollIntervalMax
62+
time
63+
Sleep
64+
pollInterval
65+
r # 69:func (r
66+
Reader
67+
fin
68+
success
69+
bool
70+
atomic
71+
StoreInt32
72+
r
73+
event
74+
int32
75+
EvtReadFin
76+
r
77+
eventBox
78+
Set
79+
EvtReadFin
80+
success
81+
r # 75:func (r
82+
Reader
83+
ReadSource
84+
r
85+
startEventPoller
86+
success
87+
bool
88+
util
89+
IsTty
90+
cmd
91+
os
92+
Getenv
93+
len
94+
cmd
95+
success
96+
r
97+
readFromCommand
98+
defaultCommand
99+
success
100+
r
101+
readFromCommand
102+
cmd
103+
success
104+
r
105+
readFromStdin
106+
r
107+
fin
108+
success
109+
r # 92:func (r
110+
Reader
111+
feed
112+
src
113+
io
114+
Reader
115+
delim
116+
byte
117+
r
118+
delimNil
119+
delim
120+
reader
121+
bufio
122+
NewReaderSize
123+
src
124+
readerBufferSize
125+
bytea
126+
err
127+
reader
128+
ReadBytes
129+
delim
130+
byteaLen
131+
len
132+
bytea
133+
byteaLen
134+
byteaLen
135+
err
136+
nil
137+
util
138+
IsWindows
139+
byteaLen
140+
bytea
141+
byteaLen
142+
byte
143+
bytea
144+
bytea
145+
byteaLen
146+
bytea
147+
bytea
148+
byteaLen
149+
r
150+
pusher
151+
bytea
152+
atomic
153+
StoreInt32
154+
r
155+
event
156+
int32
157+
EvtReadNew
158+
err
159+
nil
160+
r # 122:func (r
161+
Reader
162+
readFromStdin
163+
bool
164+
r
165+
feed
166+
os
167+
Stdin
168+
true
169+
r # 127:func (r
170+
Reader
171+
readFromCommand
172+
shell
173+
string
174+
cmd
175+
string
176+
bool
177+
listCommand
178+
util
179+
ExecCommandWith
180+
shell
181+
cmd
182+
out
183+
err
184+
listCommand
185+
StdoutPipe
186+
err
187+
nil
188+
false
189+
err
190+
listCommand
191+
Start
192+
err
193+
nil
194+
false
195+
r
196+
feed
197+
out
198+
listCommand
199+
Wait
200+
nil

0 commit comments

Comments
 (0)