Skip to content

Commit 6b99ac3

Browse files
Refactoring
* drop unnecessary string-match * add test cases to make string-match test sensitive * slightly rearrange some tests assertions to make them more intuitive * (should (equal nil ...)) → (should-not ...) * (should-not (equal nil ...)) → (should ...)
1 parent b13cbfa commit 6b99ac3

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

string-inflection.el

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ selected. If include `:', select `FOO::VERSION' to run
390390
"if FooBar => t"
391391
(let ((case-fold-search nil))
392392
(and
393-
(string-match "[[:lower:]]" str) ;; no test actually requires this
393+
(string-match "[[:lower:]]" str)
394394
(string-match "\\`[[:upper:]][[:lower:][:upper:][:digit:]]+\\'" str))))
395395

396396
(fset 'string-inflection-upper-camelcase-p 'string-inflection-pascal-case-p)
@@ -412,7 +412,6 @@ selected. If include `:', select `FOO::VERSION' to run
412412
"if Foo_Bar => t"
413413
(let ((case-fold-search nil))
414414
(and
415-
(string-match "[[:upper:]]" str) ;; no test actually requires this
416415
(string-match "_" str)
417416
(string-match "\\`[[:upper:]][[:lower:][:upper:][:digit:]_]+\\'" str))))
418417

test/string-inflection-test.el

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -110,42 +110,44 @@
110110
;; --------------------------------------------------------------------------------
111111

112112
(ert-deftest test-word-p ()
113-
(should-not (equal nil (string-inflection-word-p "foo")))
114-
(should-not (equal nil (string-inflection-word-p "eĥo")))
115-
(should (equal nil (string-inflection-word-p "foo_bar")))
116-
(should (equal nil (string-inflection-word-p "eĥo_ŝanĝo"))))
113+
(should (string-inflection-word-p "foo"))
114+
(should (string-inflection-word-p "eĥo"))
115+
(should-not (string-inflection-word-p "foo_bar"))
116+
(should-not (string-inflection-word-p "eĥo_ŝanĝo")))
117117

118118
(ert-deftest test-underscore-p ()
119-
(should-not (equal nil (string-inflection-underscore-p "foo")))
120-
(should-not (equal nil (string-inflection-underscore-p "eĥo")))
121-
(should-not (equal nil (string-inflection-underscore-p "foo_bar")))
122-
(should-not (equal nil (string-inflection-underscore-p "eĥo_ŝanĝo"))))
119+
(should (string-inflection-underscore-p "foo"))
120+
(should (string-inflection-underscore-p "eĥo"))
121+
(should (string-inflection-underscore-p "foo_bar"))
122+
(should (string-inflection-underscore-p "eĥo_ŝanĝo")))
123123

124124
(ert-deftest test-pascal-case-p ()
125-
(should-not (equal nil (string-inflection-pascal-case-p "Foo")))
126-
(should-not (equal nil (string-inflection-pascal-case-p "Eĥo")))
127-
(should-not (equal nil (string-inflection-pascal-case-p "FooBar")))
128-
(should-not (equal nil (string-inflection-pascal-case-p "EĥoŜanĝo"))))
125+
(should (string-inflection-pascal-case-p "Foo"))
126+
(should (string-inflection-pascal-case-p "Eĥo"))
127+
(should (string-inflection-pascal-case-p "FooBar"))
128+
(should (string-inflection-pascal-case-p "EĥoŜanĝo"))
129+
(should-not (string-inflection-pascal-case-p "FOO"))
130+
(should (string-inflection-pascal-case-p "Eĥĥ")))
129131

130132
(ert-deftest test-camelcase-p ()
131-
(should (equal nil (string-inflection-camelcase-p "foo")))
132-
(should (equal nil (string-inflection-camelcase-p "eĥo")))
133-
(should-not (equal nil (string-inflection-camelcase-p "fooBar")))
134-
(should-not (equal nil (string-inflection-camelcase-p "eĥoŜanĝo"))))
133+
(should-not (string-inflection-camelcase-p "foo"))
134+
(should-not (string-inflection-camelcase-p "eĥo"))
135+
(should (string-inflection-camelcase-p "fooBar"))
136+
(should (string-inflection-camelcase-p "eĥoŜanĝo")))
135137

136138
(ert-deftest test-lower-upcase-p ()
137-
(should-not (equal nil (string-inflection-upcase-p "FOO")))
138-
(should-not (equal nil (string-inflection-upcase-p "EĤO")))
139-
(should-not (equal nil (string-inflection-upcase-p "FOO_BAR")))
140-
(should-not (equal nil (string-inflection-upcase-p "EĤO_ŜANĜO"))))
139+
(should (string-inflection-upcase-p "FOO"))
140+
(should (string-inflection-upcase-p "EĤO"))
141+
(should (string-inflection-upcase-p "FOO_BAR"))
142+
(should (string-inflection-upcase-p "EĤO_ŜANĜO")))
141143

142144
(ert-deftest test-kebab-case-p ()
143-
(should-not (equal nil (string-inflection-kebab-case-p "foo-bar")))
144-
(should-not (equal nil (string-inflection-kebab-case-p "eĥo-ŝanĝo"))))
145+
(should (string-inflection-kebab-case-p "foo-bar"))
146+
(should (string-inflection-kebab-case-p "eĥo-ŝanĝo")))
145147

146148
(ert-deftest test-capital-underscore-p ()
147-
(should-not (equal nil (string-inflection-capital-underscore-p "Foo_Bar")))
148-
(should-not (equal nil (string-inflection-capital-underscore-p "Eĥo_Ŝanĝo"))))
149+
(should (string-inflection-capital-underscore-p "Foo_Bar"))
150+
(should (string-inflection-capital-underscore-p "Eĥo_Ŝanĝo")))
149151

150152
;; -------------------------------------------------------------------------------- Target word of cursor position
151153

0 commit comments

Comments
 (0)