-
Notifications
You must be signed in to change notification settings - Fork 0
/
prettier_test.go
61 lines (54 loc) · 1.75 KB
/
prettier_test.go
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
package prettier_go
import (
_ "embed"
"testing"
)
//go:embed js/antd.min.js
var antd string
func TestPrettierFormat(t *testing.T) {
// General
if ret, _ := FormatTypeScript("if (1) {\n1}", PrettierOption{TabWidth: 4}); ret != "if (1) {\n 1\n}\n" {
t.Error("FormatTypeScript error", ret)
}
if ret, _ := FormatTypeScript("if (1) {\n1}", PrettierOption{UseTabs: true}); ret != "if (1) {\n\t1\n}\n" {
t.Error("FormatTypeScript error", ret)
}
if ret, _ := FormatTypeScript("if ('1') {\n1}", PrettierOption{SingleQuote: false}); ret != "if (\"1\") {\n 1\n}\n" {
t.Error("FormatTypeScript error", ret)
}
if ret, _ := FormatTypeScript("1", PrettierOption{Semi: true}); ret != "1;\n" {
t.Error("FormatTypeScript error", ret)
}
// js
if ret, _ := FormatTypeScript("var a=1", PrettierOption{}); ret != "var a = 1\n" {
t.Error("FormatTypeScript error", ret)
}
// ts
if ret, _ := FormatTypeScript("var a: number = 1", PrettierOption{}); ret != "var a: number = 1\n" {
t.Error("FormatTypeScript error", ret)
}
// jsx
if ret, _ := FormatTypeScript("var a=<b>1</b>", PrettierOption{}); ret != "var a = <b>1</b>\n" {
t.Error("FormatTypeScript error", ret)
}
// JSON
if ret, err := FormatJSON("{a:1}", PrettierOption{}); ret != "{ \"a\": 1 }\n" {
t.Error("FormatJSON error", ret, err)
}
// Markdown
if ret, err := FormatMarkdown("# 1", PrettierOption{}); ret != "# 1\n" {
t.Error("FormatMarkdown error", ret, err)
}
// HTML
if ret, err := FormatHTML("<body class='a' ></body>", PrettierOption{}); ret != "<body class=\"a\"></body>\n" {
t.Error("FormatHTML error", ret, err)
}
}
func TestPrettierFormat1(t *testing.T) {
script, err := FormatTypeScript(antd, PrettierOption{})
if err != nil {
t.Log(err)
} else {
t.Log(len(script))
}
}