diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-11 14:58:30 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-11 14:58:30 -0500 |
| commit | e52668985817b92f296606707694729b866e8364 (patch) | |
| tree | 6b4214ff67acee159ac4e78a3a8ebd2f32dcf55a /tests | |
| parent | 734172047b05a7dd4d75c86f8aae66c5ae807de0 (diff) | |
| download | dotemacs-e52668985817b92f296606707694729b866e8364.tar.gz dotemacs-e52668985817b92f296606707694729b866e8364.zip | |
fix(custom-case): align title-case with its docstring and standard rules
cj/title-case-region contradicted its own docstring in three ways. It lowercased "is" despite the docstring calling linking verbs major words; it never restarted capitalization after a sentence-ending period; and it had no rule to capitalize the last word. I made the code match the standard: dropped "is" from the minor-word skip list, added the period to the reset characters (a period plus a blank restarts, so "3.14" and "foo.bar" are still left alone), and always capitalize the last word by locating its start once. Updated the four characterization tests that asserted the old behavior and added tests for the last-word and period-restart rules.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-custom-case-title-case-region.el | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/tests/test-custom-case-title-case-region.el b/tests/test-custom-case-title-case-region.el index 383ae927..82b4966a 100644 --- a/tests/test-custom-case-title-case-region.el +++ b/tests/test-custom-case-title-case-region.el @@ -60,16 +60,17 @@ an active region, and return the result." "The Art of War"))) (ert-deftest test-custom-case-title-case-region-normal-all-minor-words () - "All minor words in the skip list should be lowercased in mid-sentence." + "All minor words in the skip list should be lowercased in mid-sentence. +\"is\" is a linking verb, so it is a major word and is capitalized." (should (equal (test-title-case--on-string "go a an and as at but by for if in is nor of on or so the to yet go") - "Go a an and as at but by for if in is nor of on or so the to yet Go"))) + "Go a an and as at but by for if in Is nor of on or so the to yet Go"))) (ert-deftest test-custom-case-title-case-region-normal-four-letter-words-capitalized () "Words of four or more letters should always be capitalized. -Note: 'is' is explicitly in the minor word list, so it stays lowercase." +\"is\" is a linking verb (a major word), so it is capitalized too." (should (equal (test-title-case--on-string "this is from that with over") - "This is From That With Over"))) + "This Is From That With Over"))) (ert-deftest test-custom-case-title-case-region-normal-allcaps-input () "All-caps input should be downcased first, then title-cased." @@ -94,7 +95,16 @@ Note: 'is' is explicitly in the minor word list, so it stays lowercase." (ert-deftest test-custom-case-title-case-region-normal-question-resets () "Word immediately after a question mark should be capitalized, even if minor." (should (equal (test-title-case--on-string "really? the answer is no") - "Really? The Answer is No"))) + "Really? The Answer Is No"))) + +(ert-deftest test-custom-case-title-case-region-normal-last-word-capitalized () + "The last word is always capitalized, even a minor one." + (should (equal (test-title-case--on-string "the art of") "The Art Of"))) + +(ert-deftest test-custom-case-title-case-region-normal-period-restarts () + "A word after a sentence-ending period should be capitalized." + (should (equal (test-title-case--on-string "one. the next sentence") + "One. The Next Sentence"))) (ert-deftest test-custom-case-title-case-region-normal-hyphenated-word () "Second part of a hyphenated word should NOT be capitalized." @@ -141,7 +151,7 @@ Note: 'is' is explicitly in the minor word list, so it stays lowercase." (ert-deftest test-custom-case-title-case-region-boundary-unicode-words () "Unicode characters should pass through without error." (should (equal (test-title-case--on-string "the café is nice") - "The Café is Nice"))) + "The Café Is Nice"))) (ert-deftest test-custom-case-title-case-region-boundary-numbers-in-text () "Numbers mixed with text should not break title casing." |
