Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
ccabfa82
...
ccabfa82c12cdd4b128079755c05088a0b0d41a0
authored
2012-12-28 12:23:50 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
migrated cli tests to new testing format
1 parent
2b819b07
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
95 deletions
tests/suites/cli.js
tests/suites/cli.js
View file @
ccabfa8
/*global casper*/
/*jshint strict:false maxstatements:99*/
var
cli
=
require
(
'cli'
)
,
t
=
casper
.
test
;
var
cli
=
require
(
'cli'
);
t
.
comment
(
'parse(), get(), has()'
);
(
function
(
parsed
)
{
casper
.
test
.
begin
(
'parsing an empty argument list'
,
12
,
function
(
test
)
{
var
parsed
=
cli
.
parse
([]);
// clean
t
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
0
),
undefined
,
'parse() does not return inexistant positional arg'
);
t
.
assertEquals
(
parsed
.
get
(
'blah'
),
undefined
,
'parse() does not return inexistant option'
);
t
.
assert
(
!
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
.
assert
(
!
parsed
.
has
(
'blah'
),
'has() checks if an option is set'
);
t
est
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
est
.
assertEquals
(
parsed
.
options
,
{},
'parse() returns expected options object'
);
t
est
.
assertEquals
(
parsed
.
get
(
0
),
undefined
,
'parse() does not return inexistant positional arg'
);
t
est
.
assertEquals
(
parsed
.
get
(
'blah'
),
undefined
,
'parse() does not return inexistant option'
);
t
est
.
assert
(
!
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
est
.
assert
(
!
parsed
.
has
(
'blah'
),
'has() checks if an option is set'
);
// raw
t
.
assertEquals
(
parsed
.
raw
.
args
,
[],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
raw
.
options
,
{},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
raw
.
get
(
0
),
undefined
,
'parse() does not return inexistant positional arg'
);
t
.
assertEquals
(
parsed
.
raw
.
get
(
'blah'
),
undefined
,
'parse() does not return inexistant option'
);
t
.
assert
(
!
parsed
.
raw
.
has
(
0
),
'has() checks if a raw arg is set'
);
t
.
assert
(
!
parsed
.
raw
.
has
(
'blah'
),
'has() checks if a raw option is set'
);
})(
cli
.
parse
([]));
test
.
assertEquals
(
parsed
.
raw
.
args
,
[],
'parse() returns expected positional args array'
);
test
.
assertEquals
(
parsed
.
raw
.
options
,
{},
'parse() returns expected options object'
);
test
.
assertEquals
(
parsed
.
raw
.
get
(
0
),
undefined
,
'parse() does not return inexistant positional arg'
);
test
.
assertEquals
(
parsed
.
raw
.
get
(
'blah'
),
undefined
,
'parse() does not return inexistant option'
);
test
.
assert
(
!
parsed
.
raw
.
has
(
0
),
'has() checks if a raw arg is set'
);
test
.
assert
(
!
parsed
.
raw
.
has
(
'blah'
),
'has() checks if a raw option is set'
);
test
.
done
();
});
(
function
(
parsed
)
{
casper
.
test
.
begin
(
'parsing an basic argument list'
,
14
,
function
(
test
)
{
var
parsed
=
cli
.
parse
([
'foo'
,
'bar'
]);
// clean
t
.
assertEquals
(
parsed
.
args
,
[
'foo'
,
'bar'
],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
0
),
'foo'
,
'parse() retrieve first positional arg'
);
t
.
assertEquals
(
parsed
.
get
(
1
),
'bar'
,
'parse() retrieve second positional arg'
);
t
.
assert
(
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
.
assert
(
parsed
.
has
(
1
),
'has() checks if an arg is set'
);
t
.
assert
(
!
parsed
.
has
(
2
),
'has() checks if an arg is not set'
);
t
est
.
assertEquals
(
parsed
.
args
,
[
'foo'
,
'bar'
],
'parse() returns expected positional args array'
);
t
est
.
assertEquals
(
parsed
.
options
,
{},
'parse() returns expected options object'
);
t
est
.
assertEquals
(
parsed
.
get
(
0
),
'foo'
,
'parse() retrieve first positional arg'
);
t
est
.
assertEquals
(
parsed
.
get
(
1
),
'bar'
,
'parse() retrieve second positional arg'
);
t
est
.
assert
(
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
est
.
assert
(
parsed
.
has
(
1
),
'has() checks if an arg is set'
);
t
est
.
assert
(
!
parsed
.
has
(
2
),
'has() checks if an arg is not set'
);
// raw
t
.
assertEquals
(
parsed
.
raw
.
args
,
[
'foo'
,
'bar'
],
'parse() returns expected positional raw args array'
);
t
.
assertEquals
(
parsed
.
raw
.
options
,
{},
'parse() returns expected raw options object'
);
t
.
assertEquals
(
parsed
.
raw
.
get
(
0
),
'foo'
,
'parse() retrieve first positional raw arg'
);
t
.
assertEquals
(
parsed
.
raw
.
get
(
1
),
'bar'
,
'parse() retrieve second positional raw arg'
);
t
.
assert
(
parsed
.
raw
.
has
(
0
),
'has() checks if a arw arg is set'
);
t
.
assert
(
parsed
.
raw
.
has
(
1
),
'has() checks if a arw arg is set'
);
t
.
assert
(
!
parsed
.
raw
.
has
(
2
),
'has() checks if a arw arg is not set'
);
})(
cli
.
parse
([
'foo'
,
'bar'
]));
test
.
assertEquals
(
parsed
.
raw
.
args
,
[
'foo'
,
'bar'
],
'parse() returns expected positional raw args array'
);
test
.
assertEquals
(
parsed
.
raw
.
options
,
{},
'parse() returns expected raw options object'
);
test
.
assertEquals
(
parsed
.
raw
.
get
(
0
),
'foo'
,
'parse() retrieve first positional raw arg'
);
test
.
assertEquals
(
parsed
.
raw
.
get
(
1
),
'bar'
,
'parse() retrieve second positional raw arg'
);
test
.
assert
(
parsed
.
raw
.
has
(
0
),
'has() checks if a arw arg is set'
);
test
.
assert
(
parsed
.
raw
.
has
(
1
),
'has() checks if a arw arg is set'
);
test
.
assert
(
!
parsed
.
raw
.
has
(
2
),
'has() checks if a arw arg is not set'
);
test
.
done
();
});
(
function
(
parsed
)
{
casper
.
test
.
begin
(
'parsing some options'
,
12
,
function
(
test
)
{
var
parsed
=
cli
.
parse
([
'--foo=bar'
,
'--baz'
]);
// clean
t
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{
foo
:
'bar'
,
baz
:
true
},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
'foo'
),
'bar'
,
'parse() retrieve an option value'
);
t
.
assert
(
parsed
.
get
(
'baz'
),
'parse() retrieve boolean option flag'
);
t
.
assert
(
parsed
.
has
(
"foo"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"baz"
),
'has() checks if an option is set'
);
t
est
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
est
.
assertEquals
(
parsed
.
options
,
{
foo
:
'bar'
,
baz
:
true
},
'parse() returns expected options object'
);
t
est
.
assertEquals
(
parsed
.
get
(
'foo'
),
'bar'
,
'parse() retrieve an option value'
);
t
est
.
assert
(
parsed
.
get
(
'baz'
),
'parse() retrieve boolean option flag'
);
t
est
.
assert
(
parsed
.
has
(
"foo"
),
'has() checks if an option is set'
);
t
est
.
assert
(
parsed
.
has
(
"baz"
),
'has() checks if an option is set'
);
// raw
t
.
assertEquals
(
parsed
.
raw
.
args
,
[],
'parse() returns expected positional raw args array'
);
t
.
assertEquals
(
parsed
.
raw
.
options
,
{
foo
:
'bar'
,
baz
:
true
},
'parse() returns expected options raw object'
);
t
.
assertEquals
(
parsed
.
raw
.
get
(
'foo'
),
'bar'
,
'parse() retrieve an option raw value'
);
t
.
assert
(
parsed
.
raw
.
get
(
'baz'
),
'parse() retrieve boolean raw option flag'
);
t
.
assert
(
parsed
.
raw
.
has
(
"foo"
),
'has() checks if a raw option is set'
);
t
.
assert
(
parsed
.
raw
.
has
(
"baz"
),
'has() checks if a raw option is set'
);
})(
cli
.
parse
([
'--foo=bar'
,
'--baz'
]));
test
.
assertEquals
(
parsed
.
raw
.
args
,
[],
'parse() returns expected positional raw args array'
);
test
.
assertEquals
(
parsed
.
raw
.
options
,
{
foo
:
'bar'
,
baz
:
true
},
'parse() returns expected options raw object'
);
test
.
assertEquals
(
parsed
.
raw
.
get
(
'foo'
),
'bar'
,
'parse() retrieve an option raw value'
);
test
.
assert
(
parsed
.
raw
.
get
(
'baz'
),
'parse() retrieve boolean raw option flag'
);
test
.
assert
(
parsed
.
raw
.
has
(
"foo"
),
'has() checks if a raw option is set'
);
test
.
assert
(
parsed
.
raw
.
has
(
"baz"
),
'has() checks if a raw option is set'
);
test
.
done
();
});
(
function
(
parsed
)
{
casper
.
test
.
begin
(
'parsing an empty argument list'
,
8
,
function
(
test
)
{
var
parsed
=
cli
.
parse
([
'--&é"à=42===42'
]);
// clean
t
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{
'&é"à'
:
"42===42"
},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
'&é"à'
),
"42===42"
,
'parse() handles options with exotic names'
);
t
.
assert
(
parsed
.
has
(
'&é"à'
),
'has() checks if an option is set'
);
t
est
.
assertEquals
(
parsed
.
args
,
[],
'parse() returns expected positional args array'
);
t
est
.
assertEquals
(
parsed
.
options
,
{
'&é"à'
:
"42===42"
},
'parse() returns expected options object'
);
t
est
.
assertEquals
(
parsed
.
get
(
'&é"à'
),
"42===42"
,
'parse() handles options with exotic names'
);
t
est
.
assert
(
parsed
.
has
(
'&é"à'
),
'has() checks if an option is set'
);
// raw
t
.
assertEquals
(
parsed
.
raw
.
args
,
[],
'parse() returns expected positional raw args array'
);
t
.
assertEquals
(
parsed
.
raw
.
options
,
{
'&é"à'
:
"42===42"
},
'parse() returns expected options raw object'
);
t
.
assertEquals
(
parsed
.
raw
.
get
(
'&é"à'
),
"42===42"
,
'parse() handles raw options with exotic names'
);
t
.
assert
(
parsed
.
raw
.
has
(
'&é"à'
),
'has() checks if a raw option is set'
);
})(
cli
.
parse
([
'--&é"à=42===42'
]));
test
.
assertEquals
(
parsed
.
raw
.
args
,
[],
'parse() returns expected positional raw args array'
);
test
.
assertEquals
(
parsed
.
raw
.
options
,
{
'&é"à'
:
"42===42"
},
'parse() returns expected options raw object'
);
test
.
assertEquals
(
parsed
.
raw
.
get
(
'&é"à'
),
"42===42"
,
'parse() handles raw options with exotic names'
);
test
.
assert
(
parsed
.
raw
.
has
(
'&é"à'
),
'has() checks if a raw option is set'
);
test
.
done
();
});
(
function
(
parsed
)
{
casper
.
test
.
begin
(
'parsing commands containing args and options'
,
30
,
function
(
test
)
{
var
parsed
=
cli
.
parse
([
'foo & bar'
,
'baz & boz'
,
'--universe=42'
,
'--lap=13.37'
,
'--chucknorris'
,
'--oops=false'
]);
// clean
t
.
assertEquals
(
parsed
.
args
,
[
'foo & bar'
,
'baz & boz'
],
'parse() returns expected positional args array'
);
t
.
assertEquals
(
parsed
.
options
,
{
universe
:
42
,
lap
:
13.37
,
chucknorris
:
true
,
oops
:
false
},
'parse() returns expected options object'
);
t
.
assertEquals
(
parsed
.
get
(
'universe'
),
42
,
'parse() can cast a numeric option value'
);
t
.
assertEquals
(
parsed
.
get
(
'lap'
),
13.37
,
'parse() can cast a float option value'
);
t
.
assertType
(
parsed
.
get
(
'lap'
),
"number"
,
'parse() can cast a boolean value'
);
t
.
assert
(
parsed
.
get
(
'chucknorris'
),
'parse() can get a flag value by its option name'
);
t
.
assertType
(
parsed
.
get
(
'oops'
),
"boolean"
,
'parse() can cast a boolean value'
);
t
.
assertEquals
(
parsed
.
get
(
'oops'
),
false
,
'parse() can cast a boolean value'
);
t
.
assert
(
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
t
.
assert
(
parsed
.
has
(
1
),
'has() checks if an arg is set'
);
t
.
assert
(
parsed
.
has
(
"universe"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"lap"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"chucknorris"
),
'has() checks if an option is set'
);
t
.
assert
(
parsed
.
has
(
"oops"
),
'has() checks if an option is set'
);
t
.
comment
(
'drop()'
);
test
.
assertEquals
(
parsed
.
args
,
[
'foo & bar'
,
'baz & boz'
],
'parse() returns expected positional args array'
);
test
.
assertEquals
(
parsed
.
options
,
{
universe
:
42
,
lap
:
13.37
,
chucknorris
:
true
,
oops
:
false
},
'parse() returns expected options object'
);
test
.
assertEquals
(
parsed
.
get
(
'universe'
),
42
,
'parse() can cast a numeric option value'
);
test
.
assertEquals
(
parsed
.
get
(
'lap'
),
13.37
,
'parse() can cast a float option value'
);
test
.
assertType
(
parsed
.
get
(
'lap'
),
"number"
,
'parse() can cast a boolean value'
);
test
.
assert
(
parsed
.
get
(
'chucknorris'
),
'parse() can get a flag value by its option name'
);
test
.
assertType
(
parsed
.
get
(
'oops'
),
"boolean"
,
'parse() can cast a boolean value'
);
test
.
assertEquals
(
parsed
.
get
(
'oops'
),
false
,
'parse() can cast a boolean value'
);
test
.
assert
(
parsed
.
has
(
0
),
'has() checks if an arg is set'
);
test
.
assert
(
parsed
.
has
(
1
),
'has() checks if an arg is set'
);
test
.
assert
(
parsed
.
has
(
"universe"
),
'has() checks if an option is set'
);
test
.
assert
(
parsed
.
has
(
"lap"
),
'has() checks if an option is set'
);
test
.
assert
(
parsed
.
has
(
"chucknorris"
),
'has() checks if an option is set'
);
test
.
assert
(
parsed
.
has
(
"oops"
),
'has() checks if an option is set'
);
// drop()
parsed
.
drop
(
0
);
t
.
assertEquals
(
parsed
.
get
(
0
),
'baz & boz'
,
'drop() dropped arg'
);
t
est
.
assertEquals
(
parsed
.
get
(
0
),
'baz & boz'
,
'drop() dropped arg'
);
parsed
.
drop
(
"universe"
);
t
.
assert
(
!
parsed
.
has
(
"universe"
),
'drop() dropped option'
);
t
.
assertEquals
(
parsed
.
args
,
[
"baz & boz"
],
'drop() did not affect other args'
);
t
.
assertEquals
(
parsed
.
options
,
{
t
est
.
assert
(
!
parsed
.
has
(
"universe"
),
'drop() dropped option'
);
t
est
.
assertEquals
(
parsed
.
args
,
[
"baz & boz"
],
'drop() did not affect other args'
);
t
est
.
assertEquals
(
parsed
.
options
,
{
lap
:
13.37
,
chucknorris
:
true
,
oops
:
false
},
'drop() did not affect other options'
);
// raw
t
.
assertEquals
(
parsed
.
raw
.
args
,
[
'foo & bar'
,
'baz & boz'
],
'parse() returns expected positional raw args array'
);
t
.
assertEquals
(
parsed
.
raw
.
options
,
{
universe
:
"42"
,
lap
:
"13.37"
,
chucknorris
:
true
,
oops
:
"false"
},
'parse() returns expected options raw object'
);
t
.
assertEquals
(
parsed
.
raw
.
get
(
'universe'
),
"42"
,
'parse() does not a raw numeric option value'
);
t
.
assertEquals
(
parsed
.
raw
.
get
(
'lap'
),
"13.37"
,
'parse() does not cast a raw float option value'
);
t
.
assertType
(
parsed
.
raw
.
get
(
'lap'
),
"string"
,
'parse() does not cast a numeric value'
);
t
.
assert
(
parsed
.
raw
.
get
(
'chucknorris'
),
'parse() can get a flag value by its option name'
);
t
.
assertType
(
parsed
.
raw
.
get
(
'oops'
),
"string"
,
'parse() can cast a boolean value'
);
t
.
assertEquals
(
parsed
.
raw
.
get
(
'oops'
),
"false"
,
'parse() can cast a boolean value'
);
t
.
comment
(
'drop() for raw'
);
test
.
assertEquals
(
parsed
.
raw
.
args
,
[
'foo & bar'
,
'baz & boz'
],
'parse() returns expected positional raw args array'
);
test
.
assertEquals
(
parsed
.
raw
.
options
,
{
universe
:
"42"
,
lap
:
"13.37"
,
chucknorris
:
true
,
oops
:
"false"
},
'parse() returns expected options raw object'
);
test
.
assertEquals
(
parsed
.
raw
.
get
(
'universe'
),
"42"
,
'parse() does not a raw numeric option value'
);
test
.
assertEquals
(
parsed
.
raw
.
get
(
'lap'
),
"13.37"
,
'parse() does not cast a raw float option value'
);
test
.
assertType
(
parsed
.
raw
.
get
(
'lap'
),
"string"
,
'parse() does not cast a numeric value'
);
test
.
assert
(
parsed
.
raw
.
get
(
'chucknorris'
),
'parse() can get a flag value by its option name'
);
test
.
assertType
(
parsed
.
raw
.
get
(
'oops'
),
"string"
,
'parse() can cast a boolean value'
);
test
.
assertEquals
(
parsed
.
raw
.
get
(
'oops'
),
"false"
,
'parse() can cast a boolean value'
);
// drop() for raw
parsed
.
raw
.
drop
(
0
);
t
.
assertEquals
(
parsed
.
raw
.
get
(
0
),
'baz & boz'
,
'drop() dropped raw arg'
);
t
est
.
assertEquals
(
parsed
.
raw
.
get
(
0
),
'baz & boz'
,
'drop() dropped raw arg'
);
parsed
.
raw
.
drop
(
"universe"
);
t
.
assert
(
!
parsed
.
raw
.
has
(
"universe"
),
'drop() dropped raw option'
);
t
.
assertEquals
(
parsed
.
raw
.
args
,
[
"baz & boz"
],
'drop() did not affect other raw args'
);
t
.
assertEquals
(
parsed
.
raw
.
options
,
{
t
est
.
assert
(
!
parsed
.
raw
.
has
(
"universe"
),
'drop() dropped raw option'
);
t
est
.
assertEquals
(
parsed
.
raw
.
args
,
[
"baz & boz"
],
'drop() did not affect other raw args'
);
t
est
.
assertEquals
(
parsed
.
raw
.
options
,
{
lap
:
"13.37"
,
chucknorris
:
true
,
oops
:
"false"
},
'drop() did not affect other raw options'
);
})(
cli
.
parse
([
'foo & bar'
,
'baz & boz'
,
'--universe=42'
,
'--lap=13.37'
,
'--chucknorris'
,
'--oops=false'
]));
t
.
done
(
76
);
test
.
done
();
});
...
...
Please
register
or
sign in
to post a comment