-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlsp-yaml-tests.el
107 lines (92 loc) · 5.37 KB
/
lsp-yaml-tests.el
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
105
106
107
(require 'ert)
(when (require 'undercover nil t)
(undercover "lsp-yaml.el"))
(require 'lsp-yaml)
(ert-deftest lsp-yaml-test-json-encoded-default-settings ()
"Check if JSON encoded default settings are correct."
(should
(equal (json-encode (lsp-yaml--settings))
"{\"yaml\":{\"completion\":true,\"format\":{\"enable\":false},\"hover\":true,\"schemas\":{},\"validate\":true}}")))
(ert-deftest lsp-yaml-test-json-encoded-multple-schemas ()
"Check if JSON encoded settings with multiple schemas are correct."
(let ((lsp-yaml-schemas
'(:kubernetes "/kube.yaml" :kedge "/kedge.yaml")))
(should
(equal (json-encode (lsp-yaml--settings))
"{\"yaml\":{\"completion\":true,\"format\":{\"enable\":false},\"hover\":true,\"schemas\":{\"kubernetes\":\"/kube.yaml\",\"kedge\":\"/kedge.yaml\"},\"validate\":true}}"))))
(ert-deftest lsp-yaml-test-json-encoded-multple-schemas-as-alist ()
"Check if JSON encoded settings with multiple schemas alist is correct."
(let ((lsp-yaml-schemas
'(("kubernetes" . "/kube.yaml") ("kedge" . "/kedge.yaml"))))
(should
(equal (json-encode (lsp-yaml--settings))
"{\"yaml\":{\"completion\":true,\"format\":{\"enable\":false},\"hover\":true,\"schemas\":{\"kubernetes\":\"/kube.yaml\",\"kedge\":\"/kedge.yaml\"},\"validate\":true}}"))))
(ert-deftest lsp-yaml-test-json-encoded-hash-table-schemas ()
"Check if JSON encoded settings from hash table are correct."
(let ((lsp-yaml-schemas (make-hash-table)))
(puthash "http://example.com/schema.json" "/test.yaml" lsp-yaml-schemas)
(should
(equal (json-encode (lsp-yaml--settings))
"{\"yaml\":{\"completion\":true,\"format\":{\"enable\":false},\"hover\":true,\"schemas\":{\"http://example.com/schema.json\":\"/test.yaml\"},\"validate\":true}}"))))
(ert-deftest lsp-yaml-test-json-encoded-empty-schemas ()
"Check if JSON encoded settings with empty schemas are correct."
(let ((lsp-yaml-schemas nil))
(should
(equal (json-encode (lsp-yaml--settings))
"{\"yaml\":{\"completion\":true,\"format\":{\"enable\":false},\"hover\":true,\"schemas\":{},\"validate\":true}}"))))
(ert-deftest lsp-yaml-test-json-encoded-validate-false ()
"Check if JSON encoded settings are correct with validate false."
(should
(let ((lsp-yaml-validate nil))
(equal (json-encode (lsp-yaml--settings))
"{\"yaml\":{\"completion\":true,\"format\":{\"enable\":false},\"hover\":true,\"schemas\":{},\"validate\":false}}"))))
(ert-deftest lsp-yaml-test-json-encoded-hover-false ()
"Check if JSON encoded settings are correct with hover false."
(should
(let ((lsp-yaml-hover nil))
(equal (json-encode (lsp-yaml--settings))
"{\"yaml\":{\"completion\":true,\"format\":{\"enable\":false},\"hover\":false,\"schemas\":{},\"validate\":true}}"))))
(ert-deftest lsp-yaml-test-json-encoded-completion-false ()
"Check if JSON encoded settings are correct with completion false."
(should
(let ((lsp-yaml-completion nil))
(equal (json-encode (lsp-yaml--settings))
"{\"yaml\":{\"completion\":false,\"format\":{\"enable\":false},\"hover\":true,\"schemas\":{},\"validate\":true}}"))))
(ert-deftest lsp-yaml-test-json-encoded-format-enable-true ()
"Check if JSON encoded settings are correct with format.enable true."
(should
(let ((lsp-yaml-format-enable t))
(equal (json-encode (lsp-yaml--settings))
"{\"yaml\":{\"completion\":true,\"format\":{\"enable\":true},\"hover\":true,\"schemas\":{},\"validate\":true}}"))))
(ert-deftest lsp-yaml-test-json-encoded-format-options-as-plist ()
"Check if JSON encoded format options are correct from plist value."
(let ((lsp-yaml-format-enable t)
(lsp-yaml-format-options '(:singleQuote t :proseWrap "never")))
(should
(equal (json-encode (lsp-yaml--format-options))
"{\"enable\":true,\"singleQuote\":true,\"proseWrap\":\"never\"}"))))
(ert-deftest lsp-yaml-test-json-encoded-format-options-as-alist ()
"Check if JSON encoded format options are correct from alist value."
(let ((lsp-yaml-format-enable nil)
(lsp-yaml-format-options '(("bracketSpacing" . :json-false) ("proseWrap" . "always"))))
(should
(equal (json-encode (lsp-yaml--format-options))
"{\"enable\":false,\"bracketSpacing\":false,\"proseWrap\":\"always\"}"))))
(ert-deftest lsp-yaml-test-json-encoded-format-options-as-hash-table ()
"Check if JSON encoded format options are correct from hash table value."
(let ((lsp-yaml-format-enable t)
(lsp-yaml-format-options (make-hash-table)))
(puthash "singleQuote" :json-false lsp-yaml-format-options)
(puthash "bracketSpacing" t lsp-yaml-format-options)
(puthash "proseWrap" "preserve" lsp-yaml-format-options)
(let ((json (json-encode (lsp-yaml--format-options))))
(should (string-match-p "\"enable\":true" json))
(should (string-match-p "\"singleQuote\":false" json))
(should (string-match-p "\"bracketSpacing\":true" json))
(should (string-match-p "\"proseWrap\":\"preserve\"" json)))))
(ert-deftest lsp-yaml-test-json-encoded-format-options-error-invalid-type ()
"Check if user-error is thrown for invalid format options."
(let ((lsp-yaml-format-options (cons "singleQuote" t)))
(should-error (lsp-yaml--format-options) :type 'user-error))
(let ((lsp-yaml-format-options t))
(should-error (lsp-yaml--format-options) :type 'user-error)))