From 7217c37a3619c72bce6ac5be97b969a0bb2f03cc Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 12:05:04 -0500 Subject: Split tests into separate files --- test/test-macros.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/test-macros.el (limited to 'test/test-macros.el') diff --git a/test/test-macros.el b/test/test-macros.el new file mode 100644 index 0000000..6a1910c --- /dev/null +++ b/test/test-macros.el @@ -0,0 +1,18 @@ +(ert-deftest macro-test--sx-assoc-let () + "Tests macro expansion for `sx-assoc-let'" + (let ((prototype '((test . nil) (test-one . 1) (test-two . 2) + (link . "http://meta.emacs.stackexchange.com/")))) + (let ((data (copy-tree prototype))) + (should + (null (let-alist data .site)))) + + (let ((data (copy-tree prototype))) + (should + (equal (sx-assoc-let data .site) + "meta.emacs"))) + + (let ((data (copy-tree prototype))) + (should + (equal (sx-assoc-let data (cons .test-one .test-two)) + '(1 . 2)))))) + -- cgit v1.2.3 From 9469287080501f3e3c7ce0002d837664a1b9b91e Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 13:15:20 -0500 Subject: Use test fixture for sample data See (info "(ert) Fixtures and Test Suites"). --- test/test-macros.el | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'test/test-macros.el') diff --git a/test/test-macros.el b/test/test-macros.el index 6a1910c..8bdd527 100644 --- a/test/test-macros.el +++ b/test/test-macros.el @@ -1,18 +1,21 @@ +(defmacro sx-test-with-json-data (cell &rest body) + (declare (indent 1)) + `(let ((,cell '((test . nil) (test-one . 1) (test-two . 2) + (link . "http://meta.emacs.stackexchange.com/")))) + ,@body)) + (ert-deftest macro-test--sx-assoc-let () "Tests macro expansion for `sx-assoc-let'" - (let ((prototype '((test . nil) (test-one . 1) (test-two . 2) - (link . "http://meta.emacs.stackexchange.com/")))) - (let ((data (copy-tree prototype))) - (should - (null (let-alist data .site)))) - - (let ((data (copy-tree prototype))) - (should - (equal (sx-assoc-let data .site) - "meta.emacs"))) + (sx-test-with-json-data data + (should + (null (let-alist data .site)))) - (let ((data (copy-tree prototype))) - (should - (equal (sx-assoc-let data (cons .test-one .test-two)) - '(1 . 2)))))) + (sx-test-with-json-data data + (should + (equal (sx-assoc-let data .site) + "meta.emacs"))) + (sx-test-with-json-data data + (should + (equal (sx-assoc-let data (cons .test-one .test-two)) + '(1 . 2))))) -- cgit v1.2.3 From 6376a70f9d70f711723e144ea787cd0a79f7cd7b Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 14:09:02 -0500 Subject: Docstrings for tests --- test/test-macros.el | 11 ++++++----- test/test-printing.el | 7 +++++-- test/test-util.el | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) (limited to 'test/test-macros.el') diff --git a/test/test-macros.el b/test/test-macros.el index 8bdd527..2169088 100644 --- a/test/test-macros.el +++ b/test/test-macros.el @@ -1,11 +1,12 @@ (defmacro sx-test-with-json-data (cell &rest body) - (declare (indent 1)) - `(let ((,cell '((test . nil) (test-one . 1) (test-two . 2) - (link . "http://meta.emacs.stackexchange.com/")))) - ,@body)) + "Run BODY with sample data let-bound to CELL" + (declare (indent 1)) + `(let ((,cell '((test . nil) (test-one . 1) (test-two . 2) + (link . "http://meta.emacs.stackexchange.com/")))) + ,@body)) (ert-deftest macro-test--sx-assoc-let () - "Tests macro expansion for `sx-assoc-let'" + "Test `sx-assoc-let'" (sx-test-with-json-data data (should (null (let-alist data .site)))) diff --git a/test/test-printing.el b/test/test-printing.el index 0ea5b03..2260a00 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -3,7 +3,7 @@ (require 'cl-lib) (defmacro line-should-match (regexp) - "" + "Test if the line at point matches REGEXP" `(let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) @@ -11,6 +11,9 @@ (should (string-match ,regexp line)))) (defmacro question-list-regex (title votes answers &rest tags) + "Construct a matching regexp for TITLE, VOTES, and ANSWERS. +Each element of TAGS is appended at the end of the expression +after being run through `sx-question--tag-format'." `(rx line-start (+ whitespace) ,(number-to-string votes) (+ whitespace) ,(number-to-string answers) @@ -51,7 +54,7 @@ 2 1 "autocomplete" "performance" "ctags")))) (ert-deftest sx--user-@name () - "Tests macro expansion for `sx-assoc-let'" + "Test macro expansion for `sx-assoc-let'" (should (string= (sx--user-@name '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) diff --git a/test/test-util.el b/test/test-util.el index 53dc200..49df274 100644 --- a/test/test-util.el +++ b/test/test-util.el @@ -1,5 +1,5 @@ (ert-deftest test-tree-filter () - "`sx-core-filter-data'" + "Test `sx-core-filter-data'" ;; flat (should (equal @@ -34,7 +34,7 @@ '(1 2 3))))) (ert-deftest thing-as-string () - "Tests `sx--thing-as-string'" + "Test `sx--thing-as-string'" (should (string= (sx--thing-as-string '(hello world (this is a test)) -- cgit v1.2.3