deno.land / std@0.224.0 / internal / format_test.ts

format_test.ts
نووسراو ببینە
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
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { green, red, stripAnsiCode } from "../fmt/colors.ts";import { assertEquals, assertThrows } from "../assert/mod.ts";import { format } from "./format.ts";
Deno.test("format() generates correct diffs for strings", () => { assertThrows( () => { assertEquals([..."abcd"].join("\n"), [..."abxde"].join("\n")); }, Error, ` a\\n b\\n${green("+ x")}\\n${green("+ d")}\\n${green("+ e")}${red("- c")}\\n${red("- d")}`, );});
// Check that the diff formatter overrides some default behaviours of// `Deno.inspect()` which are problematic for diffing.Deno.test("format() overrides default behaviours of Deno.inspect", async (t) => { // Wraps objects into multiple lines even when they are small. Prints trailing // commas. await t.step( "fromat() always wraps objects into multiple lines and prints trailing commas", () => assertEquals( stripAnsiCode(format({ a: 1, b: 2 })), `{ a: 1, b: 2,}`, ), );
await t.step("format() wraps Object with getters", () => assertEquals( format(Object.defineProperty({}, "a", { enumerable: true, get() { return 1; }, })), `{ a: [Getter: 1],}`, ));
await t.step("format() wraps nested small objects", () => assertEquals( stripAnsiCode(format([{ x: { a: 1, b: 2 }, y: ["a", "b"] }])), `[ { x: { a: 1, b: 2, }, y: [ "a", "b", ], },]`, ));
// Grouping is disabled. await t.step("format() disables grouping", () => assertEquals( stripAnsiCode(format(["i", "i", "i", "i", "i", "i", "i"])), `[ "i", "i", "i", "i", "i", "i", "i",]`, ));});
Deno.test("format() doesn't truncate long strings in object", () => { const str = format({ foo: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", }); assertEquals( str, `{ foo: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",}`, );});
std

Version Info

Tagged at
3 weeks ago