Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MUR Drupal
d3-library
Commits
608902c9
Commit
608902c9
authored
Mar 13, 2013
by
Mike Bostock
Browse files
Checkpoint test refactoring.
parent
3442685b
Changes
88
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
802 additions
and
779 deletions
+802
-779
d3.js
d3.js
+424
-424
d3.min.js
d3.min.js
+5
-5
package.json
package.json
+1
-1
src/behavior/zoom.js
src/behavior/zoom.js
+2
-2
src/dsv/csv.js
src/dsv/csv.js
+2
-0
src/dsv/dsv.js
src/dsv/dsv.js
+3
-0
src/dsv/tsv.js
src/dsv/tsv.js
+2
-0
src/geo/clip-view.js
src/geo/clip-view.js
+1
-0
src/geo/clip.js
src/geo/clip.js
+1
-0
src/geo/conic-equidistant.js
src/geo/conic-equidistant.js
+1
-0
src/geo/path.js
src/geo/path.js
+5
-0
src/geo/rotation.js
src/geo/rotation.js
+1
-0
src/geom/voronoi.js
src/geom/voronoi.js
+1
-0
src/layout/voronoi.js
src/layout/voronoi.js
+1
-0
src/selection/on.js
src/selection/on.js
+2
-1
test/dsv/csv-test.js
test/dsv/csv-test.js
+183
-173
test/dsv/tsv-test.js
test/dsv/tsv-test.js
+166
-156
test/env-fragment.js
test/env-fragment.js
+0
-8
test/env-xhr.js
test/env-xhr.js
+1
-1
test/env.js
test/env.js
+0
-8
No files found.
d3.js
View file @
608902c9
This diff is collapsed.
Click to expand it.
d3.min.js
View file @
608902c9
This source diff could not be displayed because it is too large. You can
view the blob
instead.
package.json
View file @
608902c9
...
...
@@ -31,7 +31,7 @@
"
jsdom
"
:
"
~0.5.2
"
},
"devDependencies"
:
{
"
smash
"
:
"
~0.0.
5
"
,
"
smash
"
:
"
~0.0.
7
"
,
"
uglify-js
"
:
"
2.2.x
"
,
"
vows
"
:
"
0.7.x
"
},
...
...
src/behavior/zoom.js
View file @
608902c9
...
...
@@ -184,6 +184,6 @@ var d3_behavior_zoomInfinity = [0, Infinity]; // default scale extent
// https://developer.mozilla.org/en-US/docs/Mozilla_event_reference/wheel
var
d3_behavior_zoomDelta
,
d3_behavior_zoomWheel
=
"
onwheel
"
in
document
?
(
d3_behavior_zoomDelta
=
function
()
{
return
-
d3
.
event
.
deltaY
*
(
d3
.
event
.
deltaMode
?
120
:
1
);
},
"
wheel
"
)
:
"
onmousewheel
"
in
document
?
(
d3_behavior_zoomDelta
=
function
()
{
return
d3
.
event
.
wheelDelta
;
},
"
mousewheel
"
)
=
"
onwheel
"
in
d3_
document
?
(
d3_behavior_zoomDelta
=
function
()
{
return
-
d3
.
event
.
deltaY
*
(
d3
.
event
.
deltaMode
?
120
:
1
);
},
"
wheel
"
)
:
"
onmousewheel
"
in
d3_
document
?
(
d3_behavior_zoomDelta
=
function
()
{
return
d3
.
event
.
wheelDelta
;
},
"
mousewheel
"
)
:
(
d3_behavior_zoomDelta
=
function
()
{
return
-
d3
.
event
.
detail
;
},
"
MozMousePixelScroll
"
);
src/dsv/csv.js
View file @
608902c9
import
"
dsv
"
;
d3
.
csv
=
d3_dsv
(
"
,
"
,
"
text/csv
"
);
src/dsv/dsv.js
View file @
608902c9
import
"
../arrays/set
"
;
import
"
../xhr/xhr
"
;
function
d3_dsv
(
delimiter
,
mimeType
)
{
var
reFormat
=
new
RegExp
(
"
[
\"
"
+
delimiter
+
"
\n
]
"
),
delimiterCode
=
delimiter
.
charCodeAt
(
0
);
...
...
src/dsv/tsv.js
View file @
608902c9
import
"
dsv
"
;
d3
.
tsv
=
d3_dsv
(
"
\t
"
,
"
text/tab-separated-values
"
);
src/geo/clip-view.js
View file @
608902c9
import
"
../arrays/merge
"
;
import
"
../math/trigonometry
"
;
import
"
clip
"
;
import
"
clip-polygon
"
;
...
...
src/geo/clip.js
View file @
608902c9
import
"
../arrays/merge
"
;
import
"
../core/noop
"
;
import
"
../math/trigonometry
"
;
import
"
clip-polygon
"
;
...
...
src/geo/conic-equidistant.js
View file @
608902c9
import
"
../math/trigonometry
"
;
import
"
conic
"
;
import
"
equirectangular
"
;
import
"
geo
"
;
import
"
projection
"
;
...
...
src/geo/path.js
View file @
608902c9
import
"
../core/identity
"
;
import
"
../math/trigonometry
"
;
import
"
albers-usa
"
;
import
"
area
"
;
import
"
bounds
"
;
import
"
centroid
"
;
import
"
geo
"
;
import
"
path-area
"
;
import
"
path-buffer
"
;
import
"
path-centroid
"
;
import
"
path-context
"
;
import
"
projection
"
;
import
"
resample
"
;
import
"
stream
"
;
...
...
src/geo/rotation.js
View file @
608902c9
import
"
../math/trigonometry
"
;
import
"
equirectangular
"
;
import
"
geo
"
;
d3
.
geo
.
rotation
=
function
(
rotate
)
{
...
...
src/geom/voronoi.js
View file @
608902c9
import
"
../arrays/range
"
;
import
"
../math/trigonometry
"
;
import
"
geom
"
;
// Adapted from Nicolas Garcia Belmonte's JIT implementation:
...
...
src/layout/voronoi.js
View file @
608902c9
import
"
../core/functor
"
;
import
"
../geom/polygon
"
;
import
"
../geom/voronoi
"
;
import
"
../svg/line
"
;
import
"
layout
"
;
...
...
src/selection/on.js
View file @
608902c9
import
"
../core/array
"
;
import
"
../core/document
"
;
import
"
selection
"
;
d3_selectionPrototype
.
on
=
function
(
type
,
listener
,
capture
)
{
...
...
@@ -72,7 +73,7 @@ var d3_selection_onFilters = d3.map({
});
d3_selection_onFilters
.
forEach
(
function
(
k
)
{
if
(
"
on
"
+
k
in
document
)
d3_selection_onFilters
.
remove
(
k
);
if
(
"
on
"
+
k
in
d3_
document
)
d3_selection_onFilters
.
remove
(
k
);
});
function
d3_selection_onListener
(
listener
,
argumentz
)
{
...
...
test/dsv/csv-test.js
View file @
608902c9
require
(
"
../env
"
);
var
vows
=
require
(
"
vows
"
),
load
=
require
(
"
../load
"
),
xhr
=
require
(
"
../env-xhr
"
),
assert
=
require
(
"
../env-assert
"
);
var
suite
=
vows
.
describe
(
"
d3.csv
"
);
suite
.
addBatch
({
"
csv
"
:
{
topic
:
function
()
{
var
cb
=
this
.
callback
;
d3
.
csv
(
"
test/data/sample.csv
"
,
function
(
error
,
csv
)
{
cb
(
null
,
csv
);
});
},
"
invokes the callback with the parsed CSV
"
:
function
(
csv
)
{
assert
.
deepEqual
(
csv
,
[{
"
Hello
"
:
"
42
"
,
"
World
"
:
"
\"
fish
\"
"
}]);
},
"
overrides the mime type to text/csv
"
:
function
(
csv
)
{
assert
.
equal
(
XMLHttpRequest
.
_last
.
_info
.
mimeType
,
"
text/csv
"
);
topic
:
load
(
"
dsv/csv
"
).
sandbox
({
XMLHttpRequest
:
xhr
,
document
:
{},
window
:
{}
}),
"
on a sample file
"
:
{
topic
:
function
(
d3
)
{
var
cb
=
this
.
callback
;
d3
.
csv
(
"
test/data/sample.csv
"
,
function
(
error
,
csv
)
{
cb
(
null
,
csv
);
});
},
"
invokes the callback with the parsed CSV
"
:
function
(
csv
)
{
assert
.
deepEqual
(
csv
,
[{
"
Hello
"
:
"
42
"
,
"
World
"
:
"
\"
fish
\"
"
}]);
},
"
overrides the mime type to text/csv
"
:
function
(
csv
)
{
assert
.
equal
(
xhr
.
_last
.
_info
.
mimeType
,
"
text/csv
"
);
}
},
"
specifying a row conversion function
"
:
{
topic
:
function
()
{
"
when specifying a row conversion function
"
:
{
topic
:
function
(
d3
)
{
var
cb
=
this
.
callback
;
d3
.
csv
(
"
test/data/sample.csv
"
,
function
(
row
)
{
row
.
Hello
=
-
row
.
Hello
;
...
...
@@ -33,8 +42,9 @@ suite.addBatch({
assert
.
strictEqual
(
csv
[
0
].
Hello
,
-
42
);
}
},
"
attempting to load a file that does not exist
"
:
{
topic
:
function
()
{
"
when loading a file that does not exist
"
:
{
topic
:
function
(
d3
)
{
var
cb
=
this
.
callback
;
d3
.
csv
(
"
//does/not/exist.csv
"
,
function
(
error
,
csv
)
{
cb
(
null
,
csv
);
...
...
@@ -43,171 +53,171 @@ suite.addBatch({
"
invokes the callback with undefined
"
:
function
(
csv
)
{
assert
.
isUndefined
(
csv
);
}
}
},
"
parse
"
:
{
topic
:
function
()
{
return
d3
.
csv
.
parse
;
},
"
returns an array of objects
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n
1,2,3
\n
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
},
"
does not strip whitespace
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n
1, 2,3
\n
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
},
"
parses quoted values
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n\"
1
\"
,2,3
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
assert
.
deepEqual
(
parse
(
"
a,b,c
\n\"
1
\"
,2,3
\n
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
},
"
parses quoted values with quotes
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a
\n\"\"\"
hello
\"\"\"
"
),
[{
a
:
"
\"
hello
\"
"
}]);
},
"
parses quoted values with newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a
\n\"
new
\n
line
\"
"
),
[{
a
:
"
new
\n
line
"
}]);
assert
.
deepEqual
(
parse
(
"
a
\n\"
new
\r
line
\"
"
),
[{
a
:
"
new
\r
line
"
}]);
assert
.
deepEqual
(
parse
(
"
a
\n\"
new
\r\n
line
\"
"
),
[{
a
:
"
new
\r\n
line
"
}]);
},
"
parses unix newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n
1,2,3
\n
4,5,
\"
6
\"\n
7,8,9
"
),
[
{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
},
{
a
:
"
4
"
,
b
:
"
5
"
,
c
:
"
6
"
},
{
a
:
"
7
"
,
b
:
"
8
"
,
c
:
"
9
"
}
]);
},
"
parses mac newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\r
1,2,3
\r
4,5,
\"
6
\"\r
7,8,9
"
),
[
{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
},
{
a
:
"
4
"
,
b
:
"
5
"
,
c
:
"
6
"
},
{
a
:
"
7
"
,
b
:
"
8
"
,
c
:
"
9
"
}
]);
},
"
parses dos newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\r\n
1,2,3
\r\n
4,5,
\"
6
\"\r\n
7,8,9
"
),
[
{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
},
{
a
:
"
4
"
,
b
:
"
5
"
,
c
:
"
6
"
},
{
a
:
"
7
"
,
b
:
"
8
"
,
c
:
"
9
"
}
]);
}
},
"
parse with row function
"
:
{
"
invokes the row function for every row in order
"
:
function
()
{
var
rows
=
[];
d3
.
csv
.
parse
(
"
a
\n
1
\n
2
\n
3
\n
4
"
,
function
(
d
,
i
)
{
rows
.
push
({
d
:
d
,
i
:
i
});
});
assert
.
deepEqual
(
rows
,
[
{
d
:
{
a
:
"
1
"
},
i
:
0
},
{
d
:
{
a
:
"
2
"
},
i
:
1
},
{
d
:
{
a
:
"
3
"
},
i
:
2
},
{
d
:
{
a
:
"
4
"
},
i
:
3
}
]);
},
"
returns an array of the row function return values
"
:
function
()
{
assert
.
deepEqual
(
d3
.
csv
.
parse
(
"
a,b,c
\n
1,2,3
\n
"
,
function
(
row
)
{
return
row
;
}),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
"
parse
"
:
{
topic
:
function
(
d3
)
{
return
d3
.
csv
.
parse
;
},
"
returns an array of objects
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n
1,2,3
\n
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
},
"
does not strip whitespace
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n
1, 2,3
\n
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
},
"
parses quoted values
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n\"
1
\"
,2,3
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
assert
.
deepEqual
(
parse
(
"
a,b,c
\n\"
1
\"
,2,3
\n
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
},
"
parses quoted values with quotes
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a
\n\"\"\"
hello
\"\"\"
"
),
[{
a
:
"
\"
hello
\"
"
}]);
},
"
parses quoted values with newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a
\n\"
new
\n
line
\"
"
),
[{
a
:
"
new
\n
line
"
}]);
assert
.
deepEqual
(
parse
(
"
a
\n\"
new
\r
line
\"
"
),
[{
a
:
"
new
\r
line
"
}]);
assert
.
deepEqual
(
parse
(
"
a
\n\"
new
\r\n
line
\"
"
),
[{
a
:
"
new
\r\n
line
"
}]);
},
"
parses unix newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n
1,2,3
\n
4,5,
\"
6
\"\n
7,8,9
"
),
[
{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
},
{
a
:
"
4
"
,
b
:
"
5
"
,
c
:
"
6
"
},
{
a
:
"
7
"
,
b
:
"
8
"
,
c
:
"
9
"
}
]);
},
"
parses mac newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\r
1,2,3
\r
4,5,
\"
6
\"\r
7,8,9
"
),
[
{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
},
{
a
:
"
4
"
,
b
:
"
5
"
,
c
:
"
6
"
},
{
a
:
"
7
"
,
b
:
"
8
"
,
c
:
"
9
"
}
]);
},
"
parses dos newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\r\n
1,2,3
\r\n
4,5,
\"
6
\"\r\n
7,8,9
"
),
[
{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
},
{
a
:
"
4
"
,
b
:
"
5
"
,
c
:
"
6
"
},
{
a
:
"
7
"
,
b
:
"
8
"
,
c
:
"
9
"
}
]);
}
},
"
skips rows if the row function returns null or undefined
"
:
function
()
{
assert
.
deepEqual
(
d3
.
csv
.
parse
(
"
a,b,c
\n
1,2,3
\n
2,3,4
"
,
function
(
row
)
{
return
row
.
a
&
1
?
null
:
row
;
}),
[{
a
:
"
2
"
,
b
:
"
3
"
,
c
:
"
4
"
}]);
assert
.
deepEqual
(
d3
.
csv
.
parse
(
"
a,b,c
\n
1,2,3
\n
2,3,4
"
,
function
(
row
)
{
return
row
.
a
&
1
?
undefined
:
row
;
}),
[{
a
:
"
2
"
,
b
:
"
3
"
,
c
:
"
4
"
}]);
}
},
"
parseRows
"
:
{
topic
:
function
()
{
return
d3
.
csv
.
parseRows
;
},
"
returns an array of arrays
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n
"
),
[[
"
a
"
,
"
b
"
,
"
c
"
]]);
},
"
parses quoted values
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
\"
1
\"
,2,3
\n
"
),
[[
"
1
"
,
"
2
"
,
"
3
"
]]);
assert
.
deepEqual
(
parse
(
"
\"
hello
\"
"
),
[[
"
hello
"
]]);
},
"
parses quoted values with quotes
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
\"\"\"
hello
\"\"\"
"
),
[[
"
\"
hello
\"
"
]]);
},
"
parses quoted values with newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
\"
new
\n
line
\"
"
),
[[
"
new
\n
line
"
]]);
assert
.
deepEqual
(
parse
(
"
\"
new
\r
line
\"
"
),
[[
"
new
\r
line
"
]]);
assert
.
deepEqual
(
parse
(
"
\"
new
\r\n
line
\"
"
),
[[
"
new
\r\n
line
"
]]);
},
"
parses unix newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n
1,2,3
\n
4,5,
\"
6
\"\n
7,8,9
"
),
[
[
"
a
"
,
"
b
"
,
"
c
"
],
[
"
1
"
,
"
2
"
,
"
3
"
],
[
"
4
"
,
"
5
"
,
"
6
"
],
[
"
7
"
,
"
8
"
,
"
9
"
]
]);
},
"
parses mac newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\r
1,2,3
\r
4,5,
\"
6
\"\r
7,8,9
"
),
[
[
"
a
"
,
"
b
"
,
"
c
"
],
[
"
1
"
,
"
2
"
,
"
3
"
],
[
"
4
"
,
"
5
"
,
"
6
"
],
[
"
7
"
,
"
8
"
,
"
9
"
]
]);
"
parse with row function
"
:
{
"
invokes the row function for every row in order
"
:
function
(
d3
)
{
var
rows
=
[];
d3
.
csv
.
parse
(
"
a
\n
1
\n
2
\n
3
\n
4
"
,
function
(
d
,
i
)
{
rows
.
push
({
d
:
d
,
i
:
i
});
});
assert
.
deepEqual
(
rows
,
[
{
d
:
{
a
:
"
1
"
},
i
:
0
},
{
d
:
{
a
:
"
2
"
},
i
:
1
},
{
d
:
{
a
:
"
3
"
},
i
:
2
},
{
d
:
{
a
:
"
4
"
},
i
:
3
}
]);
},
"
returns an array of the row function return values
"
:
function
(
d3
)
{
assert
.
deepEqual
(
d3
.
csv
.
parse
(
"
a,b,c
\n
1,2,3
\n
"
,
function
(
row
)
{
return
row
;
}),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
},
"
skips rows if the row function returns null or undefined
"
:
function
(
d3
)
{
assert
.
deepEqual
(
d3
.
csv
.
parse
(
"
a,b,c
\n
1,2,3
\n
2,3,4
"
,
function
(
row
)
{
return
row
.
a
&
1
?
null
:
row
;
}),
[{
a
:
"
2
"
,
b
:
"
3
"
,
c
:
"
4
"
}]);
assert
.
deepEqual
(
d3
.
csv
.
parse
(
"
a,b,c
\n
1,2,3
\n
2,3,4
"
,
function
(
row
)
{
return
row
.
a
&
1
?
undefined
:
row
;
}),
[{
a
:
"
2
"
,
b
:
"
3
"
,
c
:
"
4
"
}]);
}
},
"
parses dos newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\r\n
1,2,3
\r\n
4,5,
\"
6
\"\r\n
7,8,9
"
),
[
[
"
a
"
,
"
b
"
,
"
c
"
],
[
"
1
"
,
"
2
"
,
"
3
"
],
[
"
4
"
,
"
5
"
,
"
6
"
],
[
"
7
"
,
"
8
"
,
"
9
"
]
]);
}
},
"
format
"
:
{
topic
:
function
()
{
return
d3
.
csv
.
format
;
},
"
takes an array of objects as input
"
:
function
(
format
)
{
assert
.
equal
(
format
([{
a
:
1
,
b
:
2
,
c
:
3
}]),
"
a,b,c
\n
1,2,3
"
);
},
"
escapes field names containing special characters
"
:
function
(
format
)
{
assert
.
equal
(
format
([{
"
foo,bar
"
:
true
}]),
"
\"
foo,bar
\"\n
true
"
);
},
"
computes the union of all fields
"
:
function
(
format
)
{
assert
.
equal
(
format
([
{
a
:
1
},
{
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
2
,
c
:
3
},
{
b
:
1
,
c
:
2
},
{
c
:
1
}
]),
"
a,b,c
\n
1,,
\n
1,2,
\n
1,2,3
\n
,1,2
\n
,,1
"
);
"
parseRows
"
:
{
topic
:
function
(
d3
)
{
return
d3
.
csv
.
parseRows
;
},
"
returns an array of arrays
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n
"
),
[[
"
a
"
,
"
b
"
,
"
c
"
]]);
},
"
parses quoted values
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
\"
1
\"
,2,3
\n
"
),
[[
"
1
"
,
"
2
"
,
"
3
"
]]);
assert
.
deepEqual
(
parse
(
"
\"
hello
\"
"
),
[[
"
hello
"
]]);
},
"
parses quoted values with quotes
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
\"\"\"
hello
\"\"\"
"
),
[[
"
\"
hello
\"
"
]]);
},
"
parses quoted values with newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
\"
new
\n
line
\"
"
),
[[
"
new
\n
line
"
]]);
assert
.
deepEqual
(
parse
(
"
\"
new
\r
line
\"
"
),
[[
"
new
\r
line
"
]]);
assert
.
deepEqual
(
parse
(
"
\"
new
\r\n
line
\"
"
),
[[
"
new
\r\n
line
"
]]);
},
"
parses unix newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\n
1,2,3
\n
4,5,
\"
6
\"\n
7,8,9
"
),
[
[
"
a
"
,
"
b
"
,
"
c
"
],
[
"
1
"
,
"
2
"
,
"
3
"
],
[
"
4
"
,
"
5
"
,
"
6
"
],
[
"
7
"
,
"
8
"
,
"
9
"
]
]);
},
"
parses mac newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\r
1,2,3
\r
4,5,
\"
6
\"\r
7,8,9
"
),
[
[
"
a
"
,
"
b
"
,
"
c
"
],
[
"
1
"
,
"
2
"
,
"
3
"
],
[
"
4
"
,
"
5
"
,
"
6
"
],
[
"
7
"
,
"
8
"
,
"
9
"
]
]);
},
"
parses dos newlines
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a,b,c
\r\n
1,2,3
\r\n
4,5,
\"
6
\"\r\n
7,8,9
"
),
[
[
"
a
"
,
"
b
"
,
"
c
"
],
[
"
1
"
,
"
2
"
,
"
3
"
],
[
"
4
"
,
"
5
"
,
"
6
"
],
[
"
7
"
,
"
8
"
,
"
9
"
]
]);
}
},
"
orders field by first-seen
"
:
function
(
format
)
{
assert
.
equal
(
format
([
{
a
:
1
,
b
:
2
},
{
c
:
3
,
b
:
4
},
{
c
:
5
,
a
:
1
,
b
:
2
}
]),
"
a,b,c
\n
1,2,
\n
,4,3
\n
1,2,5
"
);
}
},
"
formatRows
"
:
{
topic
:
function
()
{
return
d3
.
csv
.
formatRows
;
},
"
takes an array of arrays as input
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
a
"
,
"
b
"
,
"
c
"
],
[
"
1
"
,
"
2
"
,
"
3
"
]]),
"
a,b,c
\n
1,2,3
"
);
},
"
separates lines using unix newline
"
:
function
(
format
)
{
assert
.
equal
(
format
([[],
[]]),
"
\n
"
);
},
"
does not strip whitespace
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
a
"
,
"
b
"
,
"
c
"
],
[
"
1
"
,
"
2
"
,
"
3
"
]]),
"
a , b,c
\n
1,2,3
"
);
},
"
does not quote simple values
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
a
"
],
[
1
]]),
"
a
\n
1
"
);
},
"
escapes double quotes
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
\"
fish
\"
"
]]),
"
\"\"\"
fish
\"\"\"
"
);
},
"
escapes unix newlines
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
new
\n
line
"
]]),
"
\"
new
\n
line
\"
"
);
"
format
"
:
{
topic
:
function
(
d3
)
{
return
d3
.
csv
.
format
;
},
"
takes an array of objects as input
"
:
function
(
format
)
{
assert
.
equal
(
format
([{
a
:
1
,
b
:
2
,
c
:
3
}]),
"
a,b,c
\n
1,2,3
"
);
},
"
escapes field names containing special characters
"
:
function
(
format
)
{
assert
.
equal
(
format
([{
"
foo,bar
"
:
true
}]),
"
\"
foo,bar
\"\n
true
"
);
},
"
computes the union of all fields
"
:
function
(
format
)
{
assert
.
equal
(
format
([
{
a
:
1
},
{
a
:
1
,
b
:
2
},
{
a
:
1
,
b
:
2
,
c
:
3
},
{
b
:
1
,
c
:
2
},
{
c
:
1
}
]),
"
a,b,c
\n
1,,
\n
1,2,
\n
1,2,3
\n
,1,2
\n
,,1
"
);
},
"
orders field by first-seen
"
:
function
(
format
)
{
assert
.
equal
(
format
([
{
a
:
1
,
b
:
2
},
{
c
:
3
,
b
:
4
},
{
c
:
5
,
a
:
1
,
b
:
2
}
]),
"
a,b,c
\n
1,2,
\n
,4,3
\n
1,2,5
"
);
}
},
"
escapes commas
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
oxford,comma
"
]]),
"
\"
oxford,comma
\"
"
);
"
formatRows
"
:
{
topic
:
function
(
d3
)
{
return
d3
.
csv
.
formatRows
;
},
"
takes an array of arrays as input
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
a
"
,
"
b
"
,
"
c
"
],
[
"
1
"
,
"
2
"
,
"
3
"
]]),
"
a,b,c
\n
1,2,3
"
);
},
"
separates lines using unix newline
"
:
function
(
format
)
{
assert
.
equal
(
format
([[],
[]]),
"
\n
"
);
},
"
does not strip whitespace
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
a
"
,
"
b
"
,
"
c
"
],
[
"
1
"
,
"
2
"
,
"
3
"
]]),
"
a , b,c
\n
1,2,3
"
);
},
"
does not quote simple values
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
a
"
],
[
1
]]),
"
a
\n
1
"
);
},
"
escapes double quotes
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
\"
fish
\"
"
]]),
"
\"\"\"
fish
\"\"\"
"
);
},
"
escapes unix newlines
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
new
\n
line
"
]]),
"
\"
new
\n
line
\"
"
);
},
"
escapes commas
"
:
function
(
format
)
{
assert
.
equal
(
format
([[
"
oxford,comma
"
]]),
"
\"
oxford,comma
\"
"
);
}
}
}
});
...
...
test/dsv/tsv-test.js
View file @
608902c9
require
(
"
../env
"
);
var
vows
=
require
(
"
vows
"
),
load
=
require
(
"
../load
"
),
xhr
=
require
(
"
../env-xhr
"
),
assert
=
require
(
"
../env-assert
"
);
var
suite
=
vows
.
describe
(
"
d3.tsv
"
);
suite
.
addBatch
({
"
tsv
"
:
{
topic
:
function
()
{
var
cb
=
this
.
callback
;
d3
.
tsv
(
"
test/data/sample.tsv
"
,
function
(
error
,
tsv
)
{
cb
(
null
,
tsv
);
});
},
"
invokes the callback with the parsed tsv
"
:
function
(
tsv
)
{
assert
.
deepEqual
(
tsv
,
[{
"
Hello
"
:
42
,
"
World
"
:
"
\"
fish
\"
"
}]);
},
"
overrides the mime type to text/tab-separated-values
"
:
function
(
tsv
)
{
assert
.
equal
(
XMLHttpRequest
.
_last
.
_info
.
mimeType
,
"
text/tab-separated-values
"
);
topic
:
load
(
"
dsv/tsv
"
).
sandbox
({
XMLHttpRequest
:
xhr
,
document
:
{},
window
:
{}
}),
"
on a sample file
"
:
{
topic
:
function
(
d3
)
{
var
cb
=
this
.
callback
;
d3
.
tsv
(
"
test/data/sample.tsv
"
,
function
(
error
,
tsv
)
{
cb
(
null
,
tsv
);
});
},
"
invokes the callback with the parsed tsv
"
:
function
(
tsv
)
{
assert
.
deepEqual
(
tsv
,
[{
"
Hello
"
:
42
,
"
World
"
:
"
\"
fish
\"
"
}]);
},
"
overrides the mime type to text/tab-separated-values
"
:
function
(
tsv
)
{
assert
.
equal
(
xhr
.
_last
.
_info
.
mimeType
,
"
text/tab-separated-values
"
);
}
},
""
:
{
topic
:
function
()
{
"
on a file that does not exist
"
:
{
topic
:
function
(
d3
)
{
var
cb
=
this
.
callback
;
d3
.
tsv
(
"
//does/not/exist.tsv
"
,
function
(
error
,
tsv
)
{
cb
(
null
,
tsv
);
...
...
@@ -29,153 +38,154 @@ suite.addBatch({
"
invokes the callback with undefined when an error occurs
"
:
function
(
tsv
)
{
assert
.
isUndefined
(
tsv
);
}
}
},
"
parse
"
:
{
topic
:
function
()
{
return
d3
.
tsv
.
parse
;
},
"
returns an array of objects
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a
\t
b
\t
c
\n
1
\t
2
\t
3
\n
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
},
"
does not strip whitespace
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a
\t
b
\t
c
\n
1
\t
2
\t
3
\n
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
},
"
parses quoted values
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a
\t
b
\t
c
\n\"
1
\"\t
2
\t
3
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
assert
.
deepEqual
(
parse
(
"
a
\t
b
\t
c
\n\"
1
\"\t
2
\t
3
\n
"
),
[{
a
:
"
1
"
,
b
:
"
2
"
,
c
:
"
3
"
}]);
},
"
parses quoted values with quotes
"
:
function
(
parse
)
{
assert
.
deepEqual
(
parse
(
"
a
\n\"\"\"
hello
\"\"\"
"
),
[{
a
:
"
\"
hello
\"
"
}]);
},