Skip to content

Commit f061c65

Browse files
committed
more tests
1 parent 0dd2fdd commit f061c65

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

lib/posthtml-render.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
(function(global) {
2-
2+
/**
3+
* Parse PostHTMLTree to html
4+
* @param {Object} tree PostHTMLTree
5+
* @param {Object} options Parse options
6+
* @return {String} html string
7+
*/
38
function postHTMLRender(tree, options) {
49
options = options || {};
510

test/templates/parser.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/templates/render.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Html</title>
6+
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, IE=9">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<meta name="description" content="Description">
9+
10+
<meta property="og:url" content="http://github.com/posthtml">
11+
<meta property="og:type" content="website">
12+
<meta property="og:site_name" content="PostHTML">
13+
14+
<link rel="stylesheet" type="text/css" href="path/to/file.css">
15+
<script src="path/to/file.js" type="text/javascript" charset="utf-8"></script>
16+
17+
<script>
18+
console.log('PostHTML!');
19+
</script>
20+
</head>
21+
<body onload="try{if(!google.j.b){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.focus();}}catch(e){}if(document.images)new Image().src='/images/nav_logo231.png'">
22+
23+
<h1>Title</h1>
24+
<p>Lorem ipsum dolor sit amet...</p>
25+
26+
<section class="foo" style="color: red;">
27+
<header class="foo bar" style="color: blue; border: 1px solid" id="id">
28+
<div class="foo bar baz" id="idd" data-url="url/to/">
29+
<span id="idd" data-data="{ foo: 'bar' }">
30+
<a href="#">
31+
<img src="path/to/img">
32+
Link
33+
</a>
34+
</span>
35+
</div>
36+
</header>
37+
</section>
38+
39+
<script type="text/javascript">
40+
(function(){function k(a){++b;a=a||window.event;google.iTick(a.target||a.srcElement)}if(google.timers&&google.timers.load.t){var c,b,f;google.c.c.a&&(google.startTick("aft"),google.afte=!1);var g=document.getElementsByTagName("img");c=g.length;for(var d=b=0,a;d<c;++d)if(a=g[d],google.c.c.i&&"none"==a.style.display)++b;else{var h="string"!=typeof a.src||!a.src,e=h||a.complete;google.c.c.d?a.getAttribute("data-deferred")&&(e=!1,a.removeAttribute("data-deferred")):google.c.c.m&&h&&a.getAttribute("data-bsrc")&&
41+
(e=!1);e?++b:google.rll(a,!0,k)}f=c-b;google.rll(window,!1,function(){google.tick("load","ol");google.c.e("load","imc",String(b));google.c.e("load","imn",String(c));google.c.e("load","imp",String(f));google.unblockCSI("load","ol")});google.tick("load",["prt","iml"])}})();
42+
</script>
43+
44+
<script src="path/to/file2.js" type="text/javascript" charset="utf-8"></script>
45+
</body>
46+
</html>
File renamed without changes.

test/test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ var render = require('../lib/posthtml-render.js');
22
var describe = require('mocha').describe;
33
var it = require('mocha').it;
44
var expect = require('chai').expect;
5+
var path = require('path');
6+
var fs = require('fs');
7+
var html = fs.readFileSync(path.resolve(__dirname, 'templates/render.html'), 'utf8').toString();
8+
var tree = require('./templates/parser.js');
59

610
describe('PostHTML-Render test', function() {
711

12+
it('tree to html', function() {
13+
expect(html).to.eql(render(tree));
14+
});
15+
816
it('string', function() {
917
expect(render('Hello world!')).to.eql('Hello world!');
1018
});
@@ -68,11 +76,26 @@ describe('PostHTML-Render test', function() {
6876
describe('options', function() {
6977
describe('singleTag', function() {
7078
it('default', function() {
71-
expect(render({ tag: 'img' })).to.eql('<img>');
79+
80+
var SINGLE_TAGS = [
81+
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen',
82+
'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'
83+
];
84+
85+
expect(render(SINGLE_TAGS.map(function(tag) {
86+
return { tag: tag };
87+
}))).to.eql(SINGLE_TAGS.map(function(tag) {
88+
return '<' + tag + '>';
89+
}).join(''));
7290
});
91+
7392
it('set in options', function() {
7493
expect(render({ tag: 'rect' }, { singleTags: ['rect'] })).to.eql('<rect>');
7594
});
95+
96+
it('safe attrs', function() {
97+
expect(render({ tag: 'rect', attrs: { id: 'id' } }, { singleTags: ['rect'] })).to.eql('<rect id="id">');
98+
});
7699
});
77100

78101
describe('closingSingleTag', function() {

0 commit comments

Comments
 (0)