{
"version": "1.4",
"category": "encode",
"description": "Object encoding - simple objects, nested objects, key encoding",
"tests": [
{
"name": "preserves key order in objects",
"input": {
"id": 123,
"name": "Ada",
"active": true
},
"expected": "id: 123\nname: Ada\nactive: true",
"specSection": "8"
},
{
"name": "encodes null values in objects",
"input": {
"id": 123,
"value": null
},
"expected": "id: 123\nvalue: null",
"specSection": "8"
},
{
"name": "encodes empty objects as empty string",
"input": {},
"expected": "",
"specSection": "8"
},
{
"name": "quotes string value with colon",
"input": {
"note": "a:b"
},
"expected": "note: \"a:b\"",
"specSection": "7.2"
},
{
"name": "quotes string value with comma",
"input": {
"note": "a,b"
},
"expected": "note: \"a,b\"",
"specSection": "7.2"
},
{
"name": "quotes string value with newline",
"input": {
"text": "line1\nline2"
},
"expected": "text: \"line1\\nline2\"",
"specSection": "7.2"
},
{
"name": "quotes string value with leading space",
"input": {
"text": " padded "
},
"expected": "text: \" padded \"",
"specSection": "7.2"
},
{
"name": "quotes string value that looks like true",
"input": {
"v": "true"
},
"expected": "v: \"true\"",
"specSection": "7.2"
},
{
"name": "quotes string value that looks like number",
"input": {
"v": "42"
},
"expected": "v: \"42\"",
"specSection": "7.2"
},
{
"name": "quotes key with colon",
"input": {
"order:id": 7
},
"expected": "\"order:id\": 7",
"specSection": "7.3"
},
{
"name": "quotes key with spaces",
"input": {
"full name": "Ada"
},
"expected": "\"full name\": Ada",
"specSection": "7.3"
},
{
"name": "quotes numeric key",
"input": {
"123": "x"
},
"expected": "\"123\": x",
"specSection": "7.3"
},
{
"name": "quotes empty string key",
"input": {
"": 1
},
"expected": "\"\": 1",
"specSection": "7.3"
},
{
"name": "encodes deeply nested objects",
"input": {
"a": {
"b": {
"c": "deep"
}
}
},
"expected": "a:\n b:\n c: deep",
"specSection": "8"
},
{
"name": "encodes empty nested object",
"input": {
"user": {}
},
"expected": "user:",
"specSection": "8"
}
]
}