forked from lukeed/clsx
/
index.js
81 lines (71 loc) · 2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import test from 'tape';
import fn from '../src';
test('clsx', t => {
t.is(typeof fn, 'function', 'exports a function');
t.is(typeof fn(), 'string', '~> returns string output');
t.end();
});
test('strings', t => {
t.is(fn(''), '');
t.is(fn('foo'), 'foo');
t.is(fn(true && 'foo'), 'foo');
t.is(fn(false && 'foo'), '');
t.end();
});
test('strings (variadic)', t => {
t.is(fn(''), '');
t.is(fn('foo', 'bar'), 'foo bar');
t.is(fn(true && 'foo', false && 'bar', 'baz'), 'foo baz');
t.is(fn(false && 'foo', 'bar', 'baz', ''), 'bar baz');
t.end();
});
test('objects', t => {
t.is(fn({}), '');
t.is(fn({ foo:true }), 'foo');
t.is(fn({ foo:true, bar:false }), 'foo');
t.is(fn({ foo:'hiya', bar:1 }), 'foo bar');
t.is(fn({ foo:1, bar:0, baz:1 }), 'foo baz');
t.is(fn({ '-foo':1, '--bar':1 }), '-foo --bar');
t.end();
});
test('objects (variadic)', t => {
t.is(fn({}, {}), '');
t.is(fn({ foo:1 }, { bar:2 }), 'foo bar');
t.is(fn({ foo:1 }, null, { baz:1, bat:0 }), 'foo baz');
t.is(fn({ foo:1 }, {}, {}, { bar:'a' }, { baz:null, bat:Infinity }), 'foo bar bat');
t.end();
});
test('arrays', t => {
t.is(fn([]), '');
t.is(fn(['foo']), 'foo');
t.is(fn(['foo', 'bar']), 'foo bar');
t.is(fn(['foo', 0 && 'bar', 1 && 'baz']), 'foo baz');
t.end();
});
test('arrays (nested)', t => {
t.is(fn([[[]]]), '');
t.is(fn([[['foo']]]), 'foo');
t.is(fn([true, [['foo']]]), 'foo');;
t.is(fn(['foo', ['bar', ['', [['baz']]]]]), 'foo bar baz');
t.end();
});
test('arrays (variadic)', t => {
t.is(fn([], []), '');
t.is(fn(['foo'], ['bar']), 'foo bar');
t.is(fn(['foo'], null, ['baz', ''], true, '', []), 'foo baz');
t.end();
});
test('arrays (no `push` escape)', t => {
t.is(fn({ push:1 }), 'push');
t.is(fn({ pop:true }), 'pop');
t.is(fn({ push:true }), 'push');
t.is(fn('hello', { world:1, push:true }), 'hello world push');
t.end();
});
test('functions', t => {
const foo = () => {};
t.is(fn(foo, 'hello'), 'hello');
t.is(fn(foo, 'hello', fn), 'hello');
t.is(fn(foo, 'hello', [[fn], 'world']), 'hello world');
t.end();
});