Skip to content

Commit 1182443

Browse files
committed
test: simplify tests
Reduce the boilerplate by using a helper method. This makes the tests easier to understand at a glance (I think). Signed-off-by: Kevin Locke <[email protected]>
1 parent dfa1cf6 commit 1182443

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

test/index.js

+22-30
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,31 @@
44
*/
55

66
import assert from 'node:assert/strict';
7+
import { format } from 'node:util';
78

89
import dotnetIdentifierCase from '../index.js';
910

10-
describe('dotnetIdentifierCase', () => {
11-
it('returns empty string unchanged', () => {
12-
assert.equal(dotnetIdentifierCase(''), '');
13-
});
14-
15-
it('converts undefined to "Undefined"', () => {
16-
assert.equal(dotnetIdentifierCase(), 'Undefined');
17-
});
18-
19-
it('converts 1 to "1"', () => {
20-
assert.equal(dotnetIdentifierCase(1), '1');
21-
});
22-
23-
it('converts "foo" to "foo"', () => {
24-
assert.equal(dotnetIdentifierCase('foo'), 'Foo');
11+
function itTransforms(from, to) {
12+
it(format('transforms %j to %j', from, to), () => {
13+
assert.equal(dotnetIdentifierCase(from), to);
2514
});
15+
}
2616

27-
it('converts "Foo" to "foo"', () => {
28-
assert.equal(dotnetIdentifierCase('Foo'), 'Foo');
29-
});
30-
31-
it('converts "fOo" to "foo"', () => {
32-
assert.equal(dotnetIdentifierCase('fOo'), 'FOo');
33-
});
34-
35-
it('converts "FOO" to "foo"', () => {
36-
assert.equal(dotnetIdentifierCase('FOO'), 'Foo');
37-
});
38-
39-
it('converts "foo bar" to "FooBar"', () => {
40-
assert.equal(dotnetIdentifierCase('foo bar'), 'FooBar');
41-
});
17+
describe('dotnetIdentifierCase', () => {
18+
itTransforms('', '');
19+
itTransforms(undefined, 'Undefined');
20+
itTransforms(1, '1');
21+
itTransforms('foo', 'Foo');
22+
itTransforms('Foo', 'Foo');
23+
itTransforms('fOo', 'FOo');
24+
itTransforms('FOO', 'Foo');
25+
itTransforms(' foo ', 'Foo');
26+
itTransforms('_foo_', 'Foo');
27+
itTransforms('foo bar', 'FooBar');
28+
itTransforms('foo_bar', 'FooBar');
29+
itTransforms('foo.bar', 'FooBar');
30+
itTransforms('foo-bar', 'FooBar');
31+
itTransforms('fooBar', 'FooBar');
32+
itTransforms("foo's", 'Foos');
33+
itTransforms('fooV2', 'FooV2');
4234
});

0 commit comments

Comments
 (0)