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
541fba3d
...
541fba3dcbdea007945e0bf51a222d10c377472d
authored
2012-10-19 21:39:16 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixed broken utils.cleanUrl()
1 parent
8fc28ab6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
27 deletions
modules/utils.js
tests/suites/utils.js
modules/utils.js
View file @
541fba3
...
...
@@ -57,11 +57,16 @@
* @return String
*/
function
cleanUrl
(
url
)
{
var
match
=
/
(
https
?)
:
\/\/(
.*
)
/i
.
exec
(
url
);
if
(
!
match
||
match
.
length
!==
3
)
{
var
parts
=
/
(
https
?)
:
\/\/(
.*
)
/i
.
exec
(
url
);
if
(
!
parts
)
{
return
url
;
}
return
format
(
"%s://%s/"
,
match
[
1
],
match
[
2
]);
// notice the trailing slash
var
protocol
=
parts
[
1
];
var
subparts
=
parts
[
2
].
split
(
'/'
);
if
(
subparts
.
length
===
1
)
{
return
format
(
"%s://%s/"
,
protocol
,
subparts
[
0
]);
}
return
url
;
}
exports
.
cleanUrl
=
cleanUrl
;
...
...
tests/suites/utils.js
View file @
541fba3
...
...
@@ -13,35 +13,39 @@ t.comment('cleanUrl()');
'https://google.com'
:
'https://google.com/'
,
'https://www.google.com/'
:
'https://www.google.com/'
,
'https://www.google.com/?plop=2'
:
'https://www.google.com/?plop=2'
,
'file:///Users/toto/toto.html'
:
'file:///Users/toto/toto.html'
'file:///Users/toto/toto.html'
:
'file:///Users/toto/toto.html'
,
'/100'
:
'/100'
};
for
(
var
testCase
in
testCases
)
{
t
.
assertEquals
(
utils
.
cleanUrl
(
testCase
),
testCases
[
testCase
],
'cleanUrl() cleans an URL'
);
}
})();
t
.
comment
(
'equals()'
);
(
function
()
{
t
.
assert
(
utils
.
equals
(
null
,
null
),
'
Tester.testE
quals() null equality'
);
t
.
assertNot
(
utils
.
equals
(
null
,
undefined
),
'
Tester.testE
quals() null vs. undefined inequality'
);
t
.
assert
(
utils
.
equals
(
"hi"
,
"hi"
),
'
Tester.testE
quals() string equality'
);
t
.
assertNot
(
utils
.
equals
(
"hi"
,
"ih"
),
'
Tester.testE
quals() string inequality'
);
t
.
assert
(
utils
.
equals
(
5
,
5
),
'
Tester.testE
quals() number equality'
);
t
.
assertNot
(
utils
.
equals
(
"5"
,
5
),
'
Tester.testE
quals() number equality without implicit cast'
);
t
.
assert
(
utils
.
equals
(
5
,
5.0
),
'
Tester.testE
quals() number equality with cast'
);
t
.
assertNot
(
utils
.
equals
(
5
,
10
),
'
Tester.testE
quals() number inequality'
);
t
.
assert
(
utils
.
equals
([],
[]),
'
Tester.testE
quals() empty array equality'
);
t
.
assert
(
utils
.
equals
([
1
,
2
],
[
1
,
2
]),
'
Tester.testE
quals() array equality'
);
t
.
assert
(
utils
.
equals
([
1
,
2
,[
1
,
2
,
function
(){}]],
[
1
,
2
,[
1
,
2
,
function
(){}]]),
'
Tester.testE
quals() complex array equality'
);
t
.
assertNot
(
utils
.
equals
([
1
,
2
,[
1
,
2
,
function
(
a
){}]],
[
1
,
2
,[
1
,
2
,
function
(
b
){}]]),
'
Tester.testE
quals() complex array inequality'
);
t
.
assertNot
(
utils
.
equals
([
1
,
2
],
[
2
,
1
]),
'
Tester.testE
quals() shuffled array inequality'
);
t
.
assertNot
(
utils
.
equals
([
1
,
2
],
[
1
,
2
,
3
]),
'
Tester.testE
quals() array length inequality'
);
t
.
assert
(
utils
.
equals
({},
{}),
'
Tester.testE
quals() empty object equality'
);
t
.
assert
(
utils
.
equals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
2
}),
'
Tester.testE
quals() object length equality'
);
t
.
assert
(
utils
.
equals
({
a
:
1
,
b
:
2
},
{
b
:
2
,
a
:
1
}),
'
Tester.testE
quals() shuffled object keys equality'
);
t
.
assertNot
(
utils
.
equals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
3
}),
'
Tester.testE
quals() 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.testE
quals() 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.testE
quals() complex object inequality'
);
t
.
assert
(
utils
.
equals
(
function
(
x
){
return
x
;},
function
(
x
){
return
x
;}),
'
Tester.testE
quals() function equality'
);
t
.
assertNot
(
utils
.
equals
(
function
(
x
){
return
x
;},
function
(
y
){
return
y
+
2
;}),
'
Tester.testE
quals() function inequality'
);
t
.
assert
(
utils
.
equals
([{
a
:
1
,
b
:
2
},
{
c
:
3
,
d
:
4
}],
[{
a
:
1
,
b
:
2
},
{
c
:
3
,
d
:
4
}]),
'
Tester.testE
quals() arrays of objects'
);
t
.
assert
(
utils
.
equals
(
null
,
null
),
'
e
quals() null equality'
);
t
.
assertNot
(
utils
.
equals
(
null
,
undefined
),
'
e
quals() null vs. undefined inequality'
);
t
.
assert
(
utils
.
equals
(
"hi"
,
"hi"
),
'
e
quals() string equality'
);
t
.
assertNot
(
utils
.
equals
(
"hi"
,
"ih"
),
'
e
quals() string inequality'
);
t
.
assert
(
utils
.
equals
(
5
,
5
),
'
e
quals() number equality'
);
t
.
assertNot
(
utils
.
equals
(
"5"
,
5
),
'
e
quals() number equality without implicit cast'
);
t
.
assert
(
utils
.
equals
(
5
,
5.0
),
'
e
quals() number equality with cast'
);
t
.
assertNot
(
utils
.
equals
(
5
,
10
),
'
e
quals() number inequality'
);
t
.
assert
(
utils
.
equals
([],
[]),
'
e
quals() empty array equality'
);
t
.
assert
(
utils
.
equals
([
1
,
2
],
[
1
,
2
]),
'
e
quals() array equality'
);
t
.
assert
(
utils
.
equals
([
1
,
2
,[
1
,
2
,
function
(){}]],
[
1
,
2
,[
1
,
2
,
function
(){}]]),
'
e
quals() complex array equality'
);
t
.
assertNot
(
utils
.
equals
([
1
,
2
,[
1
,
2
,
function
(
a
){}]],
[
1
,
2
,[
1
,
2
,
function
(
b
){}]]),
'
e
quals() complex array inequality'
);
t
.
assertNot
(
utils
.
equals
([
1
,
2
],
[
2
,
1
]),
'
e
quals() shuffled array inequality'
);
t
.
assertNot
(
utils
.
equals
([
1
,
2
],
[
1
,
2
,
3
]),
'
e
quals() array length inequality'
);
t
.
assert
(
utils
.
equals
({},
{}),
'
e
quals() empty object equality'
);
t
.
assert
(
utils
.
equals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
2
}),
'
e
quals() object length equality'
);
t
.
assert
(
utils
.
equals
({
a
:
1
,
b
:
2
},
{
b
:
2
,
a
:
1
}),
'
e
quals() shuffled object keys equality'
);
t
.
assertNot
(
utils
.
equals
({
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
3
}),
'
e
quals() 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
}}),
'
e
quals() 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
}}),
'
e
quals() complex object inequality'
);
t
.
assert
(
utils
.
equals
(
function
(
x
){
return
x
;},
function
(
x
){
return
x
;}),
'
e
quals() function equality'
);
t
.
assertNot
(
utils
.
equals
(
function
(
x
){
return
x
;},
function
(
y
){
return
y
+
2
;}),
'
e
quals() function inequality'
);
t
.
assert
(
utils
.
equals
([{
a
:
1
,
b
:
2
},
{
c
:
3
,
d
:
4
}],
[{
a
:
1
,
b
:
2
},
{
c
:
3
,
d
:
4
}]),
'
e
quals() arrays of objects'
);
})();
t
.
comment
(
'fileExt()'
);
...
...
Please
register
or
sign in
to post a comment