aboutsummaryrefslogtreecommitdiff
path: root/test-org-link-edit.el
diff options
context:
space:
mode:
Diffstat (limited to 'test-org-link-edit.el')
-rw-r--r--test-org-link-edit.el352
1 files changed, 248 insertions, 104 deletions
diff --git a/test-org-link-edit.el b/test-org-link-edit.el
index c6b3535..c238ec8 100644
--- a/test-org-link-edit.el
+++ b/test-org-link-edit.el
@@ -46,47 +46,63 @@ otherwise place the point at the beginning of the inserted text."
;;; Slurping
-(ert-deftest test-org-link-edit/forward-slurp-word ()
- "Test `org-link-edit-forward-slurp-word'."
- ;; Slurp one word into plain link.
+(ert-deftest test-org-link-edit/forward-slurp ()
+ "Test `org-link-edit-forward-slurp'."
+ ;; Slurp one blob into plain link.
(should
(string=
"\[\[http://orgmode.org/\]\[Org's\]\] website is"
(org-test-with-temp-text
"http://orgmode.org/ Org's website is"
- (org-link-edit-forward-slurp-word)
+ (org-link-edit-forward-slurp)
(buffer-string))))
- ;; Slurp one word into empty bracket link.
+ ;; Slurp one blob into empty bracket link.
(should
(string=
"\[\[http://orgmode.org/\]\[Org's\]\] website is"
(org-test-with-temp-text
"\[\[http://orgmode.org/\]\] Org's website is"
- (org-link-edit-forward-slurp-word)
+ (org-link-edit-forward-slurp)
(buffer-string))))
- ;; Slurp one word into bracket link.
+ ;; Slurp one blob into bracket link.
(should
(string=
"\[\[http://orgmode.org/\]\[Org's website\]\] is"
(org-test-with-temp-text
"\[\[http://orgmode.org/\]\[Org's\]\] website is"
- (org-link-edit-forward-slurp-word)
+ (org-link-edit-forward-slurp)
(buffer-string))))
- ;; Slurp two words into plain link.
+ ;; Slurp one blob, but not trailing punctuation, into bracket link.
+ (should
+ (string=
+ "\[\[http://orgmode.org/\]\[Org's website\]\]."
+ (org-test-with-temp-text
+ "\[\[http://orgmode.org/\]\[Org's\]\] website."
+ (org-link-edit-forward-slurp)
+ (buffer-string))))
+ ;; Slurp all-punctuation blob into bracket link.
+ (should
+ (string=
+ "\[\[http://orgmode.org/\]\[Org's .?.?\]\]"
+ (org-test-with-temp-text
+ "\[\[http://orgmode.org/\]\[Org's\]\] .?.?"
+ (org-link-edit-forward-slurp)
+ (buffer-string))))
+ ;; Slurp two blobs into plain link.
(should
(string=
"\[\[http://orgmode.org/\]\[Org's website\]\] is"
(org-test-with-temp-text
"http://orgmode.org/ Org's website is"
- (org-link-edit-forward-slurp-word 2)
+ (org-link-edit-forward-slurp 2)
(buffer-string))))
- ;; Slurp two words into bracket link.
+ ;; Slurp two blobs into bracket link.
(should
(string=
"\[\[http://orgmode.org/\]\[Org's website is\]\]"
(org-test-with-temp-text
"\[\[http://orgmode.org/\]\[Org's\]\] website is"
- (org-link-edit-forward-slurp-word 2)
+ (org-link-edit-forward-slurp 2)
(buffer-string))))
;; Slurp new line as space.
(should
@@ -95,73 +111,89 @@ otherwise place the point at the beginning of the inserted text."
(org-test-with-temp-text
"\[\[http://orgmode.org/\]\[Org's\]\]
website is"
- (org-link-edit-forward-slurp-word 1)
+ (org-link-edit-forward-slurp 1)
(buffer-string))))
- ;; Slurp word that has no whitespace.
+ ;; Slurp blob that has no whitespace.
(should
(string=
"\[\[http://orgmode.org/\]\[website\]\]"
(org-test-with-temp-text
"\[\[http://orgmode.org/\]\]website"
- (org-link-edit-forward-slurp-word 1)
+ (org-link-edit-forward-slurp 1)
(buffer-string))))
- ;; Slurp word beginning with non-word, non-whitespace character.
+ ;; Slurp blob that isn't separated from link by whitespace.
(should
(string=
"\[\[http://orgmode.org/\]\[-website\]\]"
(org-test-with-temp-text
"\[\[http://orgmode.org/\]\]-website"
- (org-link-edit-forward-slurp-word 1)
+ (org-link-edit-forward-slurp 1)
(buffer-string))))
- ;; Slurp beyond the number of present words.
+ ;; Slurp beyond the number of present blobs.
(should-error
(org-test-with-temp-text
"\[\[http://orgmode.org/\]\[Org's\]\] website is"
- (org-link-edit-forward-slurp-word 3)
+ (org-link-edit-forward-slurp 3)
(buffer-string))
:type (list 'user-error)))
-(ert-deftest test-org-link-edit/backward-slurp-word ()
- "Test `org-link-edit-backward-slurp-word'."
- ;; Slurp one word into plain link.
+(ert-deftest test-org-link-edit/backward-slurp ()
+ "Test `org-link-edit-backward-slurp'."
+ ;; Slurp one blob into plain link.
(should
(string=
"Here \[\[http://orgmode.org/\]\[is\]\] Org's website"
(org-test-with-temp-text
"Here is <point>http://orgmode.org/ Org's website"
- (org-link-edit-backward-slurp-word)
+ (org-link-edit-backward-slurp)
(buffer-string))))
- ;; Slurp one word into empty bracket link.
+ ;; Slurp one blob into empty bracket link.
(should
(string=
"Here \[\[http://orgmode.org/\]\[is\]\] Org's website"
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\] Org's website"
- (org-link-edit-backward-slurp-word)
+ (org-link-edit-backward-slurp)
(buffer-string))))
- ;; Slurp one word into bracket link.
+ ;; Slurp one blob into bracket link.
(should
(string=
"Here \[\[http://orgmode.org/\]\[is Org's\]\] website"
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-backward-slurp-word)
+ (org-link-edit-backward-slurp)
+ (buffer-string))))
+ ;; Slurp one blob with trailing punctuation into bracket link.
+ (should
+ (string=
+ "Here \[\[http://orgmode.org/\]\[is: Org's\]\] website."
+ (org-test-with-temp-text
+ "Here is: <point>\[\[http://orgmode.org/\]\[Org's\]\] website."
+ (org-link-edit-backward-slurp)
+ (buffer-string))))
+ ;; Slurp all-punctuation blob into bracket link.
+ (should
+ (string=
+ "Here \[\[http://orgmode.org/\]\[... Org's\]\] website."
+ (org-test-with-temp-text
+ "Here ... <point>\[\[http://orgmode.org/\]\[Org's\]\] website."
+ (org-link-edit-backward-slurp)
(buffer-string))))
- ;; Slurp two words into plain link.
+ ;; Slurp two blobs into plain link.
(should
(string=
"\[\[http://orgmode.org/\]\[Here is\]\] Org's website"
(org-test-with-temp-text
"Here is <point>http://orgmode.org/ Org's website"
- (org-link-edit-backward-slurp-word 2)
+ (org-link-edit-backward-slurp 2)
(buffer-string))))
- ;; Slurp two words into bracket link.
+ ;; Slurp two blobs into bracket link.
(should
(string=
"\[\[http://orgmode.org/\]\[Here is Org's\]\] website"
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-backward-slurp-word 2)
+ (org-link-edit-backward-slurp 2)
(buffer-string))))
;; Slurp new line as space.
(should
@@ -170,149 +202,189 @@ website is"
(org-test-with-temp-text
"Here is
<point>\[\[http://orgmode.org/\]\[Org's website\]\]"
- (org-link-edit-backward-slurp-word 1)
+ (org-link-edit-backward-slurp 1)
(buffer-string))))
- ;; Slurp word that has no whitespace.
+ ;; Slurp blob that has no whitespace.
(should
(string=
"Here \[\[http://orgmode.org/\]\[is\]\] Org's website"
(org-test-with-temp-text
"Here is<point>\[\[http://orgmode.org/\]\] Org's website"
- (org-link-edit-backward-slurp-word 1)
+ (org-link-edit-backward-slurp 1)
(buffer-string))))
- ;; Slurp word ending with non-word, non-whitespace character.
+ ;; Slurp blob that isn't separated from link by whitespace.
(should
(string=
"Here \[\[http://orgmode.org/\]\[is-\]\] Org's website"
(org-test-with-temp-text
"Here is-<point>\[\[http://orgmode.org/\]\] Org's website"
- (org-link-edit-backward-slurp-word 1)
+ (org-link-edit-backward-slurp 1)
(buffer-string))))
- ;; Slurp beyond the number of present words.
+ ;; Slurp beyond the number of present blobs.
(should-error
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-backward-slurp-word 3)
+ (org-link-edit-backward-slurp 3)
(buffer-string))
:type (list 'user-error)))
(ert-deftest test-org-link-edit/slurp-negative-argument ()
- "Test `org-link-edit-forward-slurp-word' and
-`org-link-edit-backward-slurp-word' with negative arguments."
+ "Test `org-link-edit-forward-slurp' and
+`org-link-edit-backward-slurp' with negative arguments."
(should
(string=
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-forward-slurp-word 1)
+ (org-link-edit-forward-slurp 1)
(buffer-string))
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-backward-slurp-word -1)
+ (org-link-edit-backward-slurp -1)
(buffer-string))))
(should
(string=
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-forward-slurp-word -1)
+ (org-link-edit-forward-slurp -1)
(buffer-string))
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-backward-slurp-word)
+ (org-link-edit-backward-slurp)
(buffer-string)))))
;;; Barfing
-(ert-deftest test-org-link-edit/forward-barf-word ()
- "Test `org-link-edit-forward-barf-word'."
- ;; Barf last word.
+(ert-deftest test-org-link-edit/forward-barf ()
+ "Test `org-link-edit-forward-barf'."
+ ;; Barf last blob.
(should
(string=
"Org's \[\[http://orgmode.org/\]\] website is"
(org-test-with-temp-text
"Org's <point>\[\[http://orgmode.org/\]\[website\]\] is"
- (org-link-edit-forward-barf-word)
+ (org-link-edit-forward-barf)
+ (buffer-string))))
+ ;; Barf last blob with puctuation.
+ (should
+ (string=
+ "Org's \[\[http://orgmode.org/\]\] website,"
+ (org-test-with-temp-text
+ "Org's <point>\[\[http://orgmode.org/\]\[website,\]\]"
+ (org-link-edit-forward-barf)
+ (buffer-string))))
+ ;; Barf last blob, all punctuation.
+ (should
+ (string=
+ "Org's \[\[http://orgmode.org/\]\] ..."
+ (org-test-with-temp-text
+ "Org's <point>\[\[http://orgmode.org/\]\[...\]\]"
+ (org-link-edit-forward-barf)
(buffer-string))))
- ;; Barf two last words.
+ ;; Barf two last blobs.
(should
(string=
"Org's \[\[http://orgmode.org/\]\] website is"
(org-test-with-temp-text
"Org's <point>\[\[http://orgmode.org/\]\[website is\]\]"
- (org-link-edit-forward-barf-word 2)
+ (org-link-edit-forward-barf 2)
(buffer-string))))
- ;; Barf one word, not last.
+ ;; Barf one blob, not last.
(should
(string=
"Org's \[\[http://orgmode.org/\]\[website\]\] is"
(org-test-with-temp-text
"Org's <point>\[\[http://orgmode.org/\]\[website is\]\]"
- (org-link-edit-forward-barf-word 1)
+ (org-link-edit-forward-barf 1)
(buffer-string))))
- ;; Barf beyond the number of present words.
+ ;; Barf beyond the number of present blobs.
(should-error
(org-test-with-temp-text
"Org's <point>\[\[http://orgmode.org/\]\[website is\]\]"
- (org-link-edit-forward-barf-word 3)
+ (org-link-edit-forward-barf 3)
(buffer-string))
:type (list 'user-error)))
-(ert-deftest test-org-link-edit/backward-barf-word ()
- "Test `org-link-edit-backward-barf-word'."
- ;; Barf last word.
+(ert-deftest test-org-link-edit/backward-barf ()
+ "Test `org-link-edit-backward-barf'."
+ ;; Barf last blob.
(should
(string=
"Org's website \[\[http://orgmode.org/\]\] is"
(org-test-with-temp-text
"Org's <point>\[\[http://orgmode.org/\]\[website\]\] is"
- (org-link-edit-backward-barf-word)
+ (org-link-edit-backward-barf)
+ (buffer-string))))
+ ;; Barf last blob with puctuation.
+ (should
+ (string=
+ "Org's website: \[\[http://orgmode.org/\]\]"
+ (org-test-with-temp-text
+ "Org's <point>\[\[http://orgmode.org/\]\[website:\]\]"
+ (org-link-edit-backward-barf)
(buffer-string))))
- ;; Barf two last words.
+ ;; Barf last all-puctuation blob.
+ (should
+ (string=
+ "Org's ... \[\[http://orgmode.org/\]\]"
+ (org-test-with-temp-text
+ "Org's <point>\[\[http://orgmode.org/\]\[...\]\]"
+ (org-link-edit-backward-barf)
+ (buffer-string))))
+ ;; Barf two last blobs.
(should
(string=
"Org's website is \[\[http://orgmode.org/\]\]"
(org-test-with-temp-text
"Org's <point>\[\[http://orgmode.org/\]\[website is\]\]"
- (org-link-edit-backward-barf-word 2)
+ (org-link-edit-backward-barf 2)
(buffer-string))))
- ;; Barf one word, not last.
+ ;; Barf one blob, not last.
(should
(string=
"Org's website \[\[http://orgmode.org/\]\[is\]\]"
(org-test-with-temp-text
"Org's <point>\[\[http://orgmode.org/\]\[website is\]\]"
- (org-link-edit-backward-barf-word 1)
+ (org-link-edit-backward-barf 1)
+ (buffer-string))))
+ ;; Barf one blob with punctuation, not last.
+ (should
+ (string=
+ "Org's website. \[\[http://orgmode.org/\]\[is\]\]"
+ (org-test-with-temp-text
+ "Org's <point>\[\[http://orgmode.org/\]\[website. is\]\]"
+ (org-link-edit-backward-barf 1)
(buffer-string))))
- ;; Barf beyond the number of present words.
+ ;; Barf beyond the number of present blobs.
(should-error
(org-test-with-temp-text
"Org's <point>\[\[http://orgmode.org/\]\[website is\]\]"
- (org-link-edit-backward-barf-word 3)
+ (org-link-edit-backward-barf 3)
(buffer-string))
:type (list 'user-error)))
(ert-deftest test-org-link-edit/barf-negative-argument ()
- "Test `org-link-edit-forward-barf-word' and
-`org-link-edit-backward-barf-word' with negative arguments."
+ "Test `org-link-edit-forward-barf' and
+`org-link-edit-backward-barf' with negative arguments."
(should
(string=
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-forward-barf-word 1)
+ (org-link-edit-forward-barf 1)
(buffer-string))
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-backward-barf-word -1)
+ (org-link-edit-backward-barf -1)
(buffer-string))))
(should
(string=
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-forward-barf-word -1)
+ (org-link-edit-forward-barf -1)
(buffer-string))
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-backward-barf-word)
+ (org-link-edit-backward-barf)
(buffer-string)))))
@@ -327,35 +399,35 @@ website is"
;; space.
(ert-deftest test-org-link-edit/slurp-barf-round-trip ()
- "Test `org-link-edit-forward-barf-word' and
-`org-link-edit-backward-barf-word' reversibility."
+ "Test `org-link-edit-forward-barf' and
+`org-link-edit-backward-barf' reversibility."
(should
(string= "Here is \[\[http://orgmode.org/\]\[Org's\]\] website"
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-forward-barf-word 1)
- (org-link-edit-forward-slurp-word 1)
+ (org-link-edit-forward-barf 1)
+ (org-link-edit-forward-slurp 1)
(buffer-string))))
(should
(string= "Here is \[\[http://orgmode.org/\]\] Org's website"
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\] Org's website"
- (org-link-edit-forward-slurp-word 1)
- (org-link-edit-forward-barf-word 1)
+ (org-link-edit-forward-slurp 1)
+ (org-link-edit-forward-barf 1)
(buffer-string))))
(should
(string= "Here is \[\[http://orgmode.org/\]\[Org's\]\] website"
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-backward-barf-word 1)
- (org-link-edit-backward-slurp-word 1)
+ (org-link-edit-backward-barf 1)
+ (org-link-edit-backward-slurp 1)
(buffer-string))))
(should
(string= "Here is \[\[http://orgmode.org/\]\[Org's\]\] website"
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\] website"
- (org-link-edit-backward-slurp-word 1)
- (org-link-edit-backward-barf-word 1)
+ (org-link-edit-backward-slurp 1)
+ (org-link-edit-backward-barf 1)
(buffer-string))))
;; Failed round trip because of newline.
(should
@@ -363,8 +435,8 @@ website is"
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\[Org's\]\]
website"
- (org-link-edit-forward-slurp-word 1)
- (org-link-edit-forward-barf-word 1)
+ (org-link-edit-forward-slurp 1)
+ (org-link-edit-forward-barf 1)
(buffer-string))))
;; Failed round trip because of empty description and more than one
;; whitespace.
@@ -372,8 +444,8 @@ website"
(string= "Here is \[\[http://orgmode.org/\]\] website"
(org-test-with-temp-text
"Here is <point>\[\[http://orgmode.org/\]\] website"
- (org-link-edit-forward-slurp-word 1)
- (org-link-edit-forward-barf-word 1)
+ (org-link-edit-forward-slurp 1)
+ (org-link-edit-forward-barf 1)
(buffer-string)))))
@@ -394,35 +466,107 @@ website"
(should (string= link "http://orgmode.org/"))
(should (string= desc "org"))))
-(ert-deftest test-org-link-edit/split-first-words ()
- "Test `org-link-edit--split-first-words'."
- ;; Single word, n = 1
+(ert-deftest test-org-link-edit/forward-blob ()
+ "Test `org-link-edit--forward-blob'."
+ ;; Move forward one blob.
+ (should
+ (string=
+ "one"
+ (org-test-with-temp-text "one two"
+ (org-link-edit--forward-blob 1)
+ (buffer-substring (point-min) (point)))))
+ ;; Move forward one blob with point mid.
+ (should
+ (string=
+ "one"
+ (org-test-with-temp-text "o<point>ne two"
+ (org-link-edit--forward-blob 1)
+ (buffer-substring (point-min) (point)))))
+ ;; Move forward two blobs.
+ (should
+ (string=
+ "one two"
+ (org-test-with-temp-text "one two"
+ (org-link-edit--forward-blob 2)
+ (buffer-substring (point-min) (point)))))
+ ;; Move forward blob, including punctuation.
+ (should
+ (string=
+ "one."
+ (org-test-with-temp-text "one."
+ (org-link-edit--forward-blob 1)
+ (buffer-substring (point-min) (point)))))
+ ;; Move forward blob, adjusting for punctuation.
+ (should
+ (string=
+ "one"
+ (org-test-with-temp-text "one."
+ (org-link-edit--forward-blob 1 t)
+ (buffer-substring (point-min) (point)))))
+ ;; Move forward blob consisting of only punctuation characters.
+ (should
+ (string=
+ "...."
+ (org-test-with-temp-text "...."
+ (org-link-edit--forward-blob 1 t)
+ (buffer-substring (point-min) (point)))))
+ ;; Move backward one blob.
+ (should
+ (string=
+ "two"
+ (org-test-with-temp-text "one two<point>"
+ (org-link-edit--forward-blob -1)
+ (buffer-substring (point) (point-max)))))
+ ;; Move backward two blobs.
+ (should
+ (string=
+ "one two"
+ (org-test-with-temp-text "one two<point>"
+ (org-link-edit--forward-blob -2)
+ (buffer-substring (point) (point-max)))))
+ ;; Move backward one blobs, including punctuation.
+ (should
+ (string=
+ ".two."
+ (org-test-with-temp-text "one .two.<point>"
+ (org-link-edit--forward-blob -1)
+ (buffer-substring (point) (point-max)))))
+ ;; Move beyond last blob.
+ (org-test-with-temp-text "one two"
+ (should (org-link-edit--forward-blob 1))
+ (should-not (org-link-edit--forward-blob 2))
+ (should (string= "one two"
+ (buffer-substring (point-min) (point))))))
+
+(ert-deftest test-org-link-edit/split-firsts ()
+ "Test `org-link-edit--split-first-blobs'."
+ ;; Single blob, n = 1
(should (equal '("one" . "")
- (org-link-edit--split-first-words "one" 1)))
- ;; Single word, out-of-bounds
+ (org-link-edit--split-first-blobs "one" 1)))
+ ;; Single blob, out-of-bounds
(should (equal '("one" . nil)
- (org-link-edit--split-first-words "one" 2)))
- ;; Multiple words, n = 1
+ (org-link-edit--split-first-blobs "one" 2)))
+ ;; Multiple blobs, n = 1
(should (equal '("one " . "two three")
- (org-link-edit--split-first-words "one two three" 1)))
- ;; Multiple words, n > 1
+ (org-link-edit--split-first-blobs "one two three" 1)))
+ ;; Multiple blobs, n > 1
(should (equal '("one two " . "three")
- (org-link-edit--split-first-words "one two three" 2))))
+ (org-link-edit--split-first-blobs "one two three" 2))))
-(ert-deftest test-org-link-edit/split-last-words ()
- "Test `org-link-edit--split-last-words'."
- ;; Single word, n = 1
+(ert-deftest test-org-link-edit/split-lasts ()
+ "Test `org-link-edit--split-last-blobs'."
+ ;; Single blob, n = 1
(should (equal '("" . "one")
- (org-link-edit--split-last-words "one" 1)))
- ;; Single word, out-of-bounds
+ (org-link-edit--split-last-blobs "one" 1)))
+ ;; Single blob, out-of-bounds
(should (equal '(nil . "one")
- (org-link-edit--split-last-words "one" 2)))
- ;; Multiple words, n = 1
+ (org-link-edit--split-last-blobs "one" 2)))
+ ;; Multiple blobs, n = 1
(should (equal '("one two" . " three")
- (org-link-edit--split-last-words "one two three" 1)))
- ;; Multiple words, n > 1
+ (org-link-edit--split-last-blobs "one two three" 1)))
+ ;; Multiple blobs, n > 1
(should (equal '("one" . " two three")
- (org-link-edit--split-last-words "one two three" 2))))
+ (org-link-edit--split-last-blobs "one two three" 2))))
(provide 'test-org-link-edit)
;;; test-org-link-edit.el ends here