Write empty object values on same line as keys

This commit is contained in:
Kevin Sawicki
2013-04-30 22:43:51 -07:00
parent 986e5f9c7a
commit 334c4095bb
2 changed files with 6 additions and 1 deletions

View File

@@ -73,6 +73,8 @@ describe "CSON", ->
it "returns formatted CSON", ->
expect(CSON.stringify(a: {b: 'c'})).toBe "'a':\n 'b': 'c'"
expect(CSON.stringify(a:{})).toBe "'a': {}"
expect(CSON.stringify(a:[])).toBe "'a': []"
describe "when converting back to an object", ->
it "produces the original object", ->

View File

@@ -94,7 +94,10 @@ module.exports =
else if _.isArray(value)
cson += " #{@stringifyArray(value, indentLevel)}"
else if _.isObject(value)
cson += "\n#{@stringifyObject(value, indentLevel + 2)}"
if _.isEmpty(value)
cson += ' {}'
else
cson += "\n#{@stringifyObject(value, indentLevel + 2)}"
else
throw new Error("Unrecognized value type for key: #{key} with value: #{value}")
prefix = '\n'