Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
2fa6129c
Commit
2fa6129c
authored
Mar 20, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started dispenser tests
parent
bb6a921d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
141 additions
and
0 deletions
+141
-0
config/dispenser_test.go
config/dispenser_test.go
+141
-0
No files found.
config/dispenser_test.go
0 → 100644
View file @
2fa6129c
package
config
import
(
"strings"
"testing"
)
func
TestDispenser_cursor_Val_Next
(
t
*
testing
.
T
)
{
input
:=
`host:port
dir1 arg1
dir2 arg2 arg3
dir3`
d
:=
mockDispenser
(
"test"
,
input
)
if
val
:=
d
.
Val
();
val
!=
""
{
t
.
Fatalf
(
"Val(): Should return empty string when no token loaded; got '%s'"
,
val
)
}
assertNext
:=
func
(
shouldLoad
bool
,
expectedCursor
int
,
expectedVal
string
)
{
if
loaded
:=
d
.
Next
();
loaded
!=
shouldLoad
{
t
.
Errorf
(
"Next(): Expected %v but got %v instead (val '%s')"
,
shouldLoad
,
loaded
,
d
.
Val
())
}
if
d
.
cursor
!=
expectedCursor
{
t
.
Errorf
(
"Expected cursor to be %d, but was %d"
,
expectedCursor
,
d
.
cursor
)
}
if
d
.
nesting
!=
0
{
t
.
Errorf
(
"Nesting should be 0, was %d instead"
,
d
.
nesting
)
}
if
val
:=
d
.
Val
();
val
!=
expectedVal
{
t
.
Errorf
(
"Val(): Expected '%s' but got '%s'"
,
expectedVal
,
val
)
}
}
assertNext
(
true
,
0
,
"host:port"
)
assertNext
(
true
,
1
,
"dir1"
)
assertNext
(
true
,
2
,
"arg1"
)
assertNext
(
true
,
3
,
"dir2"
)
assertNext
(
true
,
4
,
"arg2"
)
assertNext
(
true
,
5
,
"arg3"
)
assertNext
(
true
,
6
,
"dir3"
)
// Note: This next test simply asserts existing behavior.
// If desired, we may wish to empty the token value after
// reading past the EOF. Open an issue if you want this change.
assertNext
(
false
,
6
,
"dir3"
)
}
func
TestDispenser_NextArg
(
t
*
testing
.
T
)
{
input
:=
`dir1 arg1
dir2 arg2 arg3
dir3`
d
:=
mockDispenser
(
"test"
,
input
)
assertNext
:=
func
(
shouldLoad
bool
,
expectedVal
string
)
{
if
d
.
Next
()
!=
shouldLoad
{
t
.
Errorf
(
"Next(): Should load token but got false instead (val: '%s')"
,
d
.
Val
())
}
if
val
:=
d
.
Val
();
val
!=
expectedVal
{
t
.
Errorf
(
"Val(): Expected '%s' but got '%s'"
,
expectedVal
,
val
)
}
}
assertNextArg
:=
func
(
expectedVal
string
,
loadAnother
bool
)
{
if
d
.
NextArg
()
!=
true
{
t
.
Error
(
"NextArg(): Should load next argument but got false instead"
)
}
if
val
:=
d
.
Val
();
val
!=
expectedVal
{
t
.
Errorf
(
"Val(): Expected '%s' but got '%s'"
,
expectedVal
,
val
)
}
if
!
loadAnother
{
if
d
.
NextArg
()
!=
false
{
t
.
Fatalf
(
"NextArg(): Should NOT load another argument, but got true instead (val: '%s')"
,
d
.
Val
())
}
}
}
assertNext
(
true
,
"dir1"
)
assertNextArg
(
"arg1"
,
false
)
assertNext
(
true
,
"dir2"
)
assertNextArg
(
"arg2"
,
true
)
assertNextArg
(
"arg3"
,
false
)
assertNext
(
true
,
"dir3"
)
assertNext
(
false
,
"dir3"
)
}
func
TestDispenser_NextLine
(
t
*
testing
.
T
)
{
input
:=
`host:port
dir1 arg1
dir2 arg2 arg3`
d
:=
mockDispenser
(
"test"
,
input
)
assertNextLine
:=
func
(
shouldLoad
bool
,
expectedVal
string
)
{
if
d
.
NextLine
()
!=
shouldLoad
{
t
.
Errorf
(
"NextLine(): Should load token but got false instead (val: '%s')"
,
d
.
Val
())
}
if
val
:=
d
.
Val
();
val
!=
expectedVal
{
t
.
Errorf
(
"Val(): Expected '%s' but got '%s'"
,
expectedVal
,
val
)
}
}
assertNextLine
(
true
,
"host:port"
)
assertNextLine
(
true
,
"dir1"
)
assertNextLine
(
false
,
"dir1"
)
d
.
Next
()
// arg1
assertNextLine
(
true
,
"dir2"
)
assertNextLine
(
false
,
"dir2"
)
d
.
Next
()
// arg2
assertNextLine
(
false
,
"arg2"
)
d
.
Next
()
// arg3
assertNextLine
(
false
,
"arg3"
)
}
func
TestDispenser_NextBlock_nesting
(
t
*
testing
.
T
)
{
/*input := `foobar1 {
sub1 arg1 arg2 arg3
sub2 arg2
sub3
}
foobar2 {
}
foobar3`
d := mockDispenser("test", input)
*/
// TODO
}
func
mockDispenser
(
filename
,
input
string
)
dispenser
{
return
dispenser
{
filename
:
filename
,
cursor
:
-
1
,
tokens
:
getTokens
(
input
),
}
}
func
getTokens
(
input
string
)
(
tokens
[]
token
)
{
var
l
lexer
l
.
load
(
strings
.
NewReader
(
input
))
for
l
.
next
()
{
tokens
=
append
(
tokens
,
l
.
token
)
}
return
}
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