deno.land / std@0.224.0 / toml / stringify_test.ts

stringify_test.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertEquals, assertThrows } from "../assert/mod.ts";import { stringify } from "./stringify.ts";
// https://github.com/denoland/deno_std/issues/1067#issuecomment-907740319Deno.test({ name: "stringify() handles object value contains '='", fn() { const src = { "a": "a = 1", "helloooooooo": 1, };
const actual = stringify(src, { keyAlignment: true }); const expected = `a = "a = 1"helloooooooo = 1`; assertEquals(actual, expected); },});
Deno.test({ name: "stringify() handles key alignment", fn() { const src = { "a": 1, "aa": 1, "aaa": 1, "aaaa": 1, "aaaaa": 1, }; const actual = stringify(src, { keyAlignment: true }); const expected = `a = 1aa = 1aaa = 1aaaa = 1aaaaa = 1`; assertEquals(actual, expected); },});
Deno.test({ name: "stringify() handles empty key", fn() { const src = { "": "a", "b": { "": "c" }, }; const actual = stringify(src); const expected = `"" = "a"
[b]"" = "c"`; assertEquals(actual, expected); },});
Deno.test({ name: "stringify() handles empty object", fn() { const src = { "a": {}, "b": { "c": {} }, }; const actual = stringify(src); const expected = `[a]
[b.c]`; assertEquals(actual, expected); },});
Deno.test({ name: "stringify() handles special keys in inline object", fn() { const src = { "a": [{ "/": "b" }, "c"], }; const actual = stringify(src); const expected = 'a = [{"/" = "b"},"c"]\n'; assertEquals(actual, expected); },});
Deno.test({ name: "stringify() throws on invalid value", fn() { assertThrows( () => stringify({ a: [[null]] }), Error, "should never reach", ); assertThrows( () => stringify({ a: [[undefined]] }), Error, "should never reach", ); },});
std

Version Info

Tagged at
6 months ago