Skip to content

Commit

Permalink
refactor tests, adds PHP tests
Browse files Browse the repository at this point in the history
* moves the auto_link test data into a JSON file
* adds a PHP auto_link test usin the same JSON test data
  • Loading branch information
aaronpk committed Jan 24, 2016
1 parent 028a460 commit fcbb5af
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 46 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ To run the PHP tests:
```
$ phpunit.phar
```

To run the JS tests:

```
$ tape js-tests/*.js | tap-spec
```

or if you don't have tape and tap-spec installed globally, then

```
$ ./node_modules/tape/bin/tape js-tests/*.js | ./node_modules/tap-spec/bin/cmd.js
```
12 changes: 12 additions & 0 deletions js-tests/auto_link-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var test = require('tape');

var auto_link = require('../cassis').auto_link;

var tests = require('../test-data/auto_link.json');

test('tests', function (t) {
t.plan(tests.length)
tests.forEach(function (obj) {
t.equal(auto_link(obj.str), obj.expect, obj.msg)
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "cassis.js",
"scripts": {
"test": "tape test/*.js | tap-spec"
"test": "tape js-tests/*.js | tap-spec"
},
"repository": {
"type": "git",
Expand Down
18 changes: 18 additions & 0 deletions php-tests/AutoLinkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
class AutoLinkTest extends PHPUnit_Framework_TestCase {

/**
* @dataProvider linkProvider
*/
public function testAutoLink($expected, $input) {
$this->assertEquals($expected, auto_link($input));
}

public function linkProvider() {
$tests = json_decode(file_get_contents(dirname(__FILE__).'/../test-data/auto_link.json'));
return array_map(function($test){
return [$test->expect, $test->str];
}, $tests);
}

}
22 changes: 22 additions & 0 deletions test-data/auto_link.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"str":"This string definately does not have any urls in it",
"expect":"This string definately does not have any urls in it",
"msg":"noop on strings without links"
},
{
"str":"this string definitely has a link to tantek.com in it",
"expect":"this string definitely has a link to <a class=\"auto-link\" href=\"http://tantek.com\">tantek.com</a> in it",
"msg":"auto_link simple .com links"
},
{
"str":"This has a stanford.edu link",
"expect":"This has a <a class=\"auto-link\" href=\"http://stanford.edu\">stanford.edu</a> link",
"msg":"auto_link simple .edu links"
},
{
"str":"This has a bret.io link",
"expect":"This has a <a class=\"auto-link\" href=\"http://bret.io\">bret.io</a> link",
"msg":"auto_link simple .io links"
}
]
45 changes: 0 additions & 45 deletions test/auto_link-test.js

This file was deleted.

0 comments on commit fcbb5af

Please sign in to comment.