diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/data-samples/inbox-item.el | 13 | ||||
-rw-r--r-- | test/test-macros.el | 4 | ||||
-rw-r--r-- | test/test-search.el | 53 | ||||
-rw-r--r-- | test/tests.el | 2 |
4 files changed, 69 insertions, 3 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-macros.el b/test/test-macros.el index 2169088..b6bf20b 100644 --- a/test/test-macros.el +++ b/test/test-macros.el @@ -9,11 +9,11 @@ "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 diff --git a/test/test-search.el b/test/test-search.el new file mode 100644 index 0000000..72dbcdc --- /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 + (= 30 (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/tests.el b/test/tests.el index bb2f9f4..ce42a9f 100644 --- a/test/tests.el +++ b/test/tests.el @@ -59,4 +59,4 @@ (apply #'message message args))) (mapc #'sx-load-test - '(api macros printing util)) + '(api macros printing util search)) |