Skip to content

Commit

Permalink
update tests.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 30, 2012
1 parent dabe970 commit fb34642
Showing 1 changed file with 56 additions and 145 deletions.
201 changes: 56 additions & 145 deletions tests.md
Original file line number Diff line number Diff line change
@@ -1,171 +1,82 @@
- [dimensions](#dimensions)
- [glob](#glob)
- [include](#include)
- [ms](#ms)
- [Parser](#parser)
- [Parser()](#parser)
- [.use(fn)](#usefn)
- [.read(path)](#readpath)
- [.parse(str)](#parsestr)
- [replace](#replace)
1341024169358
1341024169000
# TOC
- [args](#args)
- [bools](#bools)
- [date](#date)
- [dimensions](#dimensions)
- [env(prefix)](#envprefix)
- [glob](#glob)
- [include](#include)
- [ms](#ms)
- [Parser](#parser)
- [Parser()](#parser-parser)
- [.use(fn)](#parser-usefn)
- [.read(path)](#parser-readpath)
- [.parse(str)](#parser-parsestr)
- [replace](#replace)
<a name="" />

<a name="dimensions" />
# dimensions
should return an object with width/height.
<a name="args" />
# args
should support --NAME.

```js
dim('', '200x400').should.eql({ width: 200, height: 400 });
var fn = args(['foo', 'bar']);
fn('dev ui', false).should.be.false;

fn = args(['foo', '--dev-ui']);
fn('dev ui', false).should.be.true;
```

<a name="glob" />
# glob
should perform a sync glob.
should support --no-NAME.

```js
glob('', 'glob test/fixtures/*.js').should.eql(
['test/fixtures/bar.js',
'test/fixtures/baz.js',
'test/fixtures/foo.js']
);

glob('', 'glob test/fixtures/b*.js').should.eql(
['test/fixtures/bar.js',
'test/fixtures/baz.js']
);

glob('', 'glob test/fixtures/{bar,foo}.js').should.eql(
['test/fixtures/bar.js',
'test/fixtures/foo.js']
);
var fn = args(['foo', '--no-dev-ui']);
fn('dev ui', true).should.be.false;
```

<a name="include" />
# include
should parse the given file.
should support --NAME val.

```js
Parser()
.use(include)
.read('test/fixtures/include.json')
.should.eql([
"foo",
{
"view videos": "guest",
"delete videos": "admin"
},
["admin", "guest"]
]);
var fn = args(['foo', '--dev-ui', 'yes']);
fn('dev ui', false).should.equal('yes');
```

<a name="ms" />
# ms
should parse string ms representations.
<a name="bools" />
# bools
should parse string bool representations.

```js
ms('', '1000ms').should.equal(1000);
ms('', '1s').should.equal(1000);
ms('', '4 seconds').should.equal(4000);
ms('', '4 seconds').should.equal(4000);
ms('', '2 minutes').should.equal(2 * 60000);
ms('', '1 hour').should.equal(3600000);
ms('', '2 days').should.equal(2 * 86400000);
ms('', '5y').should.equal(5 * 31557600000);
ms('', '1 year').should.equal(31557600000);
ms('', '5 years').should.equal(5 * 31557600000);
bools('', 'yes').should.be.true;
bools('', 'enabled').should.be.true;
bools('', 'no').should.be.false;
bools('', 'disabled').should.be.false;
bools('', true).should.be.true;
bools('', 'other').should.be.equal('other');
```

<a name="date" />
# date
<a name="dimensions" />
# dimensions
<a name="envprefix" />
# env(prefix)
<a name="glob" />
# glob
<a name="include" />
# include
<a name="ms" />
# ms
<a name="parser" />
# Parser
<a name="parser" />
<a name="parser-parser" />
## Parser()
should return a new Parser.

```js
Parser().should.be.an.instanceof(Parser);
```

<a name="usefn" />
<a name="parser-usefn" />
## .use(fn)
should be invoked with both the key and value.

```js
var parser = new Parser;

parser.use(function(key, val){
key.should.equal('foo');
val.should.equal('bar');
done();
});

parser.parse('{ "foo": "bar" }');
```

<a name="readpath" />
<a name="parser-readpath" />
## .read(path)
should read the JSON and apply plugins.

```js
var parser = new Parser;
parser.use(function(key, val){ return val.toUpperCase(); });
var obj = parser.read('test/fixtures/config.json');
obj.should.eql({ foo: 'BAR', bar: 'BAZ' });
```

<a name="parsestr" />
<a name="parser-parsestr" />
## .parse(str)
should invoke each plugin.

```js
var parser = new Parser
, calls = [];

parser.use(function(key, val){
key.should.equal('foo');
val.should.equal('bar');
calls.push('a');
});

parser.use(function(key, val){
key.should.equal('foo');
val.should.equal('bar');
calls.push('b');
calls.should.eql(['a', 'b']);
done();
});

parser.parse('{ "foo": "bar" }');
```

should not modify when undefined is returned.

```js
var parser = new Parser;

parser.use(function(key, val){});

parser.parse('{ "foo": "bar" }')
.should.eql({ foo: 'bar' });
```

should modify when a value is returned.

```js
var parser = new Parser;

parser.use(function(key, val){ return 'hey'; });

parser.parse('{ "foo": "bar" }')
.should.eql({ foo: 'hey' });
```

<a name="replace" />
# replace
should replace occurrences of a string.

```js
replace('{root}', '/my/path')
('', '{root}/foo')
.should.equal('/my/path/foo');
```

0 comments on commit fb34642

Please sign in to comment.