Move unit tests from ert to buttercup

Easier to organize and write. Now I can hopefully strive for better
coverage!
This commit is contained in:
Henrik Lissner 2018-06-15 03:31:54 +02:00
parent 98d2f1de3f
commit eaca8c58fa
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
41 changed files with 1371 additions and 1101 deletions

View file

@ -40,7 +40,7 @@
"Improve imenu support with better expression regexps and Doom-specific forms."
(setq imenu-generic-expression
'(("Evil Commands" "^\\s-*(evil-define-\\(?:command\\|operator\\|motion\\) +\\(\\_<[^ ()\n]+\\_>\\)" 1)
("Unit tests" "^\\s-*(\\(?:ert-deftest\\|def-test!\\) +\\(\\_<[^ ()\n]+\\_>\\)" 1)
("Unit tests" "^\\s-*(\\(?:ert-deftest\\|describe\\) +\"\\([^\")]+\\)\"" 1)
("Package" "^\\s-*(\\(?:def-\\)?package! +\\(\\_<[^ ()\n]+\\_>\\)" 1)
("Settings" "^\\s-*(def-setting! +\\([^ ()\n]+\\)" 1)
("Major modes" "^\\s-*(define-derived-mode +\\([^ ()\n]+\\)" 1)
@ -113,3 +113,11 @@
(def-project-mode! +emacs-lisp-ert-mode
:modes (emacs-lisp-mode)
:match "/test[/-].+\\.el$")
(associate! buttercup-minor-mode
:modes (emacs-lisp-mode)
:match "/test[/-].+\\.el$")
(after! buttercup
(set! :yas-minor-mode 'buttercup-minor-mode))

View file

@ -1,62 +0,0 @@
;; -*- no-byte-compile: t; -*-
;;; lang/org/test/autoload-org.el
(require! :lang org)
(defmacro should-org-buffer!! (source expected &rest body)
`(should-buffer! ,source ,expected
(org-mode)
,@body))
;;
;; `+org/insert-item'
(def-test! insert-item-h1
"Should append/prepend new first-level headers with an extra newline."
(should-org-buffer!! ("* {0}Header") ("* Header\n\n* {|}")
(+org/insert-item 'below))
(should-org-buffer!! ("* {0}Header") ("* {|}\n\n* Header")
(+org/insert-item 'above)))
(def-test! insert-item-h2
"Should append/prepend new second-level (and higher) headers without an extra
newline."
(should-org-buffer!! ("** {0}Header") ("** Header\n** {|}")
(+org/insert-item 'below))
(should-org-buffer!! ("** {0}Header") ("** {|}\n** Header")
(+org/insert-item 'above)))
(def-test! insert-item-plain-list
"Should append/prepend new second-level (and higher) headers without an extra
newline."
(should-org-buffer!! ("+ {0}List item") ("+ List item\n+ {|}")
(+org/insert-item 'below))
(should-org-buffer!! ("+ {0}List item"
" + Sub item")
("+ List item"
" + Sub item"
"+ {|}")
(+org/insert-item 'below))
(should-org-buffer!! ("+ {0}List item"
"+ Next item")
("+ List item"
"+ {|}"
"+ Next item")
(+org/insert-item 'below)))
(def-test! insert-item-numbered-list
"Should append/prepend new second-level (and higher) headers without an extra
newline."
(should-org-buffer!! ("1. {0}List item") ("1. List item\n2. {|}")
(+org/insert-item 'below))
(should-org-buffer!! ("1. {0}List item"
"2. Sub item")
("1. List item"
"2. {|}"
"3. Sub item")
(+org/insert-item 'below))
(should-org-buffer!! ("1. {0}List item"
"2. Next item")
("1. {|}"
"2. List item"
"3. Next item")
(+org/insert-item 'above)))

View file

@ -0,0 +1,145 @@
;; -*- no-byte-compile: t; -*-
;;; lang/org/test/test-autoload-org.el
(describe "lang/org"
;; `+org/insert-item'
(describe "insert-item"
(before-all
(require 'org)
(load! "../autoload/org.el"))
(after-all
(unload-feature 'org t))
(before-each
(set-buffer (get-buffer-create "org"))
(erase-buffer)
(delay-mode-hooks (org-mode)))
(after-each
(kill-buffer (get-buffer "org")))
(describe "headlines"
(it "appends first-level headlines with an extra newline"
(insert! "* {0}Header")
(+org/insert-item 'below)
(expect (eobp))
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal "* Header\n\n* "))
(it "prepends first-level headlines with an extra newline"
(insert! "* {0}Header")
(+org/insert-item 'above)
(expect (eolp))
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal "* \n\n* Header"))
(it "appends second-level headlines with an no extra newline"
(insert! "** {0}Header")
(+org/insert-item 'below)
(expect (eobp))
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal "** Header\n** "))
(it "prepends second-level headlines with an no extra newline"
(insert! "** {0}Header")
(+org/insert-item 'above)
(expect (eolp))
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal "** \n** Header"))
(it "appends headlines, skipping subtrees"
(insert! "** {0}First\n"
"*** sub 1\n"
"*** sub 2\n"
"**** subsub 1\n"
"** Header")
(+org/insert-item 'below)
(expect (eolp))
(expect (line-number-at-pos) :to-be 5)
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal
(string-join '("** First"
"*** sub 1"
"*** sub 2"
"**** subsub 1"
"** "
"** Header")
"\n")))
(it "prepends headlines, skipping subtrees"
(insert! "** First\n"
"*** sub 1\n"
"*** sub 2\n"
"**** {0}subsub 1\n"
"** Header")
(+org/insert-item 'above)
(expect (eolp))
(expect (line-number-at-pos) :to-be 4)
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal
(string-join '("** First"
"*** sub 1"
"*** sub 2"
"**** "
"**** subsub 1"
"** Header")
"\n"))))
(describe "plain lists"
(it "appends items"
(insert! "+ {0}List item")
(+org/insert-item 'below)
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal "+ List item\n+ "))
(it "prepends items"
(insert! "+ {0}List item")
(+org/insert-item 'above)
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal "+ \n+ List item"))
(it "appends items, but skips over child items"
(insert! "+ {0}List item\n"
" + Sub item\n"
"+ List item")
(+org/insert-item 'below)
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal
(string-join '("+ List item"
" + Sub item"
"+ "
"+ List item")
"\n")))
(it "prepends items, but skips over child items"
(insert! "+ List item\n"
" + Sub item\n"
"+ {0}List item")
(+org/insert-item 'above)
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal
(string-join '("+ List item"
" + Sub item"
"+ "
"+ List item")
"\n"))))
(describe "numbered lists"
(it "appends items and updates numbers"
(insert! "1. {0}List item\n"
"2. Sub item\n"
"3. List item")
(+org/insert-item 'below)
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal
(string-join '("1. List item"
"2. "
"3. Sub item"
"4. List item")
"\n")))
(it "prepends items and updates numbers"
(insert! "1. List item\n"
"2. Sub item\n"
"3. {0}List item")
(+org/insert-item 'above)
(expect (buffer-substring-no-properties (point-min) (point-max))
:to-equal
(string-join '("1. List item"
"2. Sub item"
"3. "
"4. List item")
"\n"))))))

View file

@ -1,32 +0,0 @@
;; -*- no-byte-compile: t; -*-
;;; lang/web/test/autoload-css.el
(def-test! toggle-inline-or-block
(let ((css-indent-offset 2))
(should-buffer!
("body { color: red{0}; font-size: 2em; }")
("body {"
" color: red{|};"
" font-size: 2em;"
"}")
(delay-mode-hooks (css-mode))
(+css/toggle-inline-or-block))))
(def-test! comment-indent-new-line
(should-buffer!
("// test{0}"
"body { color: red; font-size: 2em; }")
("// test"
"// {|}"
"body { color: red; font-size: 2em; }")
(delay-mode-hooks (scss-mode))
(+css/comment-indent-new-line))
(should-buffer!
("// test{0}"
"body { color: red; font-size: 2em; }")
("// test"
"// {|}"
"body { color: red; font-size: 2em; }")
(delay-mode-hooks (scss-mode))
(+css/comment-indent-new-line)))

View file

@ -1,14 +0,0 @@
;; -*- no-byte-compile: t; -*-
;;; lang/web/test/autoload-html.el
(def-test! encode-entities
(should (equal (+web-encode-entities "Hello world")
"Hello world"))
(should (equal (+web-encode-entities "H€llø wørld")
"H&euro;ll&oslash; w&oslash;rld")))
(def-test! decode-entities
(should (equal (+web-decode-entities "Hello world")
"Hello world"))
(should (equal (+web-decode-entities "H&euro;ll&oslash; w&oslash;rld")
"H€llø wørld")))

View file

@ -0,0 +1,93 @@
;; -*- no-byte-compile: t; -*-
;;; lang/web/test/test-autoload-web.el
(describe "lang/web"
(describe "+html"
(before-all (load! "../autoload/html.el"))
(describe "encode entities"
(it "encodes strings with html entities"
(expect (+web-encode-entities "H€llø wørld")
:to-equal "H&euro;ll&oslash; w&oslash;rld"))
(it "does nothing when html entities are absent"
(expect (+web-encode-entities "Hello world")
:to-equal "Hello world")))
(describe "decode entities"
(it "decodes strings with html entities"
(expect (+web-decode-entities "H&euro;ll&oslash; w&oslash;rld")
:to-equal "H€llø wørld"))
(it "does nothing when html entities are absent"
(expect (+web-decode-entities "Hello world")
:to-equal "Hello world"))))
(describe "+css"
:var (css-indent-offset)
(before-all
(load! "../autoload/css.el")
(require 'smartparens)
(smartparens-mode +1))
(after-all
(smartparens-mode -1)
(unload-feature 'smartparens t))
(before-each
(setq css-indent-offset 2)
(set-buffer (get-buffer-create "css"))
(delay-mode-hooks (css-mode)))
(after-each
(kill-buffer (get-buffer "css")))
(describe "toggle-inline-or-block"
(after-each
(+css/toggle-inline-or-block)
(expect (string-trim (buffer-string)) :to-equal
(string-join
'("body {"
" color: red;"
" font-size: 2em;"
"}")
"\n")))
(describe "css-mode"
(before-each )
(it "converts inline statements into multiline blocks"
(insert! "body { color: red{0}; font-size: 2em; }"))
(it "works when cursor is on closing brace"
(insert! "body { color: red; font-size: 2em; {0}}"))
(it "works when cursor is on opening brace"
(insert! "body {{0} color: red; font-size: 2em; }"))
(it "works when cursor is on same line"
(insert! "{0}body { color: red; font-size: 2em; }"))))
(describe "comment-indent-new-line"
(before-each
(delay-mode-hooks (scss-mode)))
(it "continues commented lines on newline"
(insert! "// test{0}\n"
"body { color: red; font-size: 2em; }")
(+css/comment-indent-new-line)
(expect (string-trim (buffer-string)) :to-equal
(string-join
'("// test"
"// "
"body { color: red; font-size: 2em; }")
"\n"))
(expect (eolp))
(expect (line-number-at-pos) :to-be 2))
(it "preserves indentation within continued comments"
(insert! "// test{0}\n"
"body { color: red; font-size: 2em; }")
(+css/comment-indent-new-line)
(expect (string-trim (buffer-string)) :to-equal
(string-join
'("// test"
"// "
"body { color: red; font-size: 2em; }")
"\n"))
(expect (eolp))
(expect (line-number-at-pos) :to-be 2)))))
;;