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
de811cc0
Commit
de811cc0
authored
Mar 16, 2011
by
Alex Brainman
Committed by
Robert Griesemer
Mar 16, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/scanner: use filepath
R=gri CC=golang-dev
https://golang.org/cl/4280048
parent
b8e4fbb7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
16 deletions
+16
-16
scanner.go
src/pkg/go/scanner/scanner.go
+1
-1
scanner_test.go
src/pkg/go/scanner/scanner_test.go
+15
-15
No files found.
src/pkg/go/scanner/scanner.go
View file @
de811cc0
...
@@ -181,7 +181,7 @@ func (S *Scanner) interpretLineComment(text []byte) {
...
@@ -181,7 +181,7 @@ func (S *Scanner) interpretLineComment(text []byte) {
if
line
,
err
:=
strconv
.
Atoi
(
string
(
text
[
i
+
1
:
]));
err
==
nil
&&
line
>
0
{
if
line
,
err
:=
strconv
.
Atoi
(
string
(
text
[
i
+
1
:
]));
err
==
nil
&&
line
>
0
{
// valid //line filename:line comment;
// valid //line filename:line comment;
filename
:=
filepath
.
Clean
(
string
(
text
[
len
(
prefix
)
:
i
]))
filename
:=
filepath
.
Clean
(
string
(
text
[
len
(
prefix
)
:
i
]))
if
filename
[
0
]
!=
'/'
{
if
!
filepath
.
IsAbs
(
filename
)
{
// make filename relative to current directory
// make filename relative to current directory
filename
=
filepath
.
Join
(
S
.
dir
,
filename
)
filename
=
filepath
.
Join
(
S
.
dir
,
filename
)
}
}
...
...
src/pkg/go/scanner/scanner_test.go
View file @
de811cc0
...
@@ -7,6 +7,7 @@ package scanner
...
@@ -7,6 +7,7 @@ package scanner
import
(
import
(
"go/token"
"go/token"
"os"
"os"
"path/filepath"
"testing"
"testing"
)
)
...
@@ -443,27 +444,26 @@ func TestSemis(t *testing.T) {
...
@@ -443,27 +444,26 @@ func TestSemis(t *testing.T) {
}
}
}
}
var
segments
=
[]
struct
{
var
segments
=
[]
struct
{
srcline
string
// a line of source text
srcline
string
// a line of source text
filename
string
// filename for current token
filename
string
// filename for current token
line
int
// line number for current token
line
int
// line number for current token
}{
}{
// exactly one token per line since the test consumes one token per segment
// exactly one token per line since the test consumes one token per segment
{
" line1"
,
"dir/TestLineComments"
,
1
},
{
" line1"
,
filepath
.
Join
(
"dir"
,
"TestLineComments"
)
,
1
},
{
"
\n
line2"
,
"dir/TestLineComments"
,
2
},
{
"
\n
line2"
,
filepath
.
Join
(
"dir"
,
"TestLineComments"
)
,
2
},
{
"
\n
line3 //line File1.go:100"
,
"dir/TestLineComments"
,
3
},
// bad line comment, ignored
{
"
\n
line3 //line File1.go:100"
,
filepath
.
Join
(
"dir"
,
"TestLineComments"
)
,
3
},
// bad line comment, ignored
{
"
\n
line4"
,
"dir/TestLineComments"
,
4
},
{
"
\n
line4"
,
filepath
.
Join
(
"dir"
,
"TestLineComments"
)
,
4
},
{
"
\n
//line File1.go:100
\n
line100"
,
"dir/File1.go"
,
100
},
{
"
\n
//line File1.go:100
\n
line100"
,
filepath
.
Join
(
"dir"
,
"File1.go"
)
,
100
},
{
"
\n
//line File2.go:200
\n
line200"
,
"dir/File2.go"
,
200
},
{
"
\n
//line File2.go:200
\n
line200"
,
filepath
.
Join
(
"dir"
,
"File2.go"
)
,
200
},
{
"
\n
//line :1
\n
line1"
,
"dir"
,
1
},
{
"
\n
//line :1
\n
line1"
,
"dir"
,
1
},
{
"
\n
//line foo:42
\n
line42"
,
"dir/foo"
,
42
},
{
"
\n
//line foo:42
\n
line42"
,
filepath
.
Join
(
"dir"
,
"foo"
)
,
42
},
{
"
\n
//line foo:42
\n
line44"
,
"dir/foo"
,
44
},
// bad line comment, ignored
{
"
\n
//line foo:42
\n
line44"
,
filepath
.
Join
(
"dir"
,
"foo"
)
,
44
},
// bad line comment, ignored
{
"
\n
//line foo 42
\n
line46"
,
"dir/foo"
,
46
},
// bad line comment, ignored
{
"
\n
//line foo 42
\n
line46"
,
filepath
.
Join
(
"dir"
,
"foo"
)
,
46
},
// bad line comment, ignored
{
"
\n
//line foo:42 extra text
\n
line48"
,
"dir/foo"
,
48
},
// bad line comment, ignored
{
"
\n
//line foo:42 extra text
\n
line48"
,
filepath
.
Join
(
"dir"
,
"foo"
)
,
48
},
// bad line comment, ignored
{
"
\n
//line /bar:42
\n
line42"
,
"/
bar"
,
42
},
{
"
\n
//line /bar:42
\n
line42"
,
string
(
filepath
.
Separator
)
+
"
bar"
,
42
},
{
"
\n
//line ./foo:42
\n
line42"
,
"dir/foo"
,
42
},
{
"
\n
//line ./foo:42
\n
line42"
,
filepath
.
Join
(
"dir"
,
"foo"
)
,
42
},
{
"
\n
//line a/b/c/File1.go:100
\n
line100"
,
"dir/a/b/c/File1.go"
,
100
},
{
"
\n
//line a/b/c/File1.go:100
\n
line100"
,
filepath
.
Join
(
"dir"
,
"a"
,
"b"
,
"c"
,
"File1.go"
)
,
100
},
}
}
...
@@ -477,7 +477,7 @@ func TestLineComments(t *testing.T) {
...
@@ -477,7 +477,7 @@ func TestLineComments(t *testing.T) {
// verify scan
// verify scan
var
S
Scanner
var
S
Scanner
file
:=
fset
.
AddFile
(
"dir/TestLineComments"
,
fset
.
Base
(),
len
(
src
))
file
:=
fset
.
AddFile
(
filepath
.
Join
(
"dir"
,
"TestLineComments"
)
,
fset
.
Base
(),
len
(
src
))
S
.
Init
(
file
,
[]
byte
(
src
),
nil
,
0
)
S
.
Init
(
file
,
[]
byte
(
src
),
nil
,
0
)
for
_
,
s
:=
range
segments
{
for
_
,
s
:=
range
segments
{
p
,
_
,
lit
:=
S
.
Scan
()
p
,
_
,
lit
:=
S
.
Scan
()
...
...
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