diff --git a/spec/stdlib/cson-spec.coffee b/spec/stdlib/cson-spec.coffee index 361eaf330..1ed14b3a9 100644 --- a/spec/stdlib/cson-spec.coffee +++ b/spec/stdlib/cson-spec.coffee @@ -62,6 +62,10 @@ describe "CSON", -> it "formats the undefined value as null", -> expect(CSON.stringify(['a', undefined, 'b'])).toBe "[\n 'a'\n null\n 'b'\n]" + describe "when the array contains an object", -> + it "wraps the object in {}", -> + expect(CSON.stringify([{a:'b', a1: 'b1'}, {c: 'd'}])).toBe "[\n {\n 'a': 'b'\n 'a1': 'b1'\n }\n {\n 'c': 'd'\n }\n]" + describe "when formatting an object", -> describe "when the object is empty", -> it "returns the empty string", -> diff --git a/src/stdlib/cson.coffee b/src/stdlib/cson.coffee index 63158f006..b2797d7c4 100644 --- a/src/stdlib/cson.coffee +++ b/src/stdlib/cson.coffee @@ -21,7 +21,8 @@ module.exports = cson = '[\n' for value in array - cson += @stringifyIndent(indentLevel + 2) + indent = @stringifyIndent(indentLevel + 2) + cson += indent if _.isString(value) cson += @stringifyString(value) else if _.isBoolean(value) @@ -33,7 +34,7 @@ module.exports = else if _.isArray(value) cson += @stringifyArray(value, indentLevel + 2) else if _.isObject(value) - cson += @stringifyObject(value, indentLevel + 2) + cson += "{\n#{@stringifyObject(value, indentLevel + 4)}\n#{indent}}" else throw new Error("Unrecognized type for array value: #{value}") cson += '\n'