Created
March 29, 2012 13:42
-
-
Save bebraw/2237543 to your computer and use it in GitHub Desktop.
suite.js examples
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
var suite = require('suite.js'); | |
var t = require('./ghw').transformers; | |
// regular tests, just kv-pairs | |
suite(matchToHTML(t.bracket_pipe_link), { | |
'[[foo|bar]]': '<a href="bar.html">foo</a>', | |
'[[foo|bar bar]]': '<a href="bar-bar.html">foo</a>', | |
'[[a|b]] [[b|a]]': '<a href="b.html">a</a> <a href="a.html">b</a>', | |
'[[a|http://b]]': '<a href="http://b">a</a>', | |
'[[a|https://b]]': '<a href="https://b">a</a>', | |
'[[foo|Foo Bar]]': '<a href="foo-bar.html">foo</a>' | |
}); | |
// mixing regular and n-1 tests here | |
suite(matchToAST(t.table), suite.merge( | |
// could use multiple for these too | |
{ | |
'foo|bar\n-|-\na|\nboo': undefined, | |
'foo|bar\n-': undefined, | |
'foo\nbar': undefined, | |
'foo|bar': undefined | |
}, | |
// these will have the same result | |
suite.multiple([ | |
'foo|bar\n-|-', | |
'|foo|bar\n-|-', | |
'foo|bar|\n-|-', | |
'|foo|bar|\n-|-' | |
], | |
{header: ['foo', 'bar'], align: ['left', 'left'], lines: []} | |
) | |
)); | |
// In case you are wondering | |
// matchToHTML, matchToAST instrument given func | |
// usually you just pass a direct func reference to a suite |
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
var suite = require('suite.js'); | |
var utils = require('./utils'); | |
// number generators and invariant | |
// generators range from -100 to 100 | |
// without param can pass any float from the whole range | |
suite(sum, suite.generate(1000, | |
[suite.number(100), suite.number(100)], | |
function(op, a, b) { | |
// commutativity | |
return op(a, b) == op(b, a); | |
}) | |
); | |
// string generators and invariant | |
// words contain 10 random chars from ASCII range | |
// this has been limited to visible characters | |
suite(reverse, suite.generate(1000, | |
[suite.word(10)], | |
function(op, a) { | |
// reverse of reverse is input itself | |
return op(op(a)) == a; | |
}) | |
); |
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
exports.sum = sum; | |
exports.reverse = reverse; | |
function sum(a, b) { | |
return a + b; | |
} | |
function reverse(a) { | |
return a.split('').reverse().join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment