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
6fcae0f0
Commit
6fcae0f0
authored
Dec 14, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
token/position: provide files iterator
R=golang-dev, r2 CC=golang-dev
https://golang.org/cl/3541044
parent
52c9fb6f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
position.go
src/pkg/go/token/position.go
+22
-0
position_test.go
src/pkg/go/token/position_test.go
+18
-0
No files found.
src/pkg/go/token/position.go
View file @
6fcae0f0
...
...
@@ -385,3 +385,25 @@ func (s *FileSet) AddFile(filename string, base, size int) *File {
s
.
files
=
append
(
s
.
files
,
f
)
return
f
}
// Files returns the files added to the file set.
func
(
s
*
FileSet
)
Files
()
<-
chan
*
File
{
ch
:=
make
(
chan
*
File
)
go
func
()
{
for
i
:=
0
;
;
i
++
{
var
f
*
File
s
.
mutex
.
RLock
()
if
i
<
len
(
s
.
files
)
{
f
=
s
.
files
[
i
]
}
s
.
mutex
.
RUnlock
()
if
f
==
nil
{
break
}
ch
<-
f
}
close
(
ch
)
}()
return
ch
}
src/pkg/go/token/position_test.go
View file @
6fcae0f0
...
...
@@ -138,3 +138,21 @@ func TestLineInfo(t *testing.T) {
checkPos
(
t
,
msg
,
fset
.
Position
(
p
),
Position
{
"bar"
,
offs
,
42
,
col
})
}
}
func
TestFiles
(
t
*
testing
.
T
)
{
fset
:=
NewFileSet
()
for
i
,
test
:=
range
tests
{
fset
.
AddFile
(
test
.
filename
,
fset
.
Base
(),
test
.
size
)
j
:=
0
for
g
:=
range
fset
.
Files
()
{
if
g
.
Name
()
!=
tests
[
j
]
.
filename
{
t
.
Errorf
(
"expected filename = %s; got %s"
,
tests
[
j
]
.
filename
,
g
.
Name
())
}
j
++
}
if
j
!=
i
+
1
{
t
.
Errorf
(
"expected %d files; got %d"
,
i
+
1
,
j
)
}
}
}
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