-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
node_modules | ||
.DS_Store | ||
*-lock.* | ||
*.lock | ||
*.log | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,75 @@ | ||
const test = require('tape'); | ||
const fn = require('../dist/obj-str'); | ||
import { suite } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import objstr from '../src'; | ||
|
||
const one = true; | ||
const two = true; | ||
const bad = false; | ||
const key = 'abc'; | ||
function is(input, expect) { | ||
assert.is(objstr(input), expect); | ||
} | ||
|
||
test('obj-str', t => { | ||
t.equal(typeof fn, 'function', 'exports a function'); | ||
const API = suite('exports'); | ||
|
||
t.equal(fn(), '', 'returns empty string by default'); | ||
t.equal(fn({}), '', `{} --> ''`); | ||
t.equal(fn({foo: true}), 'foo', `{ foo:true } --> foo`); | ||
t.equal(fn({foo: true, bar: false}), 'foo', `{ foo:true, bar:false } --> foo`); | ||
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`); | ||
t.equal(fn({one, two, bad}), 'one two', `{ one, two, bad } --> one two`); | ||
t.equal(fn({'-foo': true}), '-foo', `{ '-foo':true } --> -foo`); | ||
t.equal(fn({[key]: true}), 'abc', `{ [key]:true } --> abc`); | ||
API('should export a function', () => { | ||
assert.type(objstr, 'function'); | ||
}); | ||
|
||
API.run(); | ||
|
||
// --- | ||
|
||
const usage = suite('usage'); | ||
|
||
usage('true -> ""', () => { | ||
is(true, ''); | ||
}); | ||
|
||
usage('false -> ""', () => { | ||
is(false, ''); | ||
}); | ||
|
||
usage('undefined -> ""', () => { | ||
is(undefined, ''); | ||
}); | ||
|
||
usage('null -> ""', () => { | ||
is(null, ''); | ||
}); | ||
|
||
usage('{} -> ""', () => { | ||
is({}, ''); | ||
}); | ||
|
||
t.end(); | ||
usage('[] -> ""', () => { | ||
is([], ''); | ||
}); | ||
|
||
usage('{ foo } -> "foo"', () => { | ||
is({ foo: true }, 'foo'); | ||
is({ foo: 1 }, 'foo'); | ||
}); | ||
|
||
usage('{ foo, bar } -> "foo"', () => { | ||
is({ foo: true, bar: false }, 'foo'); | ||
is({ foo: 1, bar: 0 }, 'foo'); | ||
}); | ||
|
||
usage('{ foo, bar, baz } -> "foo baz"', () => { | ||
is({ foo: 1 === 1, bar: 1 !== 1, baz: 1 !== 2 }, 'foo baz'); | ||
is({ foo: assert, bar: null, baz: Date }, 'foo baz'); | ||
}); | ||
|
||
usage('{ one, two, bad } -> "one two"', () => { | ||
let one=true, two=true, bad=false; | ||
is({ one, two, bad }, 'one two'); | ||
}); | ||
|
||
usage('{ "-foo": x } -> "-foo"', () => { | ||
is({ '-foo': true }, '-foo'); | ||
is({ '-foo': 0, '-foo': 1 }, '-foo'); | ||
}); | ||
|
||
usage('{ [key]: x } -> key', () => { | ||
let key = 'abc'; | ||
is({ [key]: true }, 'abc'); | ||
}); | ||
|
||
usage.run(); |