From ef1d321a157e300d29c48e461257897fca1c9aa4 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 20 Dec 2014 02:01:52 -0500 Subject: Expand `let-alist' upon `sx-assoc-let' expansion --- sx.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index 6f4e7c7..97a6d61 100644 --- a/sx.el +++ b/sx.el @@ -313,10 +313,11 @@ with a `link' property)." If ALIST doesn't have a `site' property, one is created using the `link' property." (declare (indent 1) (debug t)) + (require 'let-alist) `(progn - (require 'let-alist) (sx--ensure-site ,alist) - (let-alist ,alist ,@body))) + ,(macroexpand + `(let-alist ,alist ,@body)))) (defcustom sx-init-hook nil "Hook run when SX initializes. -- cgit v1.2.3 From 7d2cccd82cf6c658e330767d0e20e48e42ff1ac6 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 20 Dec 2014 02:22:37 -0500 Subject: Fix `sx-assoc-let' tests `require' form is no longer needed -- macro expansion is done with the expansion of `sx-assoc-let'. --- test/tests.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/tests.el b/test/tests.el index 66d8d88..cc58105 100644 --- a/test/tests.el +++ b/test/tests.el @@ -121,14 +121,16 @@ (ert-deftest macro-test--sx-assoc-let () "Tests macro expansion for `sx-assoc-let'" (should - (equal '(progn (require 'let-alist) - (sx--ensure-site data) - (let-alist data .test)) - (macroexpand '(sx-assoc-let data .test)))) + (equal `(progn (sx--ensure-site data) + ,(macroexpand + '(let-alist data .test))) + (macroexpand + '(sx-assoc-let data .test)))) (should - (equal '(progn (require 'let-alist) - (sx--ensure-site data) - (let-alist data (cons .test-one .test-two))) + (equal `(progn (sx--ensure-site data) + ,(macroexpand + '(let-alist data + (cons .test-one .test-two)))) (macroexpand '(sx-assoc-let data (cons .test-one .test-two)))))) -- cgit v1.2.3 From 1ab0df0975e67a626c95d89120ae0c0e2fdcf9ff Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 27 Dec 2014 19:33:26 -0200 Subject: Fix `sx-question--mark-hidden', which was just plain wrong. --- sx-question.el | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sx-question.el b/sx-question.el index 801384a..03ebb4b 100644 --- a/sx-question.el +++ b/sx-question.el @@ -159,14 +159,13 @@ If no cache exists for it, initialize one with SITE." (let ((site-cell (assoc .site sx-question--user-hidden-list))) ;; If question already hidden, do nothing. (unless (memq .question_id site-cell) - ;; First question from this site. - (push (list .site .question_id) sx-question--user-hidden-list) - ;; Question wasn't present. - ;; Add it in, but make sure it's sorted (just in case we need - ;; it later). - (sx-sorted-insert-skip-first .question_id site-cell >) - ;; This causes a small lag on `j' and `k' as the list gets large. - ;; Should we do this on a timer? + (if (null site-cell) + ;; First question from this site. + (push (list .site .question_id) sx-question--user-hidden-list) + ;; Not first question and question wasn't present. + ;; Add it in, but make sure it's sorted (just in case we + ;; decide to rely on it later). + (sx-sorted-insert-skip-first .question_id site-cell >)) ;; Save the results. (sx-cache-set 'hidden-questions sx-question--user-hidden-list))))) -- cgit v1.2.3 From 35b0883d3e551c5cbc4f416082957e977d6e03eb Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 30 Dec 2014 18:10:39 -0500 Subject: Reapply ef1d321a157e300d29c48e461257897fca1c9aa4 It was somehow lost in the merging. --- sx.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index 508de46..8fe31ac 100644 --- a/sx.el +++ b/sx.el @@ -136,10 +136,11 @@ with a `link' property)." If ALIST doesn't have a `site' property, one is created using the `link' property." (declare (indent 1) (debug t)) + (require 'let-alist) `(progn - (require 'let-alist) (sx--ensure-site ,alist) - (let-alist ,alist ,@body))) + ,(macroexpand + `(let-alist ,alist ,@body)))) ;;; Browsing filter -- cgit v1.2.3 From 06f7059bffa517d63c72a0815ff0779cfe5e5ce2 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 30 Dec 2014 23:07:36 -0500 Subject: Test sx-assoc-let according to functionality See http://emacs.stackexchange.com/q/5915/2264 and #151 for more information. This patch tests for functional equivalence rather than symbolic equivalence. Symbolic equivalence would be far preferable, but it does not appear to be happening anytime soon -- perhaps when things settle down a bit for the authors :) --- test/tests.el | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/test/tests.el b/test/tests.el index cc58105..3c275fd 100644 --- a/test/tests.el +++ b/test/tests.el @@ -120,19 +120,21 @@ (ert-deftest macro-test--sx-assoc-let () "Tests macro expansion for `sx-assoc-let'" - (should - (equal `(progn (sx--ensure-site data) - ,(macroexpand - '(let-alist data .test))) - (macroexpand - '(sx-assoc-let data .test)))) - (should - (equal `(progn (sx--ensure-site data) - ,(macroexpand - '(let-alist data - (cons .test-one .test-two)))) - (macroexpand - '(sx-assoc-let data (cons .test-one .test-two)))))) + (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)))))) (ert-deftest sx--user-@name () "Tests macro expansion for `sx-assoc-let'" -- cgit v1.2.3 From b8eb3d978109c1d5bf18be8cc1e1678afb6c017a Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 30 Dec 2014 23:10:01 -0500 Subject: Fix typo --- sx-request.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-request.el b/sx-request.el index 1031ea7..bc34f9c 100644 --- a/sx-request.el +++ b/sx-request.el @@ -162,7 +162,7 @@ the main content of the response is returned." .method .error_id .error_name .error_message)) (when (< (setq sx-request-remaining-api-requests .quota_remaining) sx-request-remaining-api-requests-message-threshold) - (sx-message "%d API requests reamining" + (sx-message "%d API requests remaining" sx-request-remaining-api-requests)) (sx-encoding-clean-content-deep .items))))))) -- cgit v1.2.3 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-api.el | 13 ++++ test/test-macros.el | 18 +++++ test/test-printing.el | 45 +++++++++++++ test/test-util.el | 66 +++++++++++++++++++ test/tests.el | 179 ++++++++------------------------------------------ 5 files changed, 169 insertions(+), 152 deletions(-) create mode 100644 test/test-api.el create mode 100644 test/test-macros.el create mode 100644 test/test-printing.el create mode 100644 test/test-util.el diff --git a/test/test-api.el b/test/test-api.el new file mode 100644 index 0000000..ca775ff --- /dev/null +++ b/test/test-api.el @@ -0,0 +1,13 @@ +(ert-deftest test-basic-request () + "Test basic request functionality" + (should (sx-request-make "sites"))) + +(ert-deftest test-question-retrieve () + "Test the ability to receive a list of questions." + (should (sx-question-get-questions 'emacs))) + +(ert-deftest test-bad-request () + "Test a method given a bad set of keywords" + (should-error + (sx-request-make "questions" '(())))) + 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)))))) + diff --git a/test/test-printing.el b/test/test-printing.el new file mode 100644 index 0000000..4fe31db --- /dev/null +++ b/test/test-printing.el @@ -0,0 +1,45 @@ + +;;; Setup +(require 'cl-lib) + +(defmacro line-should-match (regexp) + "" + `(let ((line (buffer-substring-no-properties + (line-beginning-position) + (line-end-position)))) + (message "Line here is: %S" line) + (should (string-match ,regexp line)))) + + +;;; Tests +(ert-deftest question-list-display () + (cl-letf (((symbol-function #'sx-request-make) + (lambda (&rest _) sx-test-data-questions))) + (sx-tab-frontpage nil "emacs") + (switch-to-buffer "*question-list*") + (goto-char (point-min)) + (should (equal (buffer-name) "*question-list*")) + (line-should-match + "^\\s-+1\\s-+0\\s-+Focus-hook: attenuate colours when losing focus [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[frames\\] \\[hooks\\] \\[focus\\]") + (sx-question-list-next 5) + (line-should-match + "^\\s-+0\\s-+1\\s-+Babel doesn't wrap results in verbatim [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[org-mode\\]") + ;; ;; Use this when we have a real sx-question buffer. + ;; (call-interactively 'sx-question-list-display-question) + ;; (should (equal (buffer-name) "*sx-question*")) + (switch-to-buffer "*question-list*") + (sx-question-list-previous 4) + (line-should-match + "^\\s-+2\\s-+1\\s-+"Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[autocomplete\\]"))) + +(ert-deftest sx--user-@name () + "Tests macro expansion for `sx-assoc-let'" + (should + (string= + (sx--user-@name '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) + "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj")) + (should + (string= + (sx--user-@name '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) + "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) + diff --git a/test/test-util.el b/test/test-util.el new file mode 100644 index 0000000..53dc200 --- /dev/null +++ b/test/test-util.el @@ -0,0 +1,66 @@ +(ert-deftest test-tree-filter () + "`sx-core-filter-data'" + ;; flat + (should + (equal + '((1 . t) (2 . [1 2]) (3)) + (sx--filter-data '((0 . 3) (1 . t) (a . five) (2 . [1 2]) + ("5" . bop) (3) (p . 4)) + '(1 2 3)))) + ;; complex + (should + (equal + '((1 . [a b c]) + (2 . [((a . 1) (c . 3)) + ((a . 4) (c . 6))]) + (3 . peach)) + (sx--filter-data '((1 . [a b c]) + (2 . [((a . 1) (b . 2) (c . 3)) + ((a . 4) (b . 5) (c . 6))]) + (3 . peach) + (4 . banana)) + '(1 (2 a c) 3)))) + + ;; vector + (should + (equal + [((1 . 2) (2 . 3) (3 . 4)) + ((1 . a) (2 . b) (3 . c)) + nil ((1 . alpha) (2 . beta))] + (sx--filter-data [((1 . 2) (2 . 3) (3 . 4)) + ((1 . a) (2 . b) (3 . c) (5 . seven)) + ((should-not-go)) + ((1 . alpha) (2 . beta))] + '(1 2 3))))) + +(ert-deftest thing-as-string () + "Tests `sx--thing-as-string'" + (should + (string= (sx--thing-as-string + '(hello world (this is a test)) + '(";" "+")) + "hello;world;this+is+a+test")) + (should + (string= (sx--thing-as-string + '(this is a test) '(";" "+")) + "this;is;a;test")) + (should + (string= (sx--thing-as-string + '(this is a test) "+") + "this+is+a+test")) + (should + (string= (sx--thing-as-string + '(this is a test)) + "this;is;a;test")) + (should + (string= (sx--thing-as-string + 'test) + "test")) + (should + (string= (sx--thing-as-string + 'test&) + "test&")) + (should + (string= (sx--thing-as-string + 'test& nil t) + "test%26"))) diff --git a/test/tests.el b/test/tests.el index 3c275fd..daaa8b5 100644 --- a/test/tests.el +++ b/test/tests.el @@ -1,3 +1,5 @@ + +;;; SX Settings (defun -sx--nuke () (interactive) (mapatoms @@ -5,11 +7,17 @@ (if (string-prefix-p "sx-" (symbol-name symbol)) (unintern symbol))))) -;;; Tests +(setq + sx-initialized t + sx-request-remaining-api-requests-message-threshold 50000 + debug-on-error t + user-emacs-directory "." + sx-test-base-dir (file-name-directory (or load-file-name "./"))) + + +;;; Test Data (defvar sx-test-data-dir - (expand-file-name - "data-samples/" - (file-name-directory (or load-file-name "./")))) + (expand-file-name "data-samples/" sx-test-base-dir)) (defun sx-test-sample-data (method &optional directory) (let ((file (concat (when directory (concat directory "/")) @@ -20,161 +28,28 @@ (insert-file-contents file) (read (buffer-string)))))) -(defmacro line-should-match (regexp) - "" - `(let ((line (buffer-substring-no-properties - (line-beginning-position) - (line-end-position)))) - (message "Line here is: %S" line) - (should (string-match ,regexp line)))) - (setq - sx-initialized t - sx-request-remaining-api-requests-message-threshold 50000 - debug-on-error t - user-emacs-directory "." - sx-test-data-questions (sx-test-sample-data "questions") sx-test-data-sites (sx-test-sample-data "sites")) -(setq package-user-dir - (expand-file-name (format "../../.cask/%s/elpa" emacs-version) - sx-test-data-dir)) -(package-initialize) - -(require 'cl-lib) -(require 'sx) -(require 'sx-question) -(require 'sx-question-list) -(require 'sx-tab) - -(ert-deftest test-basic-request () - "Test basic request functionality" - (should (sx-request-make "sites"))) - -(ert-deftest test-question-retrieve () - "Test the ability to receive a list of questions." - (should (sx-question-get-questions 'emacs))) - -(ert-deftest test-bad-request () - "Test a method given a bad set of keywords" - (should-error - (sx-request-make "questions" '(())))) - -(ert-deftest test-tree-filter () - "`sx-core-filter-data'" - ;; flat - (should - (equal - '((1 . t) (2 . [1 2]) (3)) - (sx--filter-data '((0 . 3) (1 . t) (a . five) (2 . [1 2]) - ("5" . bop) (3) (p . 4)) - '(1 2 3)))) - ;; complex - (should - (equal - '((1 . [a b c]) - (2 . [((a . 1) (c . 3)) - ((a . 4) (c . 6))]) - (3 . peach)) - (sx--filter-data '((1 . [a b c]) - (2 . [((a . 1) (b . 2) (c . 3)) - ((a . 4) (b . 5) (c . 6))]) - (3 . peach) - (4 . banana)) - '(1 (2 a c) 3)))) - - ;; vector - (should - (equal - [((1 . 2) (2 . 3) (3 . 4)) - ((1 . a) (2 . b) (3 . c)) - nil ((1 . alpha) (2 . beta))] - (sx--filter-data [((1 . 2) (2 . 3) (3 . 4)) - ((1 . a) (2 . b) (3 . c) (5 . seven)) - ((should-not-go)) - ((1 . alpha) (2 . beta))] - '(1 2 3))))) - -(ert-deftest question-list-display () - (cl-letf (((symbol-function #'sx-request-make) - (lambda (&rest _) sx-test-data-questions))) - (sx-tab-frontpage nil "emacs") - (switch-to-buffer "*question-list*") - (goto-char (point-min)) - (should (equal (buffer-name) "*question-list*")) - (line-should-match - "^\\s-+1\\s-+0\\s-+Focus-hook: attenuate colours when losing focus [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[frames\\] \\[hooks\\] \\[focus\\]") - (sx-question-list-next 5) - (line-should-match - "^\\s-+0\\s-+1\\s-+Babel doesn't wrap results in verbatim [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[org-mode\\]") - ;; ;; Use this when we have a real sx-question buffer. - ;; (call-interactively 'sx-question-list-display-question) - ;; (should (equal (buffer-name) "*sx-question*")) - (switch-to-buffer "*question-list*") - (sx-question-list-previous 4) - (line-should-match - "^\\s-+2\\s-+1\\s-+"Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[autocomplete\\]"))) - -(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)))) + +;;; General Settings +(setq + package-user-dir (expand-file-name + (format "../../.cask/%s/elpa" emacs-version) + sx-test-data-dir)) - (let ((data (copy-tree prototype))) - (should - (equal (sx-assoc-let data .site) - "meta.emacs"))) +(package-initialize) - (let ((data (copy-tree prototype))) - (should - (equal (sx-assoc-let data (cons .test-one .test-two)) - '(1 . 2)))))) +(require 'sx-load) -(ert-deftest sx--user-@name () - "Tests macro expansion for `sx-assoc-let'" - (should - (string= - (sx--user-@name '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) - "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj")) - (should - (string= - (sx--user-@name '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) - "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) +(defun sx-load-test (test) + (load-file + (format "%s/test-%s.el" + sx-test-base-dir + (symbol-name test)))) -(ert-deftest thing-as-string () - "Tests `sx--thing-as-string'" - (should - (string= (sx--thing-as-string - '(hello world (this is a test)) - '(";" "+")) - "hello;world;this+is+a+test")) - (should - (string= (sx--thing-as-string - '(this is a test) '(";" "+")) - "this;is;a;test")) - (should - (string= (sx--thing-as-string - '(this is a test) "+") - "this+is+a+test")) - (should - (string= (sx--thing-as-string - '(this is a test)) - "this;is;a;test")) - (should - (string= (sx--thing-as-string - 'test) - "test")) - (should - (string= (sx--thing-as-string - 'test&) - "test&")) - (should - (string= (sx--thing-as-string - 'test& nil t) - "test%26"))) +(mapc #'sx-load-test + '(api macros printing util)) -- 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(-) 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 eed71f7024169c2d400ef5d0a84595d186c81bb0 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 13:51:22 -0500 Subject: Simplify question list display tests Use a macro (using `rx') to create the regular expression for the question list display test. --- test/test-printing.el | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/test-printing.el b/test/test-printing.el index 4fe31db..0ea5b03 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -10,6 +10,18 @@ (message "Line here is: %S" line) (should (string-match ,regexp line)))) +(defmacro question-list-regex (title votes answers &rest tags) + `(rx line-start + (+ whitespace) ,(number-to-string votes) + (+ whitespace) ,(number-to-string answers) + (+ whitespace) + ,title + (+ (any whitespace digit)) + (or "y" "d" "h" "m" "mo" "s") " ago" + (+ whitespace) + (eval (mapconcat #'sx-question--tag-format + (list ,@tags) " ")))) + ;;; Tests (ert-deftest question-list-display () @@ -20,17 +32,23 @@ (goto-char (point-min)) (should (equal (buffer-name) "*question-list*")) (line-should-match - "^\\s-+1\\s-+0\\s-+Focus-hook: attenuate colours when losing focus [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[frames\\] \\[hooks\\] \\[focus\\]") + (question-list-regex + "Focus-hook: attenuate colours when losing focus" + 1 0 "frames" "hooks" "focus")) (sx-question-list-next 5) (line-should-match - "^\\s-+0\\s-+1\\s-+Babel doesn't wrap results in verbatim [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[org-mode\\]") + (question-list-regex + "Babel doesn't wrap results in verbatim" + 0 1 "org-mode" "org-export" "org-babel")) ;; ;; Use this when we have a real sx-question buffer. ;; (call-interactively 'sx-question-list-display-question) ;; (should (equal (buffer-name) "*sx-question*")) (switch-to-buffer "*question-list*") (sx-question-list-previous 4) (line-should-match - "^\\s-+2\\s-+1\\s-+"Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[autocomplete\\]"))) + (question-list-regex + ""Making tag completion table" Freezes/Blocks -- how to disable" + 2 1 "autocomplete" "performance" "ctags")))) (ert-deftest sx--user-@name () "Tests macro expansion for `sx-assoc-let'" -- 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(-) 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 From 1518cee93ef2d33af9ddf214ae1c181d02c7b94f Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 14:14:05 -0500 Subject: Add toggle for detailed test messages --- test/test-printing.el | 9 ++++++++- test/tests.el | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/test-printing.el b/test/test-printing.el index 2260a00..6225bf6 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -7,7 +7,7 @@ `(let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) - (message "Line here is: %S" line) + (sx-test-message "Line here is: %S" line) (should (string-match ,regexp line)))) (defmacro question-list-regex (title votes answers &rest tags) @@ -27,6 +27,13 @@ after being run through `sx-question--tag-format'." ;;; Tests +(ert-deftest question-list-tag () + "Test `sx-question--tag-format'." + (should + (string= + (sx-question--tag-format "tag") + "[tag]"))) + (ert-deftest question-list-display () (cl-letf (((symbol-function #'sx-request-make) (lambda (&rest _) sx-test-data-questions))) diff --git a/test/tests.el b/test/tests.el index daaa8b5..d709600 100644 --- a/test/tests.el +++ b/test/tests.el @@ -51,5 +51,11 @@ sx-test-base-dir (symbol-name test)))) +(setq sx-test-enable-messages nil) + +(defun sx-test-message (message &rest args) + (when sx-test-enable-messages + (apply #'message (cons message args)))) + (mapc #'sx-load-test '(api macros printing util)) -- cgit v1.2.3 From 7d73bc8b9da4a093b0a3b477da81252d5b805ca5 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 14:19:58 -0500 Subject: Prune sx--filter-data --- sx.el | 44 -------------------------------------------- test/test-util.el | 35 ----------------------------------- 2 files changed, 79 deletions(-) diff --git a/sx.el b/sx.el index 8fe31ac..73d1a40 100644 --- a/sx.el +++ b/sx.el @@ -239,50 +239,6 @@ and sequences of strings." (funcall first-f sequence-sep) ";")))))) -(defun sx--filter-data (data desired-tree) - "Filter DATA and return the DESIRED-TREE. - -For example: - - (sx--filter-data - '((prop1 . value1) - (prop2 . value2) - (prop3 - (test1 . 1) - (test2 . 2)) - (prop4 . t)) - '(prop1 (prop3 test2))) - -would yield - - ((prop1 . value1) - (prop3 - (test2 . 2)))" - (if (vectorp data) - (apply #'vector - (mapcar (lambda (entry) - (sx--filter-data - entry desired-tree)) - data)) - (delq - nil - (mapcar (lambda (cons-cell) - ;; @TODO the resolution of `f' is O(2n) in the worst - ;; case. It may be faster to implement the same - ;; functionality as a `while' loop to stop looking the - ;; list once it has found a match. Do speed tests. - ;; See edfab4443ec3d376c31a38bef12d305838d3fa2e. - (let ((f (or (memq (car cons-cell) desired-tree) - (assoc (car cons-cell) desired-tree)))) - (when f - (if (and (sequencep (cdr cons-cell)) - (sequencep (elt (cdr cons-cell) 0))) - (cons (car cons-cell) - (sx--filter-data - (cdr cons-cell) (cdr f))) - cons-cell)))) - data)))) - (defun sx--shorten-url (url) "Shorten URL hiding anything other than the domain. Paths after the domain are replaced with \"...\". diff --git a/test/test-util.el b/test/test-util.el index 49df274..5db1691 100644 --- a/test/test-util.el +++ b/test/test-util.el @@ -1,38 +1,3 @@ -(ert-deftest test-tree-filter () - "Test `sx-core-filter-data'" - ;; flat - (should - (equal - '((1 . t) (2 . [1 2]) (3)) - (sx--filter-data '((0 . 3) (1 . t) (a . five) (2 . [1 2]) - ("5" . bop) (3) (p . 4)) - '(1 2 3)))) - ;; complex - (should - (equal - '((1 . [a b c]) - (2 . [((a . 1) (c . 3)) - ((a . 4) (c . 6))]) - (3 . peach)) - (sx--filter-data '((1 . [a b c]) - (2 . [((a . 1) (b . 2) (c . 3)) - ((a . 4) (b . 5) (c . 6))]) - (3 . peach) - (4 . banana)) - '(1 (2 a c) 3)))) - - ;; vector - (should - (equal - [((1 . 2) (2 . 3) (3 . 4)) - ((1 . a) (2 . b) (3 . c)) - nil ((1 . alpha) (2 . beta))] - (sx--filter-data [((1 . 2) (2 . 3) (3 . 4)) - ((1 . a) (2 . b) (3 . c) (5 . seven)) - ((should-not-go)) - ((1 . alpha) (2 . beta))] - '(1 2 3))))) - (ert-deftest thing-as-string () "Test `sx--thing-as-string'" (should -- cgit v1.2.3 From b4ac5e67f55147db98e17f9e2df8d7e044b6bcdf Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 17:07:38 -0500 Subject: Remove redundant consing --- test/tests.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests.el b/test/tests.el index d709600..53e053f 100644 --- a/test/tests.el +++ b/test/tests.el @@ -55,7 +55,7 @@ (defun sx-test-message (message &rest args) (when sx-test-enable-messages - (apply #'message (cons message args)))) + (apply #'message message args))) (mapc #'sx-load-test '(api macros printing util)) -- cgit v1.2.3 From bf4f193a76100917764f249023f4844a2ca15b2c Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 19:01:36 -0500 Subject: Fix docstring --- test/test-printing.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-printing.el b/test/test-printing.el index 6225bf6..2857cb7 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -61,7 +61,7 @@ after being run through `sx-question--tag-format'." 2 1 "autocomplete" "performance" "ctags")))) (ert-deftest sx--user-@name () - "Test macro expansion for `sx-assoc-let'" + "Test `sx--user-@name' character substitution" (should (string= (sx--user-@name '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) -- cgit v1.2.3