Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
e4db08d2
Commit
e4db08d2
authored
Mar 27, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix scanner initialization, add test
R=r DELTA=27 (25 added, 0 deleted, 2 changed) OCL=26798 CL=26798
parent
eeddc8e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
scanner.go
src/lib/go/scanner.go
+3
-1
scanner_test.go
src/lib/go/scanner_test.go
+24
-1
No files found.
src/lib/go/scanner.go
View file @
e4db08d2
...
...
@@ -76,10 +76,12 @@ func (S *Scanner) next() {
// white space and ignored.
//
func
(
S
*
Scanner
)
Init
(
src
[]
byte
,
err
ErrorHandler
,
scan_comments
bool
)
{
// Explicitly initialize all fields since a scanner may be reused.
S
.
src
=
src
;
S
.
err
=
err
;
S
.
scan_comments
=
scan_comments
;
S
.
pos
.
Line
=
1
;
S
.
pos
=
token
.
Position
{
0
,
1
,
0
};
S
.
offset
=
0
;
S
.
next
();
}
...
...
src/lib/go/scanner_test.go
View file @
e4db08d2
...
...
@@ -176,7 +176,8 @@ func NewlineCount(s string) int {
}
func
Test
(
t
*
testing
.
T
)
{
// Verify that calling Scan() provides the correct results.
func
TestScan
(
t
*
testing
.
T
)
{
// make source
var
src
string
;
for
i
,
e
:=
range
tokens
{
...
...
@@ -223,3 +224,25 @@ func Test(t *testing.T) {
}
);
}
// Verify that initializing the same scanner more then once works correctly.
func
TestInit
(
t
*
testing
.
T
)
{
var
s
scanner
.
Scanner
;
// 1st init
s
.
Init
(
io
.
StringBytes
(
"if true { }"
),
&
TestErrorHandler
{
t
},
false
);
s
.
Scan
();
// if
s
.
Scan
();
// true
pos
,
tok
,
lit
:=
s
.
Scan
();
// {
if
tok
!=
token
.
LBRACE
{
t
.
Errorf
(
"bad token: got %s, expected %s"
,
tok
.
String
(),
token
.
LBRACE
);
}
// 2nd init
s
.
Init
(
io
.
StringBytes
(
"go true { ]"
),
&
TestErrorHandler
{
t
},
false
);
pos
,
tok
,
lit
=
s
.
Scan
();
// go
if
tok
!=
token
.
GO
{
t
.
Errorf
(
"bad token: got %s, expected %s"
,
tok
.
String
(),
token
.
GO
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment