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
ff68f96d
Commit
ff68f96d
authored
Jan 15, 2010
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test evaluation of range variables.
R=rsc CC=golang-dev
https://golang.org/cl/189088
parent
49a35a63
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
range.go
test/range.go
+34
-0
No files found.
test/range.go
View file @
ff68f96d
...
...
@@ -53,7 +53,41 @@ func testarray() {
}
}
// test that range evaluates the index and value expressions
// exactly once per iteration.
var
ncalls
=
0
func
getvar
(
p
*
int
)
*
int
{
ncalls
++
return
p
}
func
testcalls
()
{
var
i
,
v
int
si
:=
0
sv
:=
0
for
*
getvar
(
&
i
),
*
getvar
(
&
v
)
=
range
[
2
]
int
{
1
,
2
}
{
si
+=
i
sv
+=
v
}
if
ncalls
!=
4
{
panicln
(
"wrong number of calls:"
,
ncalls
,
"!= 4"
)
}
if
si
!=
1
||
sv
!=
3
{
panicln
(
"wrong sum in testcalls"
,
si
,
sv
)
}
ncalls
=
0
for
*
getvar
(
&
i
),
*
getvar
(
&
v
)
=
range
[
0
]
int
{}
{
panicln
(
"loop ran on empty array"
)
}
if
ncalls
!=
0
{
panicln
(
"wrong number of calls:"
,
ncalls
,
"!= 0"
)
}
}
func
main
()
{
testchan
();
testarray
();
testcalls
();
}
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