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
be7e0f81
Commit
be7e0f81
authored
Nov 19, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gotestify regexp
R=rsc DELTA=101 (53 added, 25 deleted, 23 changed) OCL=19635 CL=19637
parent
9195c22e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
42 deletions
+70
-42
Makefile
src/lib/regexp/Makefile
+43
-17
test.go
src/lib/regexp/test.go
+27
-25
No files found.
src/lib/regexp/Makefile
View file @
be7e0f81
...
...
@@ -2,28 +2,54 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
A
=
6
G
=
$(A)
g
L
=
$(A)
l
PKG
=
$(GOROOT)
/pkg/regexp.
$A
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
O
=
6
GC
=
$(O)
g
CC
=
$(O)
c
-w
AS
=
$(O)
a
AR
=
$(O)
ar
test
:
main.$A test.$A
$L
-o
test
test.
$A
./test
default
:
packages
install
:
regexp.$A
cp
regexp.
$A
$(PKG)
clean
:
rm
-f
*
.
$O
*
.a
$O
.out
main
:
main.$A
$L
-o
main main.
$A
test
:
packages
gotest
main.$A
:
regexp.$A
coverage
:
packages
gotest
6cov
-g
`
pwd
`
|
grep
-v
'^test.*\.go:'
clean
:
rm
-f
*
.6
test
%.$O
:
%.go
$(GC)
$*
.go
%.$O
:
%.c
$(CC)
$*
.c
%.$O
:
%.s
$(AS)
$*
.s
O1
=
\
regexp.
$O
\
regexp.a
:
a1
a1
:
$(O1)
$(AR)
grc regexp.a regexp.
$O
rm
-f
$(O1)
newpkg
:
clean
$(AR)
grc regexp.a
$(O1)
:
newpkg
nuke
:
clean
rm
-f
$(PKG)
rm
-f
$(GOROOT)
/pkg/regexp.a
packages
:
regexp.a
install
:
packages
cp
regexp.a
$(GOROOT)
/pkg/regexp.a
%.6
:
%.go
$G
$<
src/lib/regexp/test.go
View file @
be7e0f81
...
...
@@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
main
package
regexp
import
(
"os"
;
"regexp"
;
"testing"
;
)
var
good_re
=
[]
string
{
...
...
@@ -85,11 +86,10 @@ var matches = []Tester {
Tester
{
`a*(|(b))c*`
,
"aacc"
,
Vec
{
0
,
4
,
2
,
2
,
-
1
,
-
1
,
END
}
},
}
func
Compile
(
expr
string
,
error
*
os
.
Error
)
regexp
.
Regexp
{
func
Compile
Test
(
t
*
testing
.
T
,
expr
string
,
error
*
os
.
Error
)
regexp
.
Regexp
{
re
,
err
:=
regexp
.
Compile
(
expr
);
if
err
!=
error
{
print
(
"compiling `"
,
expr
,
"`; unexpected error: "
,
err
.
String
(),
"
\n
"
);
sys
.
exit
(
1
);
t
.
Error
(
"compiling `"
,
expr
,
"`; unexpected error: "
,
err
.
String
());
}
return
re
}
...
...
@@ -104,13 +104,13 @@ func MarkedLen(m *[] int) int {
return
i
}
func
PrintVec
(
m
*
[]
int
)
{
func
PrintVec
(
t
*
testing
.
T
,
m
*
[]
int
)
{
l
:=
MarkedLen
(
m
);
if
l
==
0
{
print
(
"
<no match>"
);
t
.
Log
(
"
\t
<no match>"
);
}
else
{
for
i
:=
0
;
i
<
l
&&
m
[
i
]
!=
END
;
i
=
i
+
2
{
print
(
m
[
i
],
","
,
m
[
i
+
1
],
" "
)
t
.
Log
(
"
\t
"
,
m
[
i
],
","
,
m
[
i
+
1
]
)
}
}
}
...
...
@@ -128,33 +128,35 @@ func Equal(m1, m2 *[]int) bool {
return
true
}
func
Match
(
expr
string
,
str
string
,
match
*
[]
int
)
{
re
:=
Compile
(
expr
,
nil
);
func
MatchTest
(
t
*
testing
.
T
,
expr
string
,
str
string
,
match
*
[]
int
)
{
re
:=
CompileTest
(
t
,
expr
,
nil
);
if
re
==
nil
{
return
}
m
:=
re
.
Execute
(
str
);
if
!
Equal
(
m
,
match
)
{
print
(
"failure on `"
,
expr
,
"` matching `"
,
str
,
"`:
\n
"
);
PrintVec
(
m
);
print
(
"
\n
should be:
\n
"
);
PrintVec
(
match
);
print
(
"
\n
"
);
sys
.
exit
(
1
);
t
.
Error
(
"failure on `"
,
expr
,
"` matching `"
,
str
,
"`:"
);
PrintVec
(
t
,
m
);
t
.
Log
(
"should be:"
);
PrintVec
(
t
,
match
);
}
}
func
main
()
{
//regexp.debug = true;
if
sys
.
argc
()
>
1
{
Compile
(
sys
.
argv
(
1
),
nil
);
sys
.
exit
(
0
);
}
export
func
TestGoodCompile
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
len
(
good_re
);
i
++
{
Compile
(
good_re
[
i
],
nil
);
Compile
Test
(
t
,
good_re
[
i
],
nil
);
}
}
export
func
TestBadCompile
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
len
(
bad_re
);
i
++
{
Compile
(
bad_re
[
i
]
.
re
,
bad_re
[
i
]
.
err
)
Compile
Test
(
t
,
bad_re
[
i
]
.
re
,
bad_re
[
i
]
.
err
)
}
}
export
func
TestMatch
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
len
(
matches
);
i
++
{
t
:=
&
matches
[
i
];
Match
(
t
.
re
,
t
.
text
,
&
t
.
match
)
t
est
:=
&
matches
[
i
];
Match
Test
(
t
,
test
.
re
,
test
.
text
,
&
tes
t
.
match
)
}
}
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