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
1fded36e
...
1fded36e18ab6354b77fcee8f9fbe7efc742238c
authored
2012-10-10 15:00:52 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refactor: moved Tester.testEquals() code to utils.equals()
1 parent
fec3cbb5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
43 deletions
modules/tester.js
modules/utils.js
tests/suites/tester.js
tests/suites/utils.js
modules/tester.js
View file @
1fded36
...
...
@@ -884,24 +884,7 @@ var Tester = function Tester(casper, options) {
* @param Boolean
*/
this
.
testEquals
=
this
.
testEqual
=
function
testEquals
(
v1
,
v2
)
{
if
(
utils
.
betterTypeOf
(
v1
)
!==
utils
.
betterTypeOf
(
v2
))
{
return
false
;
}
if
(
utils
.
isFunction
(
v1
))
{
return
v1
.
toString
()
===
v2
.
toString
();
}
if
(
v1
instanceof
Object
)
{
if
(
Object
.
keys
(
v1
).
length
!==
Object
.
keys
(
v2
).
length
)
{
return
false
;
}
for
(
var
k
in
v1
)
{
if
(
!
this
.
testEquals
(
v1
[
k
],
v2
[
k
]))
{
return
false
;
}
}
return
true
;
}
return
v1
===
v2
;
return
utils
.
equals
(
v1
,
v2
);
};
/**
...
...
modules/utils.js
View file @
1fded36
...
...
@@ -62,6 +62,35 @@
exports
.
dump
=
dump
;
/**
* Tests equality between the two passed arguments.
*
* @param Mixed v1
* @param Mixed v2
* @param Boolean
*/
function
equals
(
v1
,
v2
)
{
if
(
betterTypeOf
(
v1
)
!==
betterTypeOf
(
v2
))
{
return
false
;
}
if
(
isFunction
(
v1
))
{
return
v1
.
toString
()
===
v2
.
toString
();
}
if
(
v1
instanceof
Object
)
{
if
(
Object
.
keys
(
v1
).
length
!==
Object
.
keys
(
v2
).
length
)
{
return
false
;
}
for
(
var
k
in
v1
)
{
if
(
!
equals
(
v1
[
k
],
v2
[
k
]))
{
return
false
;
}
}
return
true
;
}
return
v1
===
v2
;
}
exports
.
equals
=
equals
;
/**
* Returns the file extension in lower case.
*
* @param String file File path
...
...
tests/suites/tester.js
View file @
1fded36
...
...
@@ -4,31 +4,6 @@ var t = casper.test;
casper
.
start
();
t
.
comment
(
'Tester.testEquals()'
);
t
.
assert
(
t
.
testEquals
(
null
,
null
),
'Tester.testEquals() null equality'
);
t
.
assertNot
(
t
.
testEquals
(
null
,
undefined
),
'Tester.testEquals() null vs. undefined inequality'
);
t
.
assert
(
t
.
testEquals
(
"hi"
,
"hi"
),
'Tester.testEquals() string equality'
);
t
.
assertNot
(
t
.
testEquals
(
"hi"
,
"ih"
),
'Tester.testEquals() string inequality'
);
t
.
assert
(
t
.
testEquals
(
5
,
5
),
'Tester.testEquals() number equality'
);
t
.
assertNot
(
t
.
testEquals
(
"5"
,
5
),
'Tester.testEquals() number equality without implicit cast'
);
t
.
assert
(
t
.
testEquals
(
5
,
5.0
),
'Tester.testEquals() number equality with cast'
);
t
.
assertNot
(
t
.
testEquals
(
5
,
10
),
'Tester.testEquals() number inequality'
);
t
.
assert
(
t
.
testEquals
([],
[]),
'Tester.testEquals() empty array equality'
);
t
.
assert
(
t
.
testEquals
([
1
,
2
],
[
1
,
2
]),
'Tester.testEquals() array equality'
);
t
.
assert
(
t
.
testEquals
([
1
,
2
,[
1
,
2
,
function
(){}]],
[
1
,
2
,[
1
,
2
,
function
(){}]]),
'Tester.testEquals() complex array equality'
);
t
.
assertNot
(
t
.
testEquals
([
1
,
2
,[
1
,
2
,
function
(
a
){}]],
[
1
,
2
,[
1
,
2
,
function
(
b
){}]]),
'Tester.testEquals() complex array inequality'
);
t
.
assertNot
(
t
.
testEquals
([
1
,
2
],
[
2
,
1
]),
'Tester.testEquals() shuffled array inequality'
);
t
.
assertNot
(
t
.
testEquals
([
1
,
2
],
[
1
,
2
,
3
]),
'Tester.testEquals() array length inequality'
);
t
.
assert
(
t
.
testEquals
({},
{}),
'Tester.testEquals() empty object equality'
);
t
.
assert
(
t
.
testEquals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
2
}),
'Tester.testEquals() object length equality'
);
t
.
assert
(
t
.
testEquals
({
a
:
1
,
b
:
2
},
{
b
:
2
,
a
:
1
}),
'Tester.testEquals() shuffled object keys equality'
);
t
.
assertNot
(
t
.
testEquals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
3
}),
'Tester.testEquals() object inequality'
);
t
.
assert
(
t
.
testEquals
({
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}},
{
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}}),
'Tester.testEquals() complex object equality'
);
t
.
assertNot
(
t
.
testEquals
({
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}},
{
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
27
}}),
'Tester.testEquals() complex object inequality'
);
t
.
assert
(
t
.
testEquals
(
function
(
x
){
return
x
;},
function
(
x
){
return
x
;}),
'Tester.testEquals() function equality'
);
t
.
assertNot
(
t
.
testEquals
(
function
(
x
){
return
x
;},
function
(
y
){
return
y
+
2
;}),
'Tester.testEquals() function inequality'
);
t
.
assert
(
t
.
testEquals
([{
a
:
1
,
b
:
2
},
{
c
:
3
,
d
:
4
}],
[{
a
:
1
,
b
:
2
},
{
c
:
3
,
d
:
4
}]),
'Tester.testEquals() arrays of objects'
);
t
.
comment
(
'Tester.sortFiles()'
);
var
testDirRoot
=
fs
.
pathJoin
(
phantom
.
casperPath
,
'tests'
,
'testdir'
);
var
files
=
t
.
findTestFiles
(
testDirRoot
);
...
...
tests/suites/utils.js
View file @
1fded36
...
...
@@ -2,6 +2,34 @@ var utils = require('utils'),
t
=
casper
.
test
,
x
=
require
(
'casper'
).
selectXPath
;
t
.
comment
(
'equals()'
);
(
function
()
{
t
.
comment
(
'Tester.testEquals()'
);
t
.
assert
(
utils
.
equals
(
null
,
null
),
'Tester.testEquals() null equality'
);
t
.
assertNot
(
utils
.
equals
(
null
,
undefined
),
'Tester.testEquals() null vs. undefined inequality'
);
t
.
assert
(
utils
.
equals
(
"hi"
,
"hi"
),
'Tester.testEquals() string equality'
);
t
.
assertNot
(
utils
.
equals
(
"hi"
,
"ih"
),
'Tester.testEquals() string inequality'
);
t
.
assert
(
utils
.
equals
(
5
,
5
),
'Tester.testEquals() number equality'
);
t
.
assertNot
(
utils
.
equals
(
"5"
,
5
),
'Tester.testEquals() number equality without implicit cast'
);
t
.
assert
(
utils
.
equals
(
5
,
5.0
),
'Tester.testEquals() number equality with cast'
);
t
.
assertNot
(
utils
.
equals
(
5
,
10
),
'Tester.testEquals() number inequality'
);
t
.
assert
(
utils
.
equals
([],
[]),
'Tester.testEquals() empty array equality'
);
t
.
assert
(
utils
.
equals
([
1
,
2
],
[
1
,
2
]),
'Tester.testEquals() array equality'
);
t
.
assert
(
utils
.
equals
([
1
,
2
,[
1
,
2
,
function
(){}]],
[
1
,
2
,[
1
,
2
,
function
(){}]]),
'Tester.testEquals() complex array equality'
);
t
.
assertNot
(
utils
.
equals
([
1
,
2
,[
1
,
2
,
function
(
a
){}]],
[
1
,
2
,[
1
,
2
,
function
(
b
){}]]),
'Tester.testEquals() complex array inequality'
);
t
.
assertNot
(
utils
.
equals
([
1
,
2
],
[
2
,
1
]),
'Tester.testEquals() shuffled array inequality'
);
t
.
assertNot
(
utils
.
equals
([
1
,
2
],
[
1
,
2
,
3
]),
'Tester.testEquals() array length inequality'
);
t
.
assert
(
utils
.
equals
({},
{}),
'Tester.testEquals() empty object equality'
);
t
.
assert
(
utils
.
equals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
2
}),
'Tester.testEquals() object length equality'
);
t
.
assert
(
utils
.
equals
({
a
:
1
,
b
:
2
},
{
b
:
2
,
a
:
1
}),
'Tester.testEquals() shuffled object keys equality'
);
t
.
assertNot
(
utils
.
equals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
3
}),
'Tester.testEquals() object inequality'
);
t
.
assert
(
utils
.
equals
({
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}},
{
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}}),
'Tester.testEquals() complex object equality'
);
t
.
assertNot
(
utils
.
equals
({
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
26
}},
{
1
:{
name
:
"bob"
,
age
:
28
},
2
:{
name
:
"john"
,
age
:
27
}}),
'Tester.testEquals() complex object inequality'
);
t
.
assert
(
utils
.
equals
(
function
(
x
){
return
x
;},
function
(
x
){
return
x
;}),
'Tester.testEquals() function equality'
);
t
.
assertNot
(
utils
.
equals
(
function
(
x
){
return
x
;},
function
(
y
){
return
y
+
2
;}),
'Tester.testEquals() function inequality'
);
t
.
assert
(
utils
.
equals
([{
a
:
1
,
b
:
2
},
{
c
:
3
,
d
:
4
}],
[{
a
:
1
,
b
:
2
},
{
c
:
3
,
d
:
4
}]),
'Tester.testEquals() arrays of objects'
);
})();
t
.
comment
(
'fileExt()'
);
(
function
()
{
var
testCases
=
{
...
...
Please
register
or
sign in
to post a comment