|
1 |
| -const test = require('tape'); |
2 |
| -const fn = require('../dist/obj-str'); |
| 1 | +import { suite } from 'uvu'; |
| 2 | +import * as assert from 'uvu/assert'; |
| 3 | +import objstr from '../src'; |
3 | 4 |
|
4 |
| -const one = true; |
5 |
| -const two = true; |
6 |
| -const bad = false; |
7 |
| -const key = 'abc'; |
| 5 | +function is(input, expect) { |
| 6 | + assert.is(objstr(input), expect); |
| 7 | +} |
8 | 8 |
|
9 |
| -test('obj-str', t => { |
10 |
| - t.equal(typeof fn, 'function', 'exports a function'); |
| 9 | +const API = suite('exports'); |
11 | 10 |
|
12 |
| - t.equal(fn(), '', 'returns empty string by default'); |
13 |
| - t.equal(fn({}), '', `{} --> ''`); |
14 |
| - t.equal(fn({foo: true}), 'foo', `{ foo:true } --> foo`); |
15 |
| - t.equal(fn({foo: true, bar: false}), 'foo', `{ foo:true, bar:false } --> foo`); |
16 |
| - t.equal(fn({foo: 1 === 1, bar: 1 !== 1, baz: 1 !== 2}), 'foo baz', `{ foo:1===1, bar:1!==1, baz:1!==2 } --> foo baz`); |
17 |
| - t.equal(fn({one, two, bad}), 'one two', `{ one, two, bad } --> one two`); |
18 |
| - t.equal(fn({'-foo': true}), '-foo', `{ '-foo':true } --> -foo`); |
19 |
| - t.equal(fn({[key]: true}), 'abc', `{ [key]:true } --> abc`); |
| 11 | +API('should export a function', () => { |
| 12 | + assert.type(objstr, 'function'); |
| 13 | +}); |
| 14 | + |
| 15 | +API.run(); |
| 16 | + |
| 17 | +// --- |
| 18 | + |
| 19 | +const usage = suite('usage'); |
| 20 | + |
| 21 | +usage('true -> ""', () => { |
| 22 | + is(true, ''); |
| 23 | +}); |
| 24 | + |
| 25 | +usage('false -> ""', () => { |
| 26 | + is(false, ''); |
| 27 | +}); |
| 28 | + |
| 29 | +usage('undefined -> ""', () => { |
| 30 | + is(undefined, ''); |
| 31 | +}); |
| 32 | + |
| 33 | +usage('null -> ""', () => { |
| 34 | + is(null, ''); |
| 35 | +}); |
| 36 | + |
| 37 | +usage('{} -> ""', () => { |
| 38 | + is({}, ''); |
| 39 | +}); |
20 | 40 |
|
21 |
| - t.end(); |
| 41 | +usage('[] -> ""', () => { |
| 42 | + is([], ''); |
22 | 43 | });
|
| 44 | + |
| 45 | +usage('{ foo } -> "foo"', () => { |
| 46 | + is({ foo: true }, 'foo'); |
| 47 | + is({ foo: 1 }, 'foo'); |
| 48 | +}); |
| 49 | + |
| 50 | +usage('{ foo, bar } -> "foo"', () => { |
| 51 | + is({ foo: true, bar: false }, 'foo'); |
| 52 | + is({ foo: 1, bar: 0 }, 'foo'); |
| 53 | +}); |
| 54 | + |
| 55 | +usage('{ foo, bar, baz } -> "foo baz"', () => { |
| 56 | + is({ foo: 1 === 1, bar: 1 !== 1, baz: 1 !== 2 }, 'foo baz'); |
| 57 | + is({ foo: assert, bar: null, baz: Date }, 'foo baz'); |
| 58 | +}); |
| 59 | + |
| 60 | +usage('{ one, two, bad } -> "one two"', () => { |
| 61 | + let one=true, two=true, bad=false; |
| 62 | + is({ one, two, bad }, 'one two'); |
| 63 | +}); |
| 64 | + |
| 65 | +usage('{ "-foo": x } -> "-foo"', () => { |
| 66 | + is({ '-foo': true }, '-foo'); |
| 67 | + is({ '-foo': 0, '-foo': 1 }, '-foo'); |
| 68 | +}); |
| 69 | + |
| 70 | +usage('{ [key]: x } -> key', () => { |
| 71 | + let key = 'abc'; |
| 72 | + is({ [key]: true }, 'abc'); |
| 73 | +}); |
| 74 | + |
| 75 | +usage.run(); |
0 commit comments