summaryrefslogtreecommitdiff
path: root/tests/test-prog-yaml--yaml-format-buffer.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-03-02 19:46:38 -0600
committerCraig Jennings <c@cjennings.net>2026-03-02 19:46:38 -0600
commitb5cae72d8f824f235f351821f7d7052b66bc2513 (patch)
tree264261c26ec5a6c721e5dbd83e93237e842e53b5 /tests/test-prog-yaml--yaml-format-buffer.el
parenta46f8af939b112b603a2c95b2e83a1932b208e20 (diff)
feat(json,yaml): add tree-sitter modes, formatting, and jq integration
New prog-json module: json-ts-mode with jq formatting (C-; f) and jq-interactively (C-c C-q). Upgraded prog-yaml to yaml-ts-mode with prettier formatting. Both use treesit-auto for grammar management. Includes 18 new tests (10 JSON, 8 YAML), 185/185 passing.
Diffstat (limited to 'tests/test-prog-yaml--yaml-format-buffer.el')
-rw-r--r--tests/test-prog-yaml--yaml-format-buffer.el76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/test-prog-yaml--yaml-format-buffer.el b/tests/test-prog-yaml--yaml-format-buffer.el
new file mode 100644
index 00000000..4e928a2c
--- /dev/null
+++ b/tests/test-prog-yaml--yaml-format-buffer.el
@@ -0,0 +1,76 @@
+;;; test-prog-yaml--yaml-format-buffer.el --- Tests for cj/yaml-format-buffer -*- lexical-binding: t -*-
+
+;;; Commentary:
+;; Tests for the cj/yaml-format-buffer function in prog-yaml.el.
+
+;;; Code:
+
+(require 'ert)
+(require 'prog-yaml)
+
+;;; Normal Cases
+
+(ert-deftest test-prog-yaml--yaml-format-buffer-normal-fixes-indentation ()
+ "Badly indented YAML is normalized to 2-space indent."
+ (with-temp-buffer
+ (insert "items:\n - one\n - two\n")
+ (cj/yaml-format-buffer)
+ (should (string= (buffer-string) "items:\n - one\n - two\n"))))
+
+(ert-deftest test-prog-yaml--yaml-format-buffer-normal-nested-map ()
+ "Nested map with inconsistent indentation is normalized."
+ (with-temp-buffer
+ (insert "server:\n host: localhost\n port: 8080\n")
+ (cj/yaml-format-buffer)
+ (should (string= (buffer-string) "server:\n host: localhost\n port: 8080\n"))))
+
+(ert-deftest test-prog-yaml--yaml-format-buffer-normal-already-formatted ()
+ "Already well-formatted YAML is unchanged."
+ (let ((formatted "name: test\nversion: 1.0\n"))
+ (with-temp-buffer
+ (insert formatted)
+ (cj/yaml-format-buffer)
+ (should (string= (buffer-string) formatted)))))
+
+(ert-deftest test-prog-yaml--yaml-format-buffer-normal-preserves-key-order ()
+ "Key order is preserved (not sorted)."
+ (with-temp-buffer
+ (insert "zebra: 1\nalpha: 2\n")
+ (cj/yaml-format-buffer)
+ (should (string-match-p "zebra.*\nalpha" (buffer-string)))))
+
+;;; Boundary Cases
+
+(ert-deftest test-prog-yaml--yaml-format-buffer-boundary-empty-document ()
+ "Empty YAML document formats without error."
+ (with-temp-buffer
+ (insert "")
+ (cj/yaml-format-buffer)
+ (should (string= (string-trim (buffer-string)) ""))))
+
+(ert-deftest test-prog-yaml--yaml-format-buffer-boundary-single-key ()
+ "Single key-value pair formats cleanly."
+ (with-temp-buffer
+ (insert "key: value\n")
+ (cj/yaml-format-buffer)
+ (should (string= (buffer-string) "key: value\n"))))
+
+(ert-deftest test-prog-yaml--yaml-format-buffer-boundary-unicode ()
+ "YAML with unicode values is preserved."
+ (with-temp-buffer
+ (insert "name: café\ncity: Zürich\n")
+ (cj/yaml-format-buffer)
+ (should (string-match-p "café" (buffer-string)))
+ (should (string-match-p "Zürich" (buffer-string)))))
+
+;;; Error Cases
+
+(ert-deftest test-prog-yaml--yaml-format-buffer-error-no-prettier ()
+ "Signals user-error when prettier is not found."
+ (cl-letf (((symbol-function 'executable-find) (lambda (_) nil)))
+ (with-temp-buffer
+ (insert "key: value\n")
+ (should-error (cj/yaml-format-buffer) :type 'user-error))))
+
+(provide 'test-prog-yaml--yaml-format-buffer)
+;;; test-prog-yaml--yaml-format-buffer.el ends here