Skip to content

Commit 6b725ac

Browse files
committed
fix: rework ensure-case to produce saner output
1 parent 65fc90a commit 6b725ac

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

source/library/ensure-case.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
export default (a, stringCase) => {
2-
const method = `to${stringCase[0].toUpperCase()}${stringCase.slice(1)}`;
3-
return typeof a !== 'string' || a[method]() === a;
1+
export default (raw = '', target = 'lowercase') => {
2+
const normalized = String(raw);
3+
4+
switch (target) {
5+
case 'uppercase':
6+
return normalized.toUpperCase() === normalized;
7+
case 'lowercase':
8+
default:
9+
return normalized.toLowerCase() === normalized;
10+
}
411
};

source/rules/body-case.test.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,49 @@ test('with empty body should succeed for "always uppercase"', t => {
4040
t.is(actual, expected);
4141
});
4242

43-
test.failing('with lowercase body should fail for "never lowercase"', t => {
43+
test('with lowercase body should fail for "never lowercase"', t => {
4444
const [actual] = bodyCase(parsed.lowercase, 'never', 'lowercase');
4545
const expected = false;
4646
t.is(actual, expected);
4747
});
4848

49-
test.failing('with lowercase body should succeed for "always lowercase"', t => {
49+
test('with lowercase body should succeed for "always lowercase"', t => {
5050
const [actual] = bodyCase(parsed.lowercase, 'always', 'lowercase');
5151
const expected = true;
5252
t.is(actual, expected);
5353
});
5454

55-
test.failing('with mixedcase body should fail for "never lowercase"', t => {
55+
test('with mixedcase body should succeed for "never lowercase"', t => {
5656
const [actual] = bodyCase(parsed.mixedcase, 'never', 'lowercase');
57-
const expected = false;
57+
const expected = true;
5858
t.is(actual, expected);
5959
});
6060

61-
test.failing('with mixedcase body should fail for "always lowercase"', t => {
61+
test('with mixedcase body should fail for "always lowercase"', t => {
6262
const [actual] = bodyCase(parsed.mixedcase, 'always', 'lowercase');
6363
const expected = false;
6464
t.is(actual, expected);
6565
});
6666

67-
test.failing('with uppercase body should fail for "never uppercase"', t => {
67+
test('with mixedcase body should succeed for "never uppercase"', t => {
68+
const [actual] = bodyCase(parsed.mixedcase, 'never', 'uppercase');
69+
const expected = true;
70+
t.is(actual, expected);
71+
});
72+
73+
test('with mixedcase body should fail for "always uppercase"', t => {
74+
const [actual] = bodyCase(parsed.mixedcase, 'always', 'uppercase');
75+
const expected = false;
76+
t.is(actual, expected);
77+
});
78+
79+
test('with uppercase body should fail for "never uppercase"', t => {
6880
const [actual] = bodyCase(parsed.uppercase, 'never', 'uppercase');
6981
const expected = false;
7082
t.is(actual, expected);
7183
});
7284

73-
test.failing('with lowercase body should succeed for "always uppercase"', t => {
85+
test('with lowercase body should succeed for "always uppercase"', t => {
7486
const [actual] = bodyCase(parsed.uppercase, 'always', 'uppercase');
7587
const expected = true;
7688
t.is(actual, expected);

0 commit comments

Comments
 (0)