Skip to content

Commit

Permalink
#2 完善测试脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
zswang committed Jan 23, 2016
1 parent 5c81d8e commit 7ab05bf
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- 0.11
- 0.10
script:
- npm run lint
- npm run test
- 0.12
before_install:
- sudo add-apt-repository ppa:ondrej/php5-oldstable --yes
- sudo apt-get update -y
- sudo apt-get install php5 -y
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
jphps
jphps(<%>)
-----

[![Build Status](https://img.shields.io/travis/zswang/jphps/master.svg)](https://travis-ci.org/zswang/jphps)
[![NPM version](https://img.shields.io/npm/v/jphps.svg)](http://badge.fury.io/js/jphps)

## 处理前

```html
function renderItem($item) {
if (isset($item)) {
<li>
<a href="!#{$item['url']}">#{$item['title']}</a>
</li>
<li>
<a href="!#{$item['url']}">#{$item['title']}</a>
</li>
}
}

Expand All @@ -20,9 +23,9 @@ renderItem(array('url' => 'http://google.com/', 'title' => 'Google'));
```php
<?php function renderItem($item) { ?>
<?php if (isset($item)) { ?>
<li>
<a href="<?php echo $item['url'] ?>"><?php echo htmlentities($item['title']) ?></a>
</li>
<li>
<a href="<?php echo $item['url'] ?>"><?php echo htmlentities($item['title']) ?></a>
</li>
<?php } ?>
<?php } ?>

Expand Down
45 changes: 45 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var assert = require('should');
var jphps = require('../.');
var fs = require('fs');
var util = require('util');

/**
* 清除 \r,为兼容 Windows 下的文本换行符 CRLF
*/
function cleanCRLF(text) {
return String(text).replace(/\r\n?/g, '\n');
}

// coverage
jphps.build();
jphps.build('\r');

function fixture(name) {
return fs.readFileSync('test/fixtures/' + name, 'utf8').replace(/\r/g, '');
}

describe('fixtures', function() {
var items = fs.readdirSync('test/fixtures').filter(function(item) {
return /\.input\.html$/.test(item);
}).map(function(item) {
return item.replace(/\.input\.html$/, '');
});

items.forEach(function(item) {
var output_php = util.format('test/fixtures/%s.output.php', item);
var text_input_html = cleanCRLF(fs.readFileSync(util.format('test/fixtures/%s.input.html', item)));
var text_output_html = cleanCRLF(fs.readFileSync(util.format('test/fixtures/%s.output.html', item)));
var text_output_php = cleanCRLF(fs.readFileSync(output_php));
it(item, function() {
assert.equal(text_output_php, jphps.build(text_input_html));
});
it(item + ' run()', function(done) {
var exec = require("child_process").exec;
exec(util.format('php "%s"', output_php), function (error, stdout, stderr) {
assert.equal(error, null);
assert.equal(text_output_html, stdout);
done();
});
})
});
});
2 changes: 0 additions & 2 deletions travis.sh

This file was deleted.

0 comments on commit 7ab05bf

Please sign in to comment.