Skip to content

Commit

Permalink
Test invalid format detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jun 15, 2015
1 parent 61fe9a4 commit d63c35a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/format-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ tape("format(specifier)(number) returns a string", function(test) {
test.end();
});

tape("format(specifier) throws an error for invalid formats", function(test) {
test.throws(function() { format.format("foo"); }, /invalid format: foo/);
test.throws(function() { format.format(".-2s"); }, /invalid format: \.-2s/);
test.throws(function() { format.format(".f"); }, /invalid format: \.f/);
test.end();
});

tape("format(\",.\") unreasonable precision values are clamped to reasonable values", function(test) {
test.equal(format.format(".30f")(0), "0.00000000000000000000");
test.equal(format.format(".0g")(1), "1");
Expand Down
7 changes: 7 additions & 0 deletions test/formatSpecifier-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
var tape = require("tape"),
format = require("../");

tape("formatSpecifier(specifier) throws an error for invalid formats", function(test) {
test.throws(function() { format.formatSpecifier("foo"); }, /invalid format: foo/);
test.throws(function() { format.formatSpecifier(".-2s"); }, /invalid format: \.-2s/);
test.throws(function() { format.formatSpecifier(".f"); }, /invalid format: \.f/);
test.end();
});

tape("formatSpecifier(\"\") has the expected defaults", function(test) {
var s = format.formatSpecifier("");
test.equal(s.fill, " ");
Expand Down

0 comments on commit d63c35a

Please sign in to comment.