aboutsummaryrefslogtreecommitdiff
path: root/test/mastodon-tl-tests.el
diff options
context:
space:
mode:
authormousebot <mousebot@riseup.net>2021-12-16 14:52:51 +0100
committermousebot <mousebot@riseup.net>2021-12-16 14:52:51 +0100
commita3dd830e4e7b5eddfc21975506fe5461a36c2a89 (patch)
treea7f3dc80903bee7fd7cdff55c6f9e5566b0b9acd /test/mastodon-tl-tests.el
parent3014e10ec268250a130ac490b5f32b3d263ad21b (diff)
parent7eb4bd98075b70a688701873d8c3488fbedd4c1f (diff)
Merge branch 'develop' into media-type
Diffstat (limited to 'test/mastodon-tl-tests.el')
-rw-r--r--test/mastodon-tl-tests.el445
1 files changed, 227 insertions, 218 deletions
diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el
index 4edf5d5..da3b315 100644
--- a/test/mastodon-tl-tests.el
+++ b/test/mastodon-tl-tests.el
@@ -1,3 +1,5 @@
+;;; mastodon-tl-test.el --- Tests for mastodon-tl.el -*- lexical-binding: nil -*-
+
(require 'cl-lib)
(require 'cl-macs)
(require 'el-mock)
@@ -89,64 +91,64 @@
(reblogged)))
"A sample reblogged/boosted toot (parsed json)")
-(ert-deftest remove-html-1 ()
+(ert-deftest mastodon-tl--remove-html-1 ()
"Should remove all <span> tags."
(let ((input "<span class=\"h-card\">foobar</span> <span>foobaz</span>"))
(should (string= (mastodon-tl--remove-html input) "foobar foobaz"))))
-(ert-deftest remove-html-2 ()
+(ert-deftest mastodon-tl--remove-html-2 ()
"Should replace <\p> tags with two new lines."
(let ((input "foobar</p>"))
(should (string= (mastodon-tl--remove-html input) "foobar\n\n"))))
-(ert-deftest toot-id-boosted ()
+(ert-deftest mastodon-tl--toot-id-boosted ()
"If a toot is boostedm, return the reblog id."
(should (string= (mastodon-tl--as-string
(mastodon-tl--toot-id mastodon-tl-test-base-boosted-toot))
"4543919")))
-(ert-deftest toot-id ()
+(ert-deftest mastodon-tl--toot-id ()
"If a toot is boostedm, return the reblog id."
(should (string= (mastodon-tl--as-string
(mastodon-tl--toot-id mastodon-tl-test-base-toot))
"61208")))
-(ert-deftest as-string-1 ()
+(ert-deftest mastodon-tl--as-string-1 ()
"Should accept a string or number and return a string."
(let ((id "1000"))
(should (string= (mastodon-tl--as-string id) id))))
-(ert-deftest as-string-2 ()
+(ert-deftest mastodon-tl--as-string-2 ()
"Should accept a string or number and return a string."
(let ((id 1000))
(should (string= (mastodon-tl--as-string id) (number-to-string id)))))
-(ert-deftest more-json ()
+(ert-deftest mastodon-tl--more-json ()
"Should request toots older than max_id."
(let ((mastodon-instance-url "https://instance.url"))
(with-mock
- (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?max_id=12345"))
- (mastodon-tl--more-json "timelines/foo" 12345))))
+ (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?max_id=12345"))
+ (mastodon-tl--more-json "timelines/foo" 12345))))
-(ert-deftest more-json-id-string ()
+(ert-deftest mastodon-tl--more-json-id-string ()
"Should request toots older than max_id.
`mastodon-tl--more-json' should accept and id that is either
a string or a numeric."
(let ((mastodon-instance-url "https://instance.url"))
(with-mock
- (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?max_id=12345"))
- (mastodon-tl--more-json "timelines/foo" "12345"))))
+ (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?max_id=12345"))
+ (mastodon-tl--more-json "timelines/foo" "12345"))))
-(ert-deftest update-json-id-string ()
+(ert-deftest mastodon-tl--update-json-id-string ()
"Should request toots more recent than since_id.
`mastodon-tl--updated-json' should accept and id that is either
a string or a numeric."
(let ((mastodon-instance-url "https://instance.url"))
(with-mock
- (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?since_id=12345"))
- (mastodon-tl--updated-json "timelines/foo" "12345"))))
+ (mock (mastodon-http--get-json "https://instance.url/api/v1/timelines/foo?since_id=12345"))
+ (mastodon-tl--updated-json "timelines/foo" "12345"))))
(ert-deftest mastodon-tl--relative-time-description ()
"Should format relative time as expected"
@@ -253,39 +255,39 @@ a string or a numeric."
(let ((mastodon-tl--show-avatars-p nil)
(timestamp (cdr (assoc 'created_at mastodon-tl-test-base-toot))))
(with-mock
- (mock (date-to-time timestamp) => '(22782 21551))
- (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
-
- (let ((byline (mastodon-tl--byline mastodon-tl-test-base-toot
- 'mastodon-tl--byline-author
- 'mastodon-tl--byline-boosted))
- (handle-location 20))
- (should (string= (substring-no-properties
- byline)
- "Account 42 (@acct42@example.space) 2999-99-99 00:11:22
+ (mock (date-to-time timestamp) => '(22782 21551))
+ (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
+
+ (let ((byline (mastodon-tl--byline mastodon-tl-test-base-toot
+ 'mastodon-tl--byline-author
+ 'mastodon-tl--byline-boosted))
+ (handle-location 20))
+ (should (string= (substring-no-properties
+ byline)
+ "Account 42 (@acct42@example.space) 2999-99-99 00:11:22
------------
"))
- (should (eq (get-text-property handle-location 'mastodon-tab-stop byline)
- 'user-handle))
- (should (string= (get-text-property handle-location 'mastodon-handle byline)
- "@acct42@example.space"))
- (should (equal (get-text-property handle-location 'help-echo byline)
- "Browse user profile of @acct42@example.space"))))))
+ (should (eq (get-text-property handle-location 'mastodon-tab-stop byline)
+ 'user-handle))
+ (should (string= (get-text-property handle-location 'mastodon-handle byline)
+ "@acct42@example.space"))
+ (should (equal (get-text-property handle-location 'help-echo byline)
+ "Browse user profile of @acct42@example.space"))))))
(ert-deftest mastodon-tl--byline-regular-with-avatar ()
"Should format the regular toot correctly."
(let ((mastodon-tl--show-avatars-p t)
(timestamp (cdr (assoc 'created_at mastodon-tl-test-base-toot))))
(with-mock
- (stub create-image => '(image "fake data"))
- (mock (date-to-time timestamp) => '(22782 21551))
- (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
-
- (should (string= (substring-no-properties
- (mastodon-tl--byline mastodon-tl-test-base-toot
- 'mastodon-tl--byline-author
- 'mastodon-tl--byline-boosted))
- "Account 42 (@acct42@example.space) 2999-99-99 00:11:22
+ (stub create-image => '(image "fake data"))
+ (mock (date-to-time timestamp) => '(22782 21551))
+ (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
+
+ (should (string= (substring-no-properties
+ (mastodon-tl--byline mastodon-tl-test-base-toot
+ 'mastodon-tl--byline-author
+ 'mastodon-tl--byline-boosted))
+ "Account 42 (@acct42@example.space) 2999-99-99 00:11:22
------------
")))))
@@ -295,14 +297,14 @@ a string or a numeric."
(toot (cons '(reblogged . t) mastodon-tl-test-base-toot))
(timestamp (cdr (assoc 'created_at toot))))
(with-mock
- (mock (date-to-time timestamp) => '(22782 21551))
- (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
-
- (should (string= (substring-no-properties
- (mastodon-tl--byline toot
- 'mastodon-tl--byline-author
- 'mastodon-tl--byline-boosted))
- "(B) Account 42 (@acct42@example.space) 2999-99-99 00:11:22
+ (mock (date-to-time timestamp) => '(22782 21551))
+ (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
+
+ (should (string= (substring-no-properties
+ (mastodon-tl--byline toot
+ 'mastodon-tl--byline-author
+ 'mastodon-tl--byline-boosted))
+ "(B) Account 42 (@acct42@example.space) 2999-99-99 00:11:22
------------
")))))
@@ -312,14 +314,14 @@ a string or a numeric."
(toot (cons '(favourited . t) mastodon-tl-test-base-toot))
(timestamp (cdr (assoc 'created_at toot))))
(with-mock
- (mock (date-to-time timestamp) => '(22782 21551))
- (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
-
- (should (string= (substring-no-properties
- (mastodon-tl--byline toot
- 'mastodon-tl--byline-author
- 'mastodon-tl--byline-boosted))
- "(F) Account 42 (@acct42@example.space) 2999-99-99 00:11:22
+ (mock (date-to-time timestamp) => '(22782 21551))
+ (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
+
+ (should (string= (substring-no-properties
+ (mastodon-tl--byline toot
+ 'mastodon-tl--byline-author
+ 'mastodon-tl--byline-boosted))
+ "(F) Account 42 (@acct42@example.space) 2999-99-99 00:11:22
------------
")))))
@@ -330,14 +332,14 @@ a string or a numeric."
(toot `((favourited . t) (reblogged . t) ,@mastodon-tl-test-base-toot))
(timestamp (cdr (assoc 'created_at toot))))
(with-mock
- (mock (date-to-time timestamp) => '(22782 21551))
- (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
-
- (should (string= (substring-no-properties
- (mastodon-tl--byline toot
- 'mastodon-tl--byline-author
- 'mastodon-tl--byline-boosted))
- "(B) (F) Account 42 (@acct42@example.space) 2999-99-99 00:11:22
+ (mock (date-to-time timestamp) => '(22782 21551))
+ (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
+
+ (should (string= (substring-no-properties
+ (mastodon-tl--byline toot
+ 'mastodon-tl--byline-author
+ 'mastodon-tl--byline-boosted))
+ "(B) (F) Account 42 (@acct42@example.space) 2999-99-99 00:11:22
------------
")))))
@@ -349,31 +351,31 @@ a string or a numeric."
(timestamp (cdr (assoc 'created_at toot)))
(original-timestamp (cdr (assoc 'created_at original-toot))))
(with-mock
- ;; We don't expect to use the toot's timestamp but the timestamp of the
- ;; reblogged toot:
- (mock (date-to-time timestamp) => '(1 2))
- (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time")
- (mock (date-to-time original-timestamp) => '(3 4))
- (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time")
-
- (let ((byline (mastodon-tl--byline toot
- 'mastodon-tl--byline-author
- 'mastodon-tl--byline-boosted))
- (handle1-location 20)
- (handle2-location 65))
- (should (string= (substring-no-properties byline)
- "Account 42 (@acct42@example.space)
+ ;; We don't expect to use the toot's timestamp but the timestamp of the
+ ;; reblogged toot:
+ (mock (date-to-time timestamp) => '(1 2))
+ (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time")
+ (mock (date-to-time original-timestamp) => '(3 4))
+ (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time")
+
+ (let ((byline (mastodon-tl--byline toot
+ 'mastodon-tl--byline-author
+ 'mastodon-tl--byline-boosted))
+ (handle1-location 20)
+ (handle2-location 65))
+ (should (string= (substring-no-properties byline)
+ "Account 42 (@acct42@example.space)
Boosted Account 43 (@acct43@example.space) original time
------------
"))
- (should (eq (get-text-property handle1-location 'mastodon-tab-stop byline)
- 'user-handle))
- (should (equal (get-text-property handle1-location 'help-echo byline)
- "Browse user profile of @acct42@example.space"))
- (should (eq (get-text-property handle2-location 'mastodon-tab-stop byline)
- 'user-handle))
- (should (equal (get-text-property handle2-location 'help-echo byline)
- "Browse user profile of @acct43@example.space"))))))
+ (should (eq (get-text-property handle1-location 'mastodon-tab-stop byline)
+ 'user-handle))
+ (should (equal (get-text-property handle1-location 'help-echo byline)
+ "Browse user profile of @acct42@example.space"))
+ (should (eq (get-text-property handle2-location 'mastodon-tab-stop byline)
+ 'user-handle))
+ (should (equal (get-text-property handle2-location 'help-echo byline)
+ "Browse user profile of @acct43@example.space"))))))
(ert-deftest mastodon-tl--byline-reblogged-with-avatars ()
"Should format the reblogged toot correctly."
@@ -383,19 +385,19 @@ a string or a numeric."
(timestamp (cdr (assoc 'created_at toot)))
(original-timestamp (cdr (assoc 'created_at original-toot))))
(with-mock
- ;; We don't expect to use the toot's timestamp but the timestamp of the
- ;; reblogged toot:
- (stub create-image => '(image "fake data"))
- (mock (date-to-time timestamp) => '(1 2))
- (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time")
- (mock (date-to-time original-timestamp) => '(3 4))
- (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time")
-
- (should (string= (substring-no-properties
- (mastodon-tl--byline toot
- 'mastodon-tl--byline-author
- 'mastodon-tl--byline-boosted))
- "Account 42 (@acct42@example.space)
+ ;; We don't expect to use the toot's timestamp but the timestamp of the
+ ;; reblogged toot:
+ (stub create-image => '(image "fake data"))
+ (mock (date-to-time timestamp) => '(1 2))
+ (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time")
+ (mock (date-to-time original-timestamp) => '(3 4))
+ (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time")
+
+ (should (string= (substring-no-properties
+ (mastodon-tl--byline toot
+ 'mastodon-tl--byline-author
+ 'mastodon-tl--byline-boosted))
+ "Account 42 (@acct42@example.space)
Boosted Account 43 (@acct43@example.space) original time
------------
")))))
@@ -408,18 +410,18 @@ a string or a numeric."
(timestamp (cdr (assoc 'created_at toot)))
(original-timestamp (cdr (assoc 'created_at original-toot))))
(with-mock
- ;; We don't expect to use the toot's timestamp but the timestamp of the
- ;; reblogged toot:
- (mock (date-to-time timestamp) => '(1 2))
- (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time")
- (mock (date-to-time original-timestamp) => '(3 4))
- (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time")
-
- (should (string= (substring-no-properties
- (mastodon-tl--byline toot
- 'mastodon-tl--byline-author
- 'mastodon-tl--byline-boosted))
- "(B) (F) Account 42 (@acct42@example.space)
+ ;; We don't expect to use the toot's timestamp but the timestamp of the
+ ;; reblogged toot:
+ (mock (date-to-time timestamp) => '(1 2))
+ (mock (format-time-string mastodon-toot-timestamp-format '(1 2)) => "reblogging time")
+ (mock (date-to-time original-timestamp) => '(3 4))
+ (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time")
+
+ (should (string= (substring-no-properties
+ (mastodon-tl--byline toot
+ 'mastodon-tl--byline-author
+ 'mastodon-tl--byline-boosted))
+ "(B) (F) Account 42 (@acct42@example.space)
Boosted Account 43 (@acct43@example.space) original time
------------
")))))
@@ -429,17 +431,17 @@ a string or a numeric."
(let ((mastodon-tl--show-avatars-p nil)
(timestamp (cdr (assoc 'created_at mastodon-tl-test-base-toot))))
(with-mock
- (mock (date-to-time timestamp) => '(22782 21551))
- (mock (current-time) => '(22782 22000))
- (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
-
- (let* ((formatted-string (mastodon-tl--byline mastodon-tl-test-base-toot
- 'mastodon-tl--byline-author
- 'mastodon-tl--byline-boosted))
- (timestamp-start (string-match "2999-99-99" formatted-string))
- (properties (text-properties-at timestamp-start formatted-string)))
- (should (equal '(22782 21551) (plist-get properties 'timestamp)))
- (should (string-equal "7 minutes ago" (plist-get properties 'display)))))))
+ (mock (date-to-time timestamp) => '(22782 21551))
+ (mock (current-time) => '(22782 22000))
+ (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22")
+
+ (let* ((formatted-string (mastodon-tl--byline mastodon-tl-test-base-toot
+ 'mastodon-tl--byline-author
+ 'mastodon-tl--byline-boosted))
+ (timestamp-start (string-match "2999-99-99" formatted-string))
+ (properties (text-properties-at timestamp-start formatted-string)))
+ (should (equal '(22782 21551) (plist-get properties 'timestamp)))
+ (should (string-equal "7 minutes ago" (plist-get properties 'display)))))))
(ert-deftest mastodon-tl--consider-timestamp-for-updates-no-active-callback ()
"Should update the timestamp update variables as expected."
@@ -454,33 +456,33 @@ a string or a numeric."
;; something a later update doesn't update:
(with-mock
- (mock (mastodon-tl--relative-time-details 'fake-timestamp) =>
- (cons "xxx ago" (time-add long-in-the-future (seconds-to-time 100))))
+ (mock (mastodon-tl--relative-time-details 'fake-timestamp) =>
+ (cons "xxx ago" (time-add long-in-the-future (seconds-to-time 100))))
- (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp)
+ (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp)
- (should (null mastodon-tl--timestamp-update-timer))
- (should (eq mastodon-tl--timestamp-next-update long-in-the-future)))
+ (should (null mastodon-tl--timestamp-update-timer))
+ (should (eq mastodon-tl--timestamp-next-update long-in-the-future)))
;; something only shortly sooner doesn't update:
(with-mock
- (mock (mastodon-tl--relative-time-details 'fake-timestamp) =>
- (cons "xxx ago" (time-subtract long-in-the-future (seconds-to-time 9))))
+ (mock (mastodon-tl--relative-time-details 'fake-timestamp) =>
+ (cons "xxx ago" (time-subtract long-in-the-future (seconds-to-time 9))))
- (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp)
+ (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp)
- (should (null mastodon-tl--timestamp-update-timer))
- (should (eq mastodon-tl--timestamp-next-update long-in-the-future)))
+ (should (null mastodon-tl--timestamp-update-timer))
+ (should (eq mastodon-tl--timestamp-next-update long-in-the-future)))
;; something much sooner, does update
(with-mock
- (mock (mastodon-tl--relative-time-details 'fake-timestamp) =>
- (cons "xxx ago" soon-in-the-future))
+ (mock (mastodon-tl--relative-time-details 'fake-timestamp) =>
+ (cons "xxx ago" soon-in-the-future))
- (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp)
+ (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp)
- (should (null mastodon-tl--timestamp-update-timer))
- (should (eq mastodon-tl--timestamp-next-update soon-in-the-future)))
+ (should (null mastodon-tl--timestamp-update-timer))
+ (should (eq mastodon-tl--timestamp-next-update soon-in-the-future)))
)))
(ert-deftest mastodon-tl--consider-timestamp-for-updates-with-active-callback ()
@@ -496,27 +498,27 @@ a string or a numeric."
;; something a later update doesn't update:
(with-mock
- (mock (mastodon-tl--relative-time-details 'fake-timestamp) =>
- (cons "xxx ago" (time-add long-in-the-future (seconds-to-time 100))))
+ (mock (mastodon-tl--relative-time-details 'fake-timestamp) =>
+ (cons "xxx ago" (time-add long-in-the-future (seconds-to-time 100))))
- (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp)
+ (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp)
- (should (eq 'initial-timer mastodon-tl--timestamp-update-timer))
- (should (eq mastodon-tl--timestamp-next-update long-in-the-future)))
+ (should (eq 'initial-timer mastodon-tl--timestamp-update-timer))
+ (should (eq mastodon-tl--timestamp-next-update long-in-the-future)))
;; something much sooner, does update
(with-mock
- (mock (mastodon-tl--relative-time-details 'fake-timestamp) =>
- (cons "xxx ago" soon-in-the-future))
- (mock (cancel-timer 'initial-timer))
- (mock (run-at-time soon-in-the-future nil
- #'mastodon-tl--update-timestamps-callback
- (current-buffer) nil) => 'new-timer)
+ (mock (mastodon-tl--relative-time-details 'fake-timestamp) =>
+ (cons "xxx ago" soon-in-the-future))
+ (mock (cancel-timer 'initial-timer))
+ (mock (run-at-time soon-in-the-future nil
+ #'mastodon-tl--update-timestamps-callback
+ (current-buffer) nil) => 'new-timer)
- (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp)
+ (mastodon-tl--consider-timestamp-for-updates 'fake-timestamp)
- (should (eq 'new-timer mastodon-tl--timestamp-update-timer))
- (should (eq mastodon-tl--timestamp-next-update soon-in-the-future)))
+ (should (eq 'new-timer mastodon-tl--timestamp-update-timer))
+ (should (eq mastodon-tl--timestamp-next-update soon-in-the-future)))
)))
(ert-deftest mastodon-tl--find-property-range--no-tag ()
@@ -691,20 +693,20 @@ a string or a numeric."
(list 'r3 r3 r2 r3)
(list 'end end r3 end))))
(with-mock
- (stub message => nil) ;; don't mess up our test output with the function's messages
- (cl-dolist (test test-cases)
- (let ((test-name (cl-first test))
- (test-start (cl-second test))
- (expected-prev (cl-third test))
- (expected-next (cl-fourth test)))
- (goto-char test-start)
- (mastodon-tl--previous-tab-item)
- (should (equal (list 'prev test-name expected-prev)
- (list 'prev test-name (point))))
- (goto-char test-start)
- (mastodon-tl--next-tab-item)
- (should (equal (list 'next test-name expected-next)
- (list 'next test-name (point)))))))))))
+ (stub message => nil) ;; don't mess up our test output with the function's messages
+ (cl-dolist (test test-cases)
+ (let ((test-name (cl-first test))
+ (test-start (cl-second test))
+ (expected-prev (cl-third test))
+ (expected-next (cl-fourth test)))
+ (goto-char test-start)
+ (mastodon-tl--previous-tab-item)
+ (should (equal (list 'prev test-name expected-prev)
+ (list 'prev test-name (point))))
+ (goto-char test-start)
+ (mastodon-tl--next-tab-item)
+ (should (equal (list 'next test-name expected-next)
+ (list 'next test-name (point)))))))))))
(ert-deftest mastodon-tl--next-tab-item--no-spaces-at-ends ()
"Should do the correct tab actions even with regions right at buffer ends."
@@ -739,20 +741,20 @@ a string or a numeric."
(list 'gap2 gap2 r3 r4)
(list 'r4 r4 r3 r4))))
(with-mock
- (stub message => nil) ;; don't mess up our test output with the function's messages
- (cl-dolist (test test-cases)
- (let ((test-name (cl-first test))
- (test-start (cl-second test))
- (expected-prev (cl-third test))
- (expected-next (cl-fourth test)))
- (goto-char test-start)
- (mastodon-tl--previous-tab-item)
- (should (equal (list 'prev test-name expected-prev)
- (list 'prev test-name (point))))
- (goto-char test-start)
- (mastodon-tl--next-tab-item)
- (should (equal (list 'next test-name expected-next)
- (list 'next test-name (point)))))))))))
+ (stub message => nil) ;; don't mess up our test output with the function's messages
+ (cl-dolist (test test-cases)
+ (let ((test-name (cl-first test))
+ (test-start (cl-second test))
+ (expected-prev (cl-third test))
+ (expected-next (cl-fourth test)))
+ (goto-char test-start)
+ (mastodon-tl--previous-tab-item)
+ (should (equal (list 'prev test-name expected-prev)
+ (list 'prev test-name (point))))
+ (goto-char test-start)
+ (mastodon-tl--next-tab-item)
+ (should (equal (list 'next test-name expected-next)
+ (list 'next test-name (point)))))))))))
(defun tl-tests--property-values-at (property ranges)
@@ -781,33 +783,33 @@ constant."
(setq markers (nreverse markers))
(with-mock
- (mock (current-time) => now)
- (stub run-at-time => 'fake-timer)
-
- ;; make the initial call
- (mastodon-tl--update-timestamps-callback (current-buffer) nil)
- (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago"
- "unset 7" "unset 8" "unset 9" "unset 10" "unset 11" "unset 12" "unset 13")
- (tl-tests--property-values-at 'display
- (tl-tests--all-regions-with-property 'timestamp))))
-
- ;; fake the follow-up call
- (mastodon-tl--update-timestamps-callback (current-buffer) (nth 4 markers))
- (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago"
- "7 minutes ago" "8 minutes ago" "9 minutes ago" "10 minutes ago" "11 minutes ago"
- "unset 12" "unset 13")
- (tl-tests--property-values-at 'display
- (tl-tests--all-regions-with-property 'timestamp))))
- (should (null (marker-position (nth 4 markers))))
-
- ;; fake the follow-up call
- (mastodon-tl--update-timestamps-callback (current-buffer) (nth 9 markers))
- (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago"
- "7 minutes ago" "8 minutes ago" "9 minutes ago" "10 minutes ago" "11 minutes ago"
- "12 minutes ago" "13 minutes ago")
- (tl-tests--property-values-at 'display
- (tl-tests--all-regions-with-property 'timestamp))))
- (should (null (marker-position (nth 9 markers)))))))))
+ (mock (current-time) => now)
+ (stub run-at-time => 'fake-timer)
+
+ ;; make the initial call
+ (mastodon-tl--update-timestamps-callback (current-buffer) nil)
+ (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago"
+ "unset 7" "unset 8" "unset 9" "unset 10" "unset 11" "unset 12" "unset 13")
+ (tl-tests--property-values-at 'display
+ (tl-tests--all-regions-with-property 'timestamp))))
+
+ ;; fake the follow-up call
+ (mastodon-tl--update-timestamps-callback (current-buffer) (nth 4 markers))
+ (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago"
+ "7 minutes ago" "8 minutes ago" "9 minutes ago" "10 minutes ago" "11 minutes ago"
+ "unset 12" "unset 13")
+ (tl-tests--property-values-at 'display
+ (tl-tests--all-regions-with-property 'timestamp))))
+ (should (null (marker-position (nth 4 markers))))
+
+ ;; fake the follow-up call
+ (mastodon-tl--update-timestamps-callback (current-buffer) (nth 9 markers))
+ (should (equal '("2 minutes ago" "3 minutes ago" "4 minutes ago" "5 minutes ago" "6 minutes ago"
+ "7 minutes ago" "8 minutes ago" "9 minutes ago" "10 minutes ago" "11 minutes ago"
+ "12 minutes ago" "13 minutes ago")
+ (tl-tests--property-values-at 'display
+ (tl-tests--all-regions-with-property 'timestamp))))
+ (should (null (marker-position (nth 9 markers)))))))))
(ert-deftest mastodon-tl--has-spoiler ()
"Should be able to detect toots with spoiler text as expected"
@@ -833,10 +835,10 @@ constant."
(insert "some text before\n")
(setq toot-start (point))
(with-mock
- (stub create-image => '(image "fake data"))
- (stub shr-render-region => nil) ;; Travis's Emacs doesn't have libxml
- (insert
- (mastodon-tl--spoiler normal-toot-with-spoiler)))
+ (stub create-image => '(image "fake data"))
+ (stub shr-render-region => nil) ;; Travis's Emacs doesn't have libxml
+ (insert
+ (mastodon-tl--spoiler normal-toot-with-spoiler)))
(setq toot-end (point))
(insert "\nsome more text.")
(add-text-properties
@@ -899,10 +901,10 @@ constant."
'help-echo "https://example.space/tags/sampletag")
" some text after"))
(rendered (with-mock
- (stub shr-render-region => nil)
- (mastodon-tl--render-text
- fake-input-text
- mastodon-tl-test-base-toot)))
+ (stub shr-render-region => nil)
+ (mastodon-tl--render-text
+ fake-input-text
+ mastodon-tl-test-base-toot)))
(tag-location 7))
(should (eq (get-text-property tag-location 'mastodon-tab-stop rendered)
'hashtag))
@@ -912,23 +914,27 @@ constant."
"Browse tag #sampletag"))))
(ert-deftest mastodon-tl--extract-hashtag-from-url-mastodon-link ()
+ "Should extract the hashtag from a tags url."
(should (equal (mastodon-tl--extract-hashtag-from-url
"https://example.org/tags/foo"
"https://example.org")
"foo")))
(ert-deftest mastodon-tl--extract-hashtag-from-url-other-link ()
+ "Should extract the hashtag from a tag url."
(should (equal (mastodon-tl--extract-hashtag-from-url
"https://example.org/tag/foo"
"https://example.org")
"foo")))
(ert-deftest mastodon-tl--extract-hashtag-from-url-wrong-instance ()
+ "Should not find a tag when the instance doesn't match."
(should (null (mastodon-tl--extract-hashtag-from-url
"https://example.org/tags/foo"
"https://other.example.org"))))
(ert-deftest mastodon-tl--extract-hashtag-from-url-not-tag ()
+ "Should not find a hashtag when not a tag url"
(should (null (mastodon-tl--extract-hashtag-from-url
"https://example.org/@userid"
"https://example.org"))))
@@ -946,10 +952,10 @@ constant."
'help-echo "https://bar.example/@foo")
" some text after"))
(rendered (with-mock
- (stub shr-render-region => nil)
- (mastodon-tl--render-text
- fake-input-text
- mastodon-tl-test-base-toot)))
+ (stub shr-render-region => nil)
+ (mastodon-tl--render-text
+ fake-input-text
+ mastodon-tl-test-base-toot)))
(mention-location 11))
(should (eq (get-text-property mention-location 'mastodon-tab-stop rendered)
'user-handle))
@@ -957,17 +963,20 @@ constant."
"Browse user profile of @foo@bar.example"))))
(ert-deftest mastodon-tl--extract-userhandle-from-url-correct-case ()
+ "Should extract the user handle from url."
(should (equal (mastodon-tl--extract-userhandle-from-url
"https://example.org/@someuser"
"@SomeUser")
"@SomeUser@example.org")))
(ert-deftest mastodon-tl--extract-userhandle-from-url-missing-at-in-text ()
+ "Should not extract a user handle from url if the text is wrong."
(should (null (mastodon-tl--extract-userhandle-from-url
"https://example.org/@someuser"
"SomeUser"))))
(ert-deftest mastodon-tl--extract-userhandle-from-url-query-in-url ()
+ "Should not extract a user handle from url if there is a query param."
(should (null (mastodon-tl--extract-userhandle-from-url
"https://example.org/@someuser?shouldnot=behere"
"SomeUser"))))