Skip to content
This repository was archived by the owner on Jan 6, 2021. It is now read-only.

Commit 116d0ac

Browse files
author
Christian Johansen
committed
Format empty strings as (empty string)
1 parent 6e8ff82 commit 116d0ac

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

lib/formatio.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
function ascii(f, object, processed, indent) {
6666
if (typeof object === "string") {
67+
if (object.length === 0) { return "(empty string)"; }
6768
var qs = f.quoteStrings;
6869
var quote = typeof qs !== "boolean" || qs;
6970
return processed || quote ? '"' + object + '"' : object;

test/formatio-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
assert.equals(formatio.ascii("A string"), '"A string"');
3333
},
3434

35+
"formats 0-length strings in a special way": function () {
36+
assert.equals(formatio.ascii(""), "(empty string)");
37+
},
38+
3539
"formats booleans without quotes": function () {
3640
assert.equals(formatio.ascii(true), "true");
3741
assert.equals(formatio.ascii(false), "false");

0 commit comments

Comments
 (0)