mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Wrap objects inside arrays in {}
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user