|
1 | 1 | import { describe, it, expect } from "vitest";
|
2 | 2 | import { inspect } from "util";
|
3 |
| -import { titleCase } from "./index.js"; |
| 3 | +import { titleCase, Options } from "./index.js"; |
4 | 4 |
|
5 | 5 | /**
|
6 | 6 | * Based on https://github.com/gouch/to-title-case/blob/master/test/tests.json.
|
7 | 7 | */
|
8 |
| -const TEST_CASES: [string, string][] = [ |
| 8 | +const TEST_CASES: [string, string, Options?][] = [ |
9 | 9 | ["", ""],
|
10 | 10 | ["2019", "2019"],
|
11 | 11 | ["test", "Test"],
|
@@ -71,18 +71,30 @@ const TEST_CASES: [string, string][] = [
|
71 | 71 | ['"a quote." a test.', '"A Quote." A Test.'],
|
72 | 72 | ['"The U.N." a quote.', '"The U.N." A Quote.'],
|
73 | 73 | ['"The U.N.". a quote.', '"The U.N.". A Quote.'],
|
| 74 | + ['"The U.N.". a quote.', '"The U.N.". A quote.', { sentenceCase: true }], |
74 | 75 | ['"go without"', '"Go Without"'],
|
75 | 76 | ["the iPhone: a quote", "The iPhone: A Quote"],
|
| 77 | + ["the iPhone: a quote", "The iPhone: a quote", { sentenceCase: true }], |
76 | 78 | ["the U.N. and me", "The U.N. and Me"],
|
| 79 | + ["the U.N. and me", "The U.N. and me", { sentenceCase: true }], |
| 80 | + ["the U.N. and me", "The U.N. And Me", { smallWords: new Set() }], |
77 | 81 | ["start-and-end", "Start-and-End"],
|
78 | 82 | ["go-to-iPhone", "Go-to-iPhone"],
|
79 | 83 | ["Keep #tag", "Keep #tag"],
|
| 84 | + ['"Hello world", says John.', '"Hello World", Says John.'], |
| 85 | + [ |
| 86 | + '"Hello world", says John.', |
| 87 | + '"Hello world", says John.', |
| 88 | + { sentenceCase: true }, |
| 89 | + ], |
80 | 90 | ];
|
81 | 91 |
|
82 | 92 | describe("swap case", () => {
|
83 |
| - for (const [input, result] of TEST_CASES) { |
84 |
| - it(`${inspect(input)} -> ${inspect(result)}`, () => { |
85 |
| - expect(titleCase(input)).toEqual(result); |
| 93 | + for (const [input, result, options] of TEST_CASES) { |
| 94 | + it(`${inspect(input)} (${ |
| 95 | + options ? JSON.stringify(options) : "null" |
| 96 | + }) -> ${inspect(result)}`, () => { |
| 97 | + expect(titleCase(input, options)).toEqual(result); |
86 | 98 | });
|
87 | 99 | }
|
88 | 100 | });
|
0 commit comments