own as-function-name, stigmergy in writing tests
stigmergy: We know how to write tests, we know where to find sample code (s.el) and by applying babysteps we get only what we want. Function does a bit less than s-dashed-words, it doesn'c change CamelCase to dashed-case, but does camelcase. But for what we need it is good enough probably. the regexp in s-dashed-words looked daunting.
This commit is contained in:
@@ -351,7 +351,7 @@ the description. This may destroy existing links, or change their targets so use
|
|||||||
(cdr bounds))
|
(cdr bounds))
|
||||||
(old-name
|
(old-name
|
||||||
(buffer-substring-no-properties begin end)))
|
(buffer-substring-no-properties begin end)))
|
||||||
(message "Will rename to %s" new-name)
|
(message "Will rename to %s" new-name) ;; should use as-function-name here
|
||||||
(movd (intern old-name) (intern new-name))
|
(movd (intern old-name) (intern new-name))
|
||||||
(delete-region begin end)
|
(delete-region begin end)
|
||||||
(insert (s-dashed-words new-name))
|
(insert (s-dashed-words new-name))
|
||||||
@@ -361,10 +361,11 @@ the description. This may destroy existing links, or change their targets so use
|
|||||||
;; tests are better than literate programming when you want to triangulate on the same function
|
;; tests are better than literate programming when you want to triangulate on the same function
|
||||||
;; org only shows the last return value by default, you can return a list of course, but still
|
;; org only shows the last return value by default, you can return a list of course, but still
|
||||||
(defun as-function-name (candidate-name)
|
(defun as-function-name (candidate-name)
|
||||||
"Take the string and make it suitable to be a function name"
|
"Take the string and make it suitable to be a function name. Replaces space with dash and make string all lowercase."
|
||||||
(declare (side-effect-free t))
|
(declare (side-effect-free t))
|
||||||
(candidate-name)
|
(s-join "-" (mapcar 'downcase (split-string candidate-name " " t))))
|
||||||
|
|
||||||
|
;; (s-join "-" (mapcar 'downcase (s-split-words s))))
|
||||||
(ert-deftest refactor-rename-should-leave-forward-slash()
|
(ert-deftest refactor-rename-should-leave-forward-slash()
|
||||||
(should (equal (as-function-name "qwan/echo")
|
(should (equal (as-function-name "qwan/echo")
|
||||||
"qwan/echo")))
|
"qwan/echo")))
|
||||||
@@ -372,4 +373,9 @@ the description. This may destroy existing links, or change their targets so use
|
|||||||
(ert-deftest refactor-rename-should-replace-space-with-dash()
|
(ert-deftest refactor-rename-should-replace-space-with-dash()
|
||||||
(should (equal (as-function-name "qwan/echo chamber")
|
(should (equal (as-function-name "qwan/echo chamber")
|
||||||
"qwan/echo-chamber")))
|
"qwan/echo-chamber")))
|
||||||
|
|
||||||
|
|
||||||
|
(ert-deftest refactor-rename-should-replace-uppercase-with-lowercase()
|
||||||
|
(should (equal (as-function-name "Echo-chamber")
|
||||||
|
"echo-chamber")))
|
||||||
(ert "refactor.*")
|
(ert "refactor.*")
|
||||||
|
|||||||
Reference in New Issue
Block a user