Kaynağa Gözat

add QUnit tests based on the examples folder.

tags/0.5.0-vsc
thegrandpoobah 16 yıl önce
ebeveyn
işleme
6cc86e23a1
4 değiştirilmiş dosya ile 1751 ekleme ve 0 silme
  1. +119
    -0
      test/qunit/qunit.css
  2. +1069
    -0
      test/qunit/qunit.js
  3. +17
    -0
      test/unit.html
  4. +546
    -0
      test/unit.js

+ 119
- 0
test/qunit/qunit.css Dosyayı Görüntüle

@@ -0,0 +1,119 @@

ol#qunit-tests {
font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
margin:0;
padding:0;
list-style-position:inside;

font-size: smaller;
}
ol#qunit-tests li{
padding:0.4em 0.5em 0.4em 2.5em;
border-bottom:1px solid #fff;
font-size:small;
list-style-position:inside;
}
ol#qunit-tests li ol{
box-shadow: inset 0px 2px 13px #999;
-moz-box-shadow: inset 0px 2px 13px #999;
-webkit-box-shadow: inset 0px 2px 13px #999;
margin-top:0.5em;
margin-left:0;
padding:0.5em;
background-color:#fff;
border-radius:15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
}
ol#qunit-tests li li{
border-bottom:none;
margin:0.5em;
background-color:#fff;
list-style-position: inside;
padding:0.4em 0.5em 0.4em 0.5em;
}

ol#qunit-tests li li.pass{
border-left:26px solid #C6E746;
background-color:#fff;
color:#5E740B;
}
ol#qunit-tests li li.fail{
border-left:26px solid #EE5757;
background-color:#fff;
color:#710909;
}
ol#qunit-tests li.pass{
background-color:#D2E0E6;
color:#528CE0;
}
ol#qunit-tests li.fail{
background-color:#EE5757;
color:#000;
}
ol#qunit-tests li strong {
cursor:pointer;
}
h1#qunit-header{
background-color:#0d3349;
margin:0;
padding:0.5em 0 0.5em 1em;
color:#fff;
font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
border-top-right-radius:15px;
border-top-left-radius:15px;
-moz-border-radius-topright:15px;
-moz-border-radius-topleft:15px;
-webkit-border-top-right-radius:15px;
-webkit-border-top-left-radius:15px;
text-shadow: rgba(0, 0, 0, 0.5) 4px 4px 1px;
}
h2#qunit-banner{
font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
height:5px;
margin:0;
padding:0;
}
h2#qunit-banner.qunit-pass{
background-color:#C6E746;
}
h2#qunit-banner.qunit-fail, #qunit-testrunner-toolbar {
background-color:#EE5757;
}
#qunit-testrunner-toolbar {
font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
padding:0;
/*width:80%;*/
padding:0em 0 0.5em 2em;
font-size: small;
}
h2#qunit-userAgent {
font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
background-color:#2b81af;
margin:0;
padding:0;
color:#fff;
font-size: small;
padding:0.5em 0 0.5em 2.5em;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
p#qunit-testresult{
font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
margin:0;
font-size: small;
color:#2b81af;
border-bottom-right-radius:15px;
border-bottom-left-radius:15px;
-moz-border-radius-bottomright:15px;
-moz-border-radius-bottomleft:15px;
-webkit-border-bottom-right-radius:15px;
-webkit-border-bottom-left-radius:15px;
background-color:#D2E0E6;
padding:0.5em 0.5em 0.5em 2.5em;
}
strong b.fail{
color:#710909;
}
strong b.pass{
color:#5E740B;
}

+ 1069
- 0
test/qunit/qunit.js
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 17
- 0
test/unit.html Dosyayı Görüntüle

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>mustache.js unit tests</title>
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit/qunit.js"></script>
<script type="text/javascript" src="../mustache.js"></script>
<script type="text/javascript" src="unit.js"></script>
</head>
<body>
<h1 id="qunit-header">mustache.js unit tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
</body>
</html>

+ 546
- 0
test/unit.js Dosyayı Görüntüle

@@ -0,0 +1,546 @@
test("Parser", function() {
expect(2);

// matches whitespace_partial.html
equals(
Mustache.to_html(
'<h1>{{ greeting }}</h1>\n{{> partial }}\n<h3>{{ farewell }}</h3>',
{
greeting: function() {
return "Welcome";
},

farewell: function() {
return "Fair enough, right?";
},

partial: {
name: "Chris",
value: 10000,
taxed_value: function() {
return this.value - (this.value * 0.4);
},
in_ca: true
}
},
{partial:'Hello {{ name}}\nYou have just won ${{value }}!\n{{# in_ca }}\nWell, ${{ taxed_value }}, after taxes.\n{{/ in_ca }}\n'}
),
'<h1>Welcome</h1>\nHello Chris\nYou have just won $10000!\nWell, $6000, after taxes.\n\n<h3>Fair enough, right?</h3>',
'Whitespace in Tag names'
);
equals(
Mustache.to_html(
'{{tag1}}\n\n\n{{tag2}}\n',
{ tag1: 'Hello', tag2: 'World' },
{}
),
'Hello\n\n\nWorld\n',
'Preservation of white space'
);
});

test("Basic Variables", function() {
expect(3);
// matches escaped.html
equals(
Mustache.to_html(
'<h1>{{title}}</h1>\nBut not {{entities}}.\n',
{
title: function() {
return "Bear > Shark";
},
entities: "&quot;"
},
{}
),
'<h1>Bear &gt; Shark</h1>\nBut not &quot;.\n',
'HTML Escaping'
);
// matches null_string.html
equals(
Mustache.to_html(
'Hello {{name}}\nglytch {{glytch}}\nbinary {{binary}}\nvalue {{value}}\nnumeric {{numeric}}',
{
name: "Elise",
glytch: true,
binary: false,
value: null,
numeric: function() {
return NaN;
}
},
{}
),
'Hello Elise\nglytch true\nbinary false\nvalue \nnumeric NaN',
'Different variable types'
);
// matches two_in_a_row.html
equals(
Mustache.to_html(
'{{greeting}}, {{name}}!',
{
name: "Joe",
greeting: "Welcome"
},
{}
),
'Welcome, Joe!'
);
});

test("'{' or '&' (Unescaped Variable)", function() {
expect(2);
// matches unescaped.html
equals(
Mustache.to_html(
'<h1>{{{title}}}</h1>',
{
title: function() {
return "Bear > Shark";
}
},
{}
),
'<h1>Bear > Shark</h1>',
'{ character'
);
equals(
Mustache.to_html(
'<h1>{{&title}}</h1>',
{
title: function() {
return "Bear > Shark";
}
},
{}
),
'<h1>Bear > Shark</h1>',
'& character'
);
});

test("'#' (Sections)", function() {
expect(7);
// matches array_of_partials_implicit_partial.html
equals(
Mustache.to_html(
'Here is some stuff!\n{{#numbers}}\n{{>partial}}\n{{/numbers}}',
{ numbers: ['1', '2', '3', '4'] },
{ partial: '{{.}}' }
),
'Here is some stuff!\n1\n2\n3\n4\n',
'Array of Partials (Implicit)'
);
// matches array_of_partials_partial.html
equals(
Mustache.to_html(
'Here is some stuff!\n{{#numbers}}\n{{>partial}}\n{{/numbers}}',
{ numbers: [{i: '1'}, {i: '2'}, {i: '3'}, {i: '4'}] },
{ partial: '{{i}}' }
),
'Here is some stuff!\n1\n2\n3\n4\n',
'Array of Partials (Explicit)'
);
// matches array_of_strings.html
equals(
Mustache.to_html(
'{{#array_of_strings}}{{.}} {{/array_of_strings}}',
{array_of_strings: ['hello', 'world']},
{}
),
'hello world ',
'Array of Strings'
);
// mathces higher_order_sections.html
equals(
Mustache.to_html(
'{{#bolder}}Hi {{name}}.{{/bolder}}\n',
{
"name": "Tater",
"helper": "To tinker?",
"bolder": function() {
return function(text, render) {
return "<b>" + render(text) + '</b> ' + this.helper;
}
}
},
{}
),
'<b>Hi Tater.</b> To tinker?'
);
// matches recursion_with_same_names.html
equals(
Mustache.to_html(
'{{ name }}\n{{ description }}\n\n{{#terms}}\n {{name}}\n {{index}}\n{{/terms}}\n',
{
name: 'name',
description: 'desc',
terms: [
{name: 't1', index: 0},
{name: 't2', index: 1},
]
},
{}
),
'name\ndesc\n\n t1\n 0\n t2\n 1\n'
);
// matches reuse_of_enumerables.html
equals(
Mustache.to_html(
'{{#terms}}\n {{name}}\n {{index}}\n{{/terms}}\n{{#terms}}\n {{name}}\n {{index}}\n{{/terms}}\n',
{
terms: [
{name: 't1', index: 0},
{name: 't2', index: 1},
]
},
{}
),
' t1\n 0\n t2\n 1\n t1\n 0\n t2\n 1\n',
'Lazy match of Section and Inverted Section'
);
// matches section_as_context.html
equals(
Mustache.to_html(
'{{#a_object}}\n <h1>{{title}}</h1>\n <p>{{description}}</p>\n <ul>\n {{#a_list}}\n <li>{{label}}</li>\n {{/a_list}}\n </ul>\n{{/a_object}}\n',
{
a_object: {
title: 'this is an object',
description: 'one of its attributes is a list',
a_list: [{label: 'listitem1'}, {label: 'listitem2'}]
}
},
{}
),
' <h1>this is an object</h1>\n <p>one of its attributes is a list</p>\n <ul>\n <li>listitem1</li>\n <li>listitem2</li>\n </ul>\n',
'Lazy match of Section and Inverted Section'
);
});

test("'^' (Inverted Section)", function() {
expect(1);
// matches inverted_section.html
equals(
Mustache.to_html(
'{{#repo}}<b>{{name}}</b>{{/repo}}\n{{^repo}}No repos :({{/repo}}\n',
{
"repo": []
},
{}
),
'No repos :('
);
});

test("'>' (Partials)", function() {
expect(4);
// matches view_partial.html
equals(
Mustache.to_html(
'<h1>{{greeting}}</h1>\n{{>partial}}\n<h3>{{farewell}}</h3>',
{
greeting: function() {
return "Welcome";
},
farewell: function() {
return "Fair enough, right?";
},
partial: {
name: "Chris",
value: 10000,
taxed_value: function() {
return this.value - (this.value * 0.4);
},
in_ca: true
}
},
{partial: 'Hello {{name}}\nYou have just won ${{value}}!\n{{#in_ca}}\nWell, ${{ taxed_value }}, after taxes.\n{{/in_ca}}\n'}
),
'<h1>Welcome</h1>\nHello Chris\nYou have just won $10000!\nWell, $6000, after taxes.\n\n<h3>Fair enough, right?</h3>'
);
// matches array_partial.html
equals(
Mustache.to_html(
'{{>partial}}',
{
partial: {
array: ['1', '2', '3', '4']
}
},
{ partial: 'Here\'s a non-sense array of values\n{{#array}}\n {{.}}\n{{/array}}' }
),
'Here\'s a non-sense array of values\n 1\n 2\n 3\n 4\n'
);
// matches template_partial.html
equals(
Mustache.to_html(
'<h1>{{title}}</h1>\n{{>partial}}',
{
title: function() {
return "Welcome";
},
partial: {
again: "Goodbye"
}
},
{partial:'Again, {{again}}!'}
),
'<h1>Welcome</h1>\nAgain, Goodbye!'
);
// matches partial_recursion.html
equals(
Mustache.to_html(
'{{name}}\n{{#kids}}\n{{>partial}}\n{{/kids}}',
{
name: '1',
kids: [
{
name: '1.1',
children: [
{name: '1.1.1'}
]
}
]
},
{partial:'{{name}}\n{{#children}}\n{{>partial}}\n{{/children}}'}
),
'1\n1.1\n1.1.1\n\n\n'
);
});

test("'=' (Set Delimiter)", function() {
expect(1);
// matches delimiter.html
equals(
Mustache.to_html(
'{{=<% %>=}}*\n<% first %>\n* <% second %>\n<%=| |=%>\n* | third |\n|={{ }}=|\n* {{ fourth }}',
{
first: "It worked the first time.",
second: "And it worked the second time.",
third: "Then, surprisingly, it worked the third time.",
fourth: "Fourth time also fine!."
},
{}
),
'*\nIt worked the first time.\n* And it worked the second time.\n* Then, surprisingly, it worked the third time.\n* Fourth time also fine!.',
'Simple Set Delimiter'
);
});

test("'!' (Comments)", function() {
expect(1);
// matches comments.html
equals(
Mustache.to_html(
'<h1>{{title}}{{! just something interesting... or not... }}</h1>\n',
{
title: function() {
return "A Comedy of Errors";
}
},
{}
),
'<h1>A Comedy of Errors</h1>\n'
);
});

test("'%' (Pragmas)", function() {
expect(2);
// matches array_of_strings_options.html
equals(
Mustache.to_html(
'{{%IMPLICIT-ITERATOR iterator=rob}}\n{{#array_of_strings_options}}{{rob}} {{/array_of_strings_options}}',
{array_of_strings_options: ['hello', 'world']},
{}
),
'\nhello world ',
'IMPLICIT-ITERATOR pragma'
);
// matches unknown_pragma.txt
try {
equals(
Mustache.to_html(
'{{%I-HAVE-THE-GREATEST-MUSTACHE}}\n',
{},
{}
),
'hello world ',
'IMPLICIT-ITERATOR pragma'
);
ok(false);
} catch (e) {
equals(e.message, 'This implementation of mustache doesn\'t understand the \'I-HAVE-THE-GREATEST-MUSTACHE\' pragma');
}
});

test("Empty", function() {
expect(2);
// matches empty_template.html
equals(
Mustache.to_html(
'<html><head></head><body><h1>Test</h1></body></html>',
{},
{}
),
'<html><head></head><body><h1>Test</h1></body></html>',
'Empty Template'
);
// matches empty_partial.html
equals(
Mustache.to_html(
'hey {{foo}}\n{{>partial}}\n',
{
foo: 1
},
{partial: 'yo'}
),
'hey 1\nyo\n',
'Empty Partial'
);
});

test("Demo", function() {
expect(2);
// matches simple.html
equals(
Mustache.to_html(
'Hello {{name}}\nYou have just won ${{value}}!\n{{#in_ca}}\nWell, ${{ taxed_value }}, after taxes.\n{{/in_ca}}',
{
name: "Chris",
value: 10000,
taxed_value: function() {
return this.value - (this.value * 0.4);
},
in_ca: true
},
{}
),
'Hello Chris\nYou have just won $10000!\nWell, $6000, after taxes.\n',
'A simple template'
);
// matches complex.html
var template = [
'<h1>{{header}}</h1>',
'{{#list}}',
' <ul>',
' {{#item}}',
' {{#current}}',
' <li><strong>{{name}}</strong></li>',
' {{/current}}',
' {{#link}}',
' <li><a href="{{url}}">{{name}}</a></li>',
' {{/link}}',
' {{/item}}',
' </ul>',
'{{/list}}',
'{{#empty}}',
' <p>The list is empty.</p>',
'{{/empty}}',
].join('\n');
var view = {
header: function() {
return "Colors";
},
item: [
{name: "red", current: true, url: "#Red"},
{name: "green", current: false, url: "#Green"},
{name: "blue", current: false, url: "#Blue"}
],
link: function() {
return this["current"] !== true;
},
list: function() {
return this.item.length !== 0;
},
empty: function() {
return this.item.length === 0;
}
};
var expected_result = [
'<h1>Colors</h1>',
' <ul>',
' <li><strong>red</strong></li>',
' <li><a href="#Green">green</a></li>',
' <li><a href="#Blue">blue</a></li>',
' </ul>',
''
].join('\n');
equals(
Mustache.to_html(
template,
view,
{}
),
expected_result,
'A complex template'
);
});

test("Regression Suite", function() {
expect(3);
// matches bug_11_eating_whitespace.html
equals(
Mustache.to_html(
'{{tag}} foo',
{ tag: "yo" },
{}
),
'yo foo',
'Issue 11'
);
// matches delimiters_partial.html
equals(
Mustache.to_html(
'{{#enumerate}}\n{{>partial}}\n{{/enumerate}}',
{ enumerate: [ { text: 'A' }, { text: 'B' } ] },
{ partial: '{{=[[ ]]=}}\n{{text}}\n[[={{ }}=]]' }
),
'{{text}}\n{{text}}\n',
'Issue 44'
);
// matches bug_46_set_delimiter.html
equals(
Mustache.to_html(
'{{=[[ ]]=}}[[#IsMustacheAwesome]]mustache is awesome![[/IsMustacheAwesome]]',
{IsMustacheAwesome: true},
{}
),
'mustache is awesome!',
'Issue 46'
);
});

Yükleniyor…
İptal
Kaydet