Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
922f8487
Commit
922f8487
authored
Nov 19, 2014
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/cli: Added argument parse tests
parent
a69ddbb9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
0 deletions
+105
-0
commands/cli/parse_test.go
commands/cli/parse_test.go
+105
-0
No files found.
commands/cli/parse_test.go
View file @
922f8487
...
@@ -49,3 +49,108 @@ func TestOptionParsing(t *testing.T) {
...
@@ -49,3 +49,108 @@ func TestOptionParsing(t *testing.T) {
t
.
Errorf
(
"Returned command was different than expected"
)
t
.
Errorf
(
"Returned command was different than expected"
)
}
}
}
}
func
TestArgumentParsing
(
t
*
testing
.
T
)
{
rootCmd
:=
&
commands
.
Command
{
Subcommands
:
map
[
string
]
*
commands
.
Command
{
"noarg"
:
&
commands
.
Command
{},
"onearg"
:
&
commands
.
Command
{
Arguments
:
[]
commands
.
Argument
{
commands
.
StringArg
(
"a"
,
true
,
false
,
"some arg"
),
},
},
"twoargs"
:
&
commands
.
Command
{
Arguments
:
[]
commands
.
Argument
{
commands
.
StringArg
(
"a"
,
true
,
false
,
"some arg"
),
commands
.
StringArg
(
"b"
,
true
,
false
,
"another arg"
),
},
},
"variadic"
:
&
commands
.
Command
{
Arguments
:
[]
commands
.
Argument
{
commands
.
StringArg
(
"a"
,
true
,
true
,
"some arg"
),
},
},
"optional"
:
&
commands
.
Command
{
Arguments
:
[]
commands
.
Argument
{
commands
.
StringArg
(
"b"
,
false
,
true
,
"another arg"
),
},
},
"reversedoptional"
:
&
commands
.
Command
{
Arguments
:
[]
commands
.
Argument
{
commands
.
StringArg
(
"a"
,
false
,
false
,
"some arg"
),
commands
.
StringArg
(
"b"
,
true
,
false
,
"another arg"
),
},
},
},
}
_
,
_
,
_
,
err
:=
Parse
([]
string
{
"noarg"
},
nil
,
rootCmd
)
if
err
!=
nil
{
t
.
Error
(
"Should have passed"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"noarg"
,
"value!"
},
nil
,
rootCmd
)
if
err
==
nil
{
t
.
Error
(
"Should have failed (provided an arg, but command didn't define any)"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"onearg"
,
"value!"
},
nil
,
rootCmd
)
if
err
!=
nil
{
t
.
Error
(
"Should have passed"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"onearg"
},
nil
,
rootCmd
)
if
err
==
nil
{
t
.
Error
(
"Should have failed (didn't provide any args, arg is required)"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"twoargs"
,
"value1"
,
"value2"
},
nil
,
rootCmd
)
if
err
!=
nil
{
t
.
Error
(
"Should have passed"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"twoargs"
,
"value!"
},
nil
,
rootCmd
)
if
err
==
nil
{
t
.
Error
(
"Should have failed (only provided 1 arg, needs 2)"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"twoargs"
},
nil
,
rootCmd
)
if
err
==
nil
{
t
.
Error
(
"Should have failed (didn't provide any args, 2 required)"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"variadic"
,
"value!"
},
nil
,
rootCmd
)
if
err
!=
nil
{
t
.
Error
(
"Should have passed"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"variadic"
,
"value1"
,
"value2"
,
"value3"
},
nil
,
rootCmd
)
if
err
!=
nil
{
t
.
Error
(
"Should have passed"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"variadic"
},
nil
,
rootCmd
)
if
err
==
nil
{
t
.
Error
(
"Should have failed (didn't provide any args, 1 required)"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"optional"
,
"value!"
},
nil
,
rootCmd
)
if
err
!=
nil
{
t
.
Error
(
"Should have passed"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"optional"
},
nil
,
rootCmd
)
if
err
!=
nil
{
t
.
Error
(
"Should have passed"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"reversedoptional"
,
"value1"
,
"value2"
},
nil
,
rootCmd
)
if
err
!=
nil
{
t
.
Error
(
"Should have passed"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"reversedoptional"
,
"value!"
},
nil
,
rootCmd
)
if
err
!=
nil
{
t
.
Error
(
"Should have passed"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"reversedoptional"
},
nil
,
rootCmd
)
if
err
==
nil
{
t
.
Error
(
"Should have failed (didn't provide any args, 1 required)"
)
}
_
,
_
,
_
,
err
=
Parse
([]
string
{
"reversedoptional"
,
"value1"
,
"value2"
,
"value3"
},
nil
,
rootCmd
)
if
err
==
nil
{
t
.
Error
(
"Should have failed (provided too many args, only takes 1)"
)
}
}
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