aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2015-01-04 16:23:34 -0500
committerSean Allred <code@seanallred.com>2015-01-04 16:23:34 -0500
commit671053bf0824197fefe742ed9dd98c1b9a06565a (patch)
tree3f457adffd80d7c180b52e936cef3698b067f28b /test
parent3b275a93789a568d23ece65086ffebb8de430f3a (diff)
parent3c05aae9915976e749591600f6e8f59cbccef1a4 (diff)
Merge branch 'master' into more-tests
Conflicts: Makefile test/tests.el
Diffstat (limited to 'test')
-rw-r--r--test/data-samples/inbox-item.el13
-rw-r--r--test/test-api.el3
-rw-r--r--test/test-macros.el26
-rw-r--r--test/test-printing.el2
-rw-r--r--test/test-search.el53
-rw-r--r--test/test-state.el22
-rw-r--r--test/test-util.el14
-rw-r--r--test/tests.el5
8 files changed, 133 insertions, 5 deletions
diff --git a/test/data-samples/inbox-item.el b/test/data-samples/inbox-item.el
new file mode 100644
index 0000000..faeba12
--- /dev/null
+++ b/test/data-samples/inbox-item.el
@@ -0,0 +1,13 @@
+((title . "Can I mark inbox items as read in api v2.2?")
+ (link . "http://stackapps.com/posts/comments/12080?noredirect=1")
+ (item_type . "comment")
+ (question_id . 5059)
+ (comment_id . 12080)
+ (creation_date . 1419153905)
+ (is_unread . :json-false)
+ (site (site_type . "main_site")
+ (name . "Stack Apps")
+ (api_site_parameter . "stackapps")
+ (site_url . "http://stackapps.com")
+ (favicon_url . "http://cdn.sstatic.net/stackapps/img/favicon.ico")
+ (styling (link_color . "#0077DD") (tag_foreground_color . "#555555") (tag_background_color . "#E7ECEC"))))
diff --git a/test/test-api.el b/test/test-api.el
index ca775ff..b7d5dbb 100644
--- a/test/test-api.el
+++ b/test/test-api.el
@@ -11,3 +11,6 @@
(should-error
(sx-request-make "questions" '(()))))
+(ert-deftest test-method-get-all ()
+ "Tests sx-method interface to `sx-request-all-items'"
+ (should (< 250 (length (sx-method-call 'sites :get-all t)))))
diff --git a/test/test-macros.el b/test/test-macros.el
index 2169088..1634603 100644
--- a/test/test-macros.el
+++ b/test/test-macros.el
@@ -9,14 +9,36 @@
"Test `sx-assoc-let'"
(sx-test-with-json-data data
(should
- (null (let-alist data .site))))
+ (null (let-alist data .site_par))))
(sx-test-with-json-data data
(should
- (equal (sx-assoc-let data .site)
+ (equal (sx-assoc-let data .site_par)
"meta.emacs")))
(sx-test-with-json-data data
(should
(equal (sx-assoc-let data (cons .test-one .test-two))
'(1 . 2)))))
+
+(ert-deftest macro-test--sx-filter-from-nil ()
+ "Test `sx-filter-from-nil'"
+ (should
+ (equal
+ (sx-filter-from-nil
+ (one two (three four five) (six seven)
+ (a b c d e)))
+ '((one two three.four three.five six.seven
+ a.b a.c a.d a.e
+ .backoff
+ .error_id
+ .error_message
+ .error_name
+ .has_more
+ .items
+ .page
+ .page_size
+ .quota_max
+ .quota_remaining
+ .total)
+ nil none))))
diff --git a/test/test-printing.el b/test/test-printing.el
index 60382b2..29c209d 100644
--- a/test/test-printing.el
+++ b/test/test-printing.el
@@ -73,7 +73,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 . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★")))
diff --git a/test/test-search.el b/test/test-search.el
new file mode 100644
index 0000000..72f0846
--- /dev/null
+++ b/test/test-search.el
@@ -0,0 +1,53 @@
+(defmacro test-with-bogus-string (cell &rest body)
+ "Let-bind a bogus string to CELL and execute BODY."
+ (declare (indent 1))
+ `(let ((,cell "E7631BCF-A94B-4507-8F0C-02CFB3207F55"))
+ ,@body))
+
+
+(ert-deftest test-search-basic ()
+ "Test basic search functionality"
+ (should
+ (sx-search-get-questions
+ "emacs" 1 "emacs")))
+
+(ert-deftest test-search-empty ()
+ "Test bogus search returns empty vector"
+ (test-with-bogus-string query
+ (should
+ (equal
+ []
+ (sx-search-get-questions "emacs" 1 query)))))
+
+(ert-deftest test-search-invalid ()
+ "Test invalid search"
+ (should-error
+ ;; @todo: test the interactive call
+ (sx-search
+ "emacs" nil nil ["emacs"])))
+
+(ert-deftest test-search-full-page ()
+ "Test retrieval of the full search page"
+ (should
+ (= 100 (length (sx-search-get-questions
+ "stackoverflow" 1 "jquery")))))
+
+(ert-deftest test-search-exclude-tags ()
+ "Test excluding tags from a search"
+ (should
+ (cl-every
+ (lambda (p)
+ (sx-assoc-let p
+ (not (member "org-export" .tags))))
+ (sx-search-get-questions
+ "emacs" 1 nil "org-mode" "org-export")))
+ (should
+ (cl-every
+ (lambda (p)
+ (sx-assoc-let p
+ (not (or (member "org-export" .tags)
+ (member "org-agenda" .tags)))))
+ (sx-search-get-questions
+ "emacs" 1 nil "org-mode"
+ ["org-export" "org-agenda"]))))
+
diff --git a/test/test-state.el b/test/test-state.el
new file mode 100644
index 0000000..7af4a64
--- /dev/null
+++ b/test/test-state.el
@@ -0,0 +1,22 @@
+(defmacro with-question-data (cell id &rest body)
+ (declare (indent 2))
+ `(let ((,cell '((question_id . ,id)
+ (site_par . "emacs")
+ (last_activity_date . 1234123456))))
+ ,@body))
+
+(ert-deftest test-question-mark-read ()
+ "00ccd139248e782cd8316eff65c26aed838c7e46"
+ (with-question-data q 10
+ ;; Check basic logic.
+ (should (sx-question--mark-read q))
+ (should (sx-question--read-p q))
+ (should (not (setcdr (assq 10 (cdr (assoc "emacs" sx-question--user-read-list))) nil)))
+ ;; Don't freak out because the cdr was nil.
+ (should (not (sx-question--read-p q)))
+ (should (sx-question--mark-read q)))
+ (should
+ (with-question-data q nil
+ ;; Don't freak out because question_id was nil.
+ (sx-question--mark-read q))))
+
diff --git a/test/test-util.el b/test/test-util.el
index 5db1691..1e3dc2b 100644
--- a/test/test-util.el
+++ b/test/test-util.el
@@ -29,3 +29,17 @@
(string= (sx--thing-as-string
'test& nil t)
"test%26")))
+
+(ert-deftest tree ()
+ (should
+ (equal
+ (sx--tree-expand
+ (lambda (path) (mapconcat #'symbol-name path "."))
+ '(a b (c d (e f g) h i (j k) l) m (n o) p))
+ '("a" "b" "c.d" "c.e.f" "c.e.g" "c.h" "c.i" "c.j.k" "c.l" "m" "n.o" "p")))
+ (should
+ (equal
+ (sx--tree-expand
+ (lambda (path) (intern (mapconcat #'symbol-name path "/")))
+ '(a b (c d (e f g) h i (j k) l) m (n o) p))
+ '(a b c/d c/e/f c/e/g c/h c/i c/j/k c/l m n/o p))))
diff --git a/test/tests.el b/test/tests.el
index 7bfc86c..5eec57c 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -11,6 +11,7 @@
sx-initialized t
sx-request-remaining-api-requests-message-threshold 50000
debug-on-error t
+ url-show-status nil
user-emacs-directory "."
sx-test-base-dir (file-name-directory (or load-file-name "./")))
@@ -55,10 +56,10 @@
(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))
+ '(api macros printing util search))
(ert-deftest user-entry-functions ()
"Ensures all entry functions are autoloaded."