Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
MUR Drupal
d3-library
Commits
2831f6c7
Commit
2831f6c7
authored
Mar 14, 2013
by
Mike Bostock
Browse files
Refactor cor tests for minimal loading.
parent
97f034a4
Changes
4
Hide whitespace changes
Inline
Side-by-side
test/core/functor-test.js
View file @
2831f6c7
...
...
@@ -6,18 +6,18 @@ var suite = vows.describe("d3.functor");
suite
.
addBatch
({
"
functor
"
:
{
topic
:
load
(
"
core/functor
"
),
"
when passed a function, returns the function
"
:
function
(
d3
)
{
topic
:
load
(
"
core/functor
"
)
.
expression
(
"
d3.functor
"
)
,
"
when passed a function, returns the function
"
:
function
(
functor
)
{
function
foo
()
{}
assert
.
strictEqual
(
d3
.
functor
(
foo
),
foo
);
assert
.
strictEqual
(
functor
(
foo
),
foo
);
},
"
when passed a non-function, returns a wrapper function
"
:
function
(
d3
)
{
"
when passed a non-function, returns a wrapper function
"
:
function
(
functor
)
{
var
a
=
{};
assert
.
isNull
(
d3
.
functor
(
null
)());
assert
.
isUndefined
(
d3
.
functor
(
undefined
)());
assert
.
strictEqual
(
d3
.
functor
(
a
)(),
a
);
assert
.
strictEqual
(
d3
.
functor
(
1
)(),
1
);
assert
.
deepEqual
(
d3
.
functor
([
1
])(),
[
1
]);
assert
.
isNull
(
functor
(
null
)());
assert
.
isUndefined
(
functor
(
undefined
)());
assert
.
strictEqual
(
functor
(
a
)(),
a
);
assert
.
strictEqual
(
functor
(
1
)(),
1
);
assert
.
deepEqual
(
functor
([
1
])(),
[
1
]);
}
}
});
...
...
test/core/ns-test.js
View file @
2831f6c7
...
...
@@ -6,43 +6,49 @@ var suite = vows.describe("ns");
suite
.
addBatch
({
"
ns
"
:
{
topic
:
load
(
"
core/ns
"
),
topic
:
load
(
"
core/ns
"
)
.
expression
(
"
d3.ns
"
)
,
"
prefix
"
:
{
"
svg is http://www.w3.org/2000/svg
"
:
function
(
d3
)
{
assert
.
equal
(
d3
.
ns
.
prefix
.
svg
,
"
http://www.w3.org/2000/svg
"
)
;
topic
:
function
(
ns
)
{
return
ns
.
prefix
;
},
"
xhtml
is http://www.w3.org/
1999/xhtml
"
:
function
(
d3
)
{
assert
.
equal
(
d3
.
ns
.
prefix
.
xhtml
,
"
http://www.w3.org/
1999/xhtml
"
);
"
svg
is http://www.w3.org/
2000/svg
"
:
function
(
prefix
)
{
assert
.
equal
(
prefix
.
svg
,
"
http://www.w3.org/
2000/svg
"
);
},
"
x
link
is http://www.w3.org/1999/x
link
"
:
function
(
d3
)
{
assert
.
equal
(
d3
.
ns
.
prefix
.
x
link
,
"
http://www.w3.org/1999/x
link
"
);
"
x
html
is http://www.w3.org/1999/x
html
"
:
function
(
prefix
)
{
assert
.
equal
(
prefix
.
x
html
,
"
http://www.w3.org/1999/x
html
"
);
},
"
x
m
l is http://www.w3.org/
XML/1998/namespace
"
:
function
(
d3
)
{
assert
.
equal
(
d3
.
ns
.
prefix
.
x
m
l
,
"
http://www.w3.org/
XML/1998/namespace
"
);
"
xl
ink
is http://www.w3.org/
1999/xlink
"
:
function
(
prefix
)
{
assert
.
equal
(
prefix
.
xl
ink
,
"
http://www.w3.org/
1999/xlink
"
);
},
"
xmlns is http://www.w3.org/2000/xmlns/
"
:
function
(
d3
)
{
assert
.
equal
(
d3
.
ns
.
prefix
.
xmlns
,
"
http://www.w3.org/2000/xmlns/
"
);
"
xml is http://www.w3.org/XML/1998/namespace
"
:
function
(
prefix
)
{
assert
.
equal
(
prefix
.
xml
,
"
http://www.w3.org/XML/1998/namespace
"
);
},
"
xmlns is http://www.w3.org/2000/xmlns/
"
:
function
(
prefix
)
{
assert
.
equal
(
prefix
.
xmlns
,
"
http://www.w3.org/2000/xmlns/
"
);
}
},
"
qualify
"
:
{
"
local name returns name
"
:
function
(
d3
)
{
assert
.
equal
(
d3
.
ns
.
qualify
(
"
local
"
),
"
local
"
);
topic
:
function
(
ns
)
{
return
ns
.
qualify
;
},
"
local name returns name
"
:
function
(
qualify
)
{
assert
.
equal
(
qualify
(
"
local
"
),
"
local
"
);
},
"
known qualified name returns space and local
"
:
function
(
d3
)
{
var
name
=
d3
.
ns
.
qualify
(
"
svg:path
"
);
"
known qualified name returns space and local
"
:
function
(
qualify
)
{
var
name
=
qualify
(
"
svg:path
"
);
assert
.
equal
(
name
.
space
,
"
http://www.w3.org/2000/svg
"
);
assert
.
equal
(
name
.
local
,
"
path
"
);
},
"
unknown qualified name returns name
"
:
function
(
d3
)
{
assert
.
equal
(
d3
.
ns
.
qualify
(
"
foo:bar
"
),
"
bar
"
);
"
unknown qualified name returns name
"
:
function
(
qualify
)
{
assert
.
equal
(
qualify
(
"
foo:bar
"
),
"
bar
"
);
},
"
known local name returns space and local
"
:
function
(
d3
)
{
var
name
=
d3
.
ns
.
qualify
(
"
svg
"
);
"
known local name returns space and local
"
:
function
(
qualify
)
{
var
name
=
qualify
(
"
svg
"
);
assert
.
equal
(
name
.
space
,
"
http://www.w3.org/2000/svg
"
);
assert
.
equal
(
name
.
local
,
"
svg
"
);
},
"
names that collide with built-ins are ignored
"
:
function
(
d3
)
{
assert
.
equal
(
d3
.
ns
.
qualify
(
"
hasOwnProperty:test
"
),
"
test
"
);
"
names that collide with built-ins are ignored
"
:
function
(
qualify
)
{
assert
.
equal
(
qualify
(
"
hasOwnProperty:test
"
),
"
test
"
);
}
}
}
...
...
test/core/rebind-test.js
View file @
2831f6c7
...
...
@@ -6,43 +6,43 @@ var suite = vows.describe("d3.rebind");
suite
.
addBatch
({
"
rebind
"
:
{
topic
:
load
(
"
core/rebind
"
),
"
source function always has source as context
"
:
function
(
d
3
)
{
topic
:
load
(
"
core/rebind
"
)
.
expression
(
"
d3.rebind
"
)
,
"
source function always has source as context
"
:
function
(
rebin
d
)
{
var
target
=
{},
source
=
{
method
:
function
()
{
that
=
this
;
}},
that
;
d3
.
rebind
(
target
,
source
,
"
method
"
);
rebind
(
target
,
source
,
"
method
"
);
assert
.
strictEqual
((
target
.
method
(),
that
),
source
);
assert
.
strictEqual
((
target
.
method
.
call
({}),
that
),
source
);
},
"
source function receives target function's arguments
"
:
function
(
d
3
)
{
"
source function receives target function's arguments
"
:
function
(
rebin
d
)
{
var
target
=
{},
source
=
{
method
:
function
()
{
those
=
Array
.
prototype
.
slice
.
call
(
arguments
);
}},
those
;
d3
.
rebind
(
target
,
source
,
"
method
"
);
rebind
(
target
,
source
,
"
method
"
);
assert
.
deepEqual
((
target
.
method
(),
those
),
[]);
assert
.
deepEqual
((
target
.
method
(
1
),
those
),
[
1
]);
assert
.
deepEqual
((
target
.
method
(
null
),
those
),
[
null
]);
assert
.
deepEqual
((
target
.
method
(
source
,
source
,
1
),
those
),
[
source
,
source
,
1
]);
},
"
target function returns target if source function returns source
"
:
function
(
d
3
)
{
"
target function returns target if source function returns source
"
:
function
(
rebin
d
)
{
var
target
=
{},
source
=
{
method
:
function
(
value
)
{
return
value
?
source
:
42
;
}};
d3
.
rebind
(
target
,
source
,
"
method
"
);
rebind
(
target
,
source
,
"
method
"
);
assert
.
strictEqual
(
target
.
method
(
true
),
target
);
},
"
otherwise, target function returns source function return value
"
:
function
(
d
3
)
{
"
otherwise, target function returns source function return value
"
:
function
(
rebin
d
)
{
var
target
=
{},
source
=
{
method
:
function
(
value
)
{
return
value
?
source
:
42
;
}};
d3
.
rebind
(
target
,
source
,
"
method
"
);
rebind
(
target
,
source
,
"
method
"
);
assert
.
strictEqual
(
target
.
method
(
false
),
42
);
},
"
can bind multiple methods
"
:
function
(
d
3
)
{
"
can bind multiple methods
"
:
function
(
rebin
d
)
{
var
target
=
{},
source
=
{
foo
:
function
()
{
return
1
;
},
bar
:
function
()
{
return
2
;
}
};
d3
.
rebind
(
target
,
source
,
"
foo
"
,
"
bar
"
);
rebind
(
target
,
source
,
"
foo
"
,
"
bar
"
);
assert
.
strictEqual
(
target
.
foo
(),
1
);
assert
.
strictEqual
(
target
.
bar
(),
2
);
},
"
returns the target object
"
:
function
(
d
3
)
{
"
returns the target object
"
:
function
(
rebin
d
)
{
var
target
=
{},
source
=
{
foo
:
function
()
{}};
assert
.
strictEqual
(
d3
.
rebind
(
target
,
source
,
"
foo
"
),
target
);
assert
.
strictEqual
(
rebind
(
target
,
source
,
"
foo
"
),
target
);
}
}
});
...
...
test/core/version-test.js
View file @
2831f6c7
...
...
@@ -6,9 +6,9 @@ var suite = vows.describe("d3.version");
suite
.
addBatch
({
"
version
"
:
{
topic
:
load
(),
"
has the form major.minor.patch
"
:
function
(
d3
)
{
assert
.
match
(
d3
.
version
,
/^
[
0-9
]
+
\.[
0-9
]
+
\.[
0-9
]
+/
);
topic
:
load
()
.
expression
(
"
d3.version
"
)
,
"
has the form major.minor.patch
"
:
function
(
version
)
{
assert
.
match
(
version
,
/^
[
0-9
]
+
\.[
0-9
]
+
\.[
0-9
]
+/
);
}
}
});
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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