From 3617d7e799999354df1417908cf0724b19cbabc5 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Thu, 12 Jan 2023 22:18:38 +0000 Subject: [PATCH] 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. --- config.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/config.el b/config.el index aa53deb..a33c429 100644 --- a/config.el +++ b/config.el @@ -351,7 +351,7 @@ the description. This may destroy existing links, or change their targets so use (cdr bounds)) (old-name (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)) (delete-region begin end) (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 ;; org only shows the last return value by default, you can return a list of course, but still (defun as-function-name (candidate-name) - "Take the string and make it suitable to be a function name" - (declare (side-effect-free t)) - (candidate-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)) + (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() (should (equal (as-function-name "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() (should (equal (as-function-name "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.*")