Skip to content

Commit af48d88

Browse files
committed
Added test cases
1 parent f46ab93 commit af48d88

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

jsone/render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def ifConstruct(template, context):
143143
def jsonConstruct(template, context):
144144
checkUndefinedProperties(template, ['\$json'])
145145
value = renderValue(template['$json'], context)
146-
return json.dumps(value, separators=(',', ':'))
146+
return json.dumps(value, separators=(',', ':'), sort_keys=True)
147147

148148

149149
@operator('$let')

specification.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,28 @@ result: '{"Z":null,"a":{"b":["9",8,{}],"c":45},"q":1,"r":true}'
4949
---
5050
title: $json sorting unicode strings
5151
context: {}
52-
template: {$json: {'\u0048\u0050': 56, '\u0042\u0010': 44, '\u0055\u0045': 43}}
53-
result: '{"\u0042\u0010": 44, "\u0048\u0050": 56, "\u0055\u0045": 43}'
52+
template: {$json: {'\u3347\u0050': 1, '\uE1FF\u0010': 2, '\u0055\u0045': 3}}
53+
result: '{"\\u0055\\u0045": 3, "\\u3347\\u0050": 1 , "\\uE1FF\\u0010": 2}'
54+
---
55+
title: $json sorting unicode strings2
56+
context: {}
57+
template: {$json: {'u005A\u10000\u0050': 1, '\u{E1FFF}\u0010': 2, '\u0055a\u0045': 3}}
58+
result: '{"\\u0055a\\u0045": 3, "\\u005A\\u10000\\u0050": 1, "\\u{E1FFF}\\u0010": 2}'
59+
---
60+
title: $json sorting unicode strings3
61+
context: {}
62+
template: {$json: {'e\u{E3FFE}\u732b':'hey', '\u0041\u0012\u107000':'hi', 'A\u{24000}':'hello'}}
63+
result: '{"\\u0041\\u0012\\u107000":"hi", "A\\u{24000}":"hello", "e\\u{E3FFE}\\u732b":"hey"}'
64+
---
65+
title: $json sorting unicode strings4
66+
context: {}
67+
template: {$json: {'e\u{E3FFE}\u732b':'hey', '\u0041\u{24000}\u107000':'hi', 'A\u4FFF':'hello'}}
68+
result: '{"A\\u4FFF": "hello", "\\u0041\\u{24000}\\u107000": "hi", "e\\u{E3FFE}\\u732b": "hey" }'
69+
---
70+
title: $json sorting unicode string5
71+
context: {}
72+
template: {$json: {'\u{24000}\u732b':'hey', '\u007C\u{24000}\u107000':'hi', '\u0012\u{FFFF4}':'hello'}}
73+
result: '{"A\\u4FFF": "hello", "\\u0041\\u{24000}\\u107000": "hi", "e\\u{E3FFE}\\u732b": "hey" }'
5474
---
5575
title: string interpolation
5676
context: {key: 'world', num: 1}

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,6 @@ module.exports = (template, context = {}) => {
373373
return null;
374374
}
375375
return result;
376-
};
376+
};
377+
378+
//var template = {$json: {'e\uE120\u732b':'hey', '\uE241\u0012\u{107000}':'hi', '\u{24000}\u0022':'hello'}};

0 commit comments

Comments
 (0)