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
04ff7bb1
...
04ff7bb132c81a4d04a868fd320ea022318c682e
authored
2011-12-14 11:23:18 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added more tests for FunctionArgsInjector
1 parent
6b1f3b76
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
8 deletions
lib/tester.js
lib/utils.js
tests/suites/injector.js
lib/tester.js
View file @
04ff7bb
...
...
@@ -88,8 +88,8 @@
exporter
.
addSuccess
(
"unknown"
,
message
);
}
else
{
casper
.
echo
(
this
.
colorize
(
FAIL
,
'RED_BAR'
)
+
' '
+
this
.
formatMessage
(
message
,
'WARNING'
));
this
.
comment
(
' got: '
+
testValue
);
this
.
comment
(
' expected: '
+
expected
);
this
.
comment
(
' got: '
+
serialize
(
testValue
)
);
this
.
comment
(
' expected: '
+
serialize
(
expected
)
);
this
.
testResults
.
failed
++
;
exporter
.
addFailure
(
"unknown"
,
message
,
"test failed; expected: "
+
expected
+
"; got: "
+
testValue
,
"assertEquals"
);
}
...
...
lib/utils.js
View file @
04ff7bb
...
...
@@ -146,12 +146,7 @@ function createPage(casper) {
* @param Mixed value
*/
function
dump
(
value
)
{
if
(
isType
(
value
,
"array"
))
{
value
=
value
.
map
(
function
(
prop
)
{
return
isType
(
prop
,
"function"
)
?
prop
.
toString
().
replace
(
/
\s{2,}
/
,
''
)
:
prop
;
});
}
console
.
log
(
JSON
.
stringify
(
value
,
null
,
4
));
console
.
log
(
serialize
(
value
));
}
/**
...
...
@@ -265,3 +260,18 @@ function replaceFunctionPlaceholders(fn, replacements) {
}
return
fn
;
}
/**
* Serializes a value using JSON.
*
* @param Mixed value
* @return String
*/
function
serialize
(
value
)
{
if
(
isType
(
value
,
"array"
))
{
value
=
value
.
map
(
function
(
prop
)
{
return
isType
(
prop
,
"function"
)
?
prop
.
toString
().
replace
(
/
\s{2,}
/
,
''
)
:
prop
;
});
}
return
JSON
.
stringify
(
value
,
null
,
4
);
}
...
...
tests/suites/injector.js
View file @
04ff7bb
...
...
@@ -13,6 +13,40 @@
t
.
assertEquals
(
extract
.
body
,
'return a + b;'
,
'FunctionArgsInjector.extract() process function body as expected'
);
t
.
assertEquals
(
extract
.
args
,
[
'a'
,
'b'
],
'FunctionArgsInjector.extract() process function args as expected'
);
function
Plop
(
foo
,
bar
)
{
return
'foo: '
+
foo
+
', bar: '
+
bar
;
}
function
Plip
()
{
return
'plop'
;
}
function
foo_bar
(
boz
)
{}
var
gni
=
function
(
$bubu_bibi
,
__popo__
)
{};
var
gno
=
function
(
arg1
,
/*plop*/
arg2
)
{
};
t
.
assertEquals
(
injector
.
extract
(
Plop
),
{
name
:
'Plop'
,
args
:
[
'foo'
,
'bar'
],
body
:
"return 'foo: ' + foo +', bar: ' + bar;"
},
'FunctionArgsInjector.extract() handles named functions with arguments and body'
);
t
.
assertEquals
(
injector
.
extract
(
Plip
),
{
name
:
'Plip'
,
args
:
[],
body
:
"return 'plop';"
},
'FunctionArgsInjector.extract() handles functions with no arguments'
);
t
.
assertEquals
(
injector
.
extract
(
foo_bar
),
{
name
:
'foo_bar'
,
args
:
[
'boz'
],
body
:
""
},
'FunctionArgsInjector.extract() handles functions with no body'
);
t
.
assertEquals
(
injector
.
extract
(
gni
),
{
name
:
null
,
args
:
[
'$bubu_bibi'
,
'__popo__'
],
body
:
""
},
'FunctionArgsInjector.extract() handles anonymous functions with complex args passed'
);
t
.
assertEquals
(
injector
.
extract
(
gno
),
{
name
:
null
,
args
:
[
'arg1'
,
'arg2'
],
body
:
""
},
'FunctionArgsInjector.extract() handles can filter comments in function args'
);
t
.
comment
(
'FunctionArgsInjector.process()'
);
var
processed
;
eval
(
'processed = '
+
injector
.
process
({
a
:
1
,
b
:
2
}));
...
...
Please
register
or
sign in
to post a comment