Skip to content

toString(): Print keys in JSON #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions __tests__/Conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,30 @@ describe('Conversion', () => {
});

var immutableOrderedDataString = 'OrderedMap { ' +
'deepList: List [ '+
'"deepList": List [ '+
'OrderedMap { '+
'position: "first"'+
'"position": "first"'+
' }, ' +
'OrderedMap { '+
'position: "second"'+
'"position": "second"'+
' }, '+
'OrderedMap { '+
'position: "third"'+
'"position": "third"'+
' }' +
' ], '+
'deepMap: OrderedMap { '+
'a: "A", '+
'b: "B"'+
'"deepMap": OrderedMap { '+
'"a": "A", '+
'"b": "B"'+
' }, '+
'emptyMap: OrderedMap {}, ' +
'point: Point { x: 10, y: 20 }, '+
'string: "Hello", '+
'list: List [ 1, 2, 3 ]'+
'"emptyMap": OrderedMap {}, ' +
'"point": Point { "x": 10, "y": 20 }, '+
'"string": "Hello", '+
'"list": List [ 1, 2, 3 ]'+
' }';

var nonStringKeyMap = OrderedMap().set(1, true).set(false, "foo");
var nonStringKeyMapString = 'OrderedMap { 1: true, false: "foo" }';

it('Converts deep JS to deep immutable sequences', () => {
expect(Immutable.fromJS(js)).is(immutableData);
});
Expand All @@ -134,6 +137,10 @@ describe('Conversion', () => {
expect(seq.toString()).is(immutableOrderedDataString);
});

it('Prints keys as JSON values', () => {
expect(nonStringKeyMap.toString()).is(nonStringKeyMapString);
});

it('Converts deep sequences to JSON', () => {
var json = immutableData.toJS();
expect(json).not.is(js); // raw JS is not immutable.
Expand Down
2 changes: 1 addition & 1 deletion dist/immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4600,7 +4600,7 @@
KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
KeyedIterablePrototype.__toStringMapper = function(v, k) {return k + ': ' + quoteString(v)};
KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};



Expand Down
Loading