Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
jaichandra authored and Jai Chandra committed Sep 12, 2016
1 parent 56be690 commit ec7b247
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 2 deletions.
9 changes: 7 additions & 2 deletions js/lib/beautify-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,14 @@
} else if (comment.indexOf('<!--') === 0) { // <!-- comment ...
delimiter = '-->';
matched = true;
} else if (comment.indexOf('{{!') === 0) { // {{! handlebars comment
delimiter = '}}';
} else if (comment.indexOf('{{!--') === 0) { // {{!-- handlebars comment
delimiter = '--}}';
matched = true;
} else if (comment.indexOf('{{!') === 0) { // {{! handlebars comment
if (comment.length === 5 && comment.indexOf('{{!--') === -1) {
delimiter = '}}';
matched = true;
}
} else if (comment.indexOf('<?') === 0) { // {{! handlebars comment
delimiter = '?>';
matched = true;
Expand Down
110 changes: 110 additions & 0 deletions js/test/generated/beautify-html-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,61 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('<div class=\'{{#if thingIs "value"}}{{! comment}}{{/if}}\'></div>');
test_fragment('<div class=\'{{#if thingIs \'value\'}}{{! comment}}{{/if}}\'></div>');

// Handlebars Indenting On - (content = "{{!-- comment--}}")
opts.indent_handlebars = true;
test_fragment('{{page-title}}');
test_fragment('{{#if 0}}{{/if}}');
test_fragment('{{#if 0}}{{!-- comment--}}{{/if}}');
test_fragment('{{#if 0}}\n{{/if}}');
test_fragment(
'{{#if words}}{{/if}}',
'{{#if words}}{{/if}}');
test_fragment(
'{{#if words}}{{!-- comment--}}{{/if}}',
'{{#if words}}{{!-- comment--}}{{/if}}');
test_fragment(
'{{#if words}}{{!-- comment--}}{{/if}}',
'{{#if words}}{{!-- comment--}}{{/if}}');
test_fragment('{{#if 1}}\n <div>\n </div>\n{{/if}}');
test_fragment(
'{{#if 1}}\n<div>\n</div>\n{{/if}}',
'{{#if 1}}\n <div>\n </div>\n{{/if}}');
test_fragment('<div>\n {{#if 1}}\n {{/if}}\n</div>');
test_fragment(
'<div>\n{{#if 1}}\n{{/if}}\n</div>',
'<div>\n {{#if 1}}\n {{/if}}\n</div>');
test_fragment(
'{{#if}}\n{{#each}}\n{{#if}}\n{{!-- comment--}}\n{{/if}}\n{{#if}}\n{{!-- comment--}}\n{{/if}}\n{{/each}}\n{{/if}}',
'{{#if}}\n {{#each}}\n {{#if}}\n {{!-- comment--}}\n {{/if}}\n {{#if}}\n {{!-- comment--}}\n {{/if}}\n {{/each}}\n{{/if}}');
test_fragment('{{#if 1}}\n <div>\n </div>\n{{/if}}');
test_fragment(
'{{#if 1}}\n {{!-- comment--}}\n {{else}}\n {{!-- comment--}}\n{{/if}}',
'{{#if 1}}\n {{!-- comment--}}\n{{else}}\n {{!-- comment--}}\n{{/if}}');
test_fragment(
'{{#if 1}}\n {{else}}\n {{/if}}',
'{{#if 1}}\n{{else}}\n{{/if}}');
test_fragment(
'{{#if thing}}\n{{#if otherthing}}\n {{!-- comment--}}\n {{else}}\n{{!-- comment--}}\n {{/if}}\n {{else}}\n{{!-- comment--}}\n{{/if}}',
'{{#if thing}}\n {{#if otherthing}}\n {{!-- comment--}}\n {{else}}\n {{!-- comment--}}\n {{/if}}\n{{else}}\n {{!-- comment--}}\n{{/if}}');
test_fragment(
'<div{{somestyle}}></div>',
'<div {{somestyle}}></div>');
test_fragment(
'<div{{#if test}}class="foo"{{/if}}>{{!-- comment--}}</div>',
'<div {{#if test}} class="foo" {{/if}}>{{!-- comment--}}</div>');
test_fragment(
'<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>{{!-- comment--}}</div>',
'<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>{{!-- comment--}}</div>');
test_fragment(
'<span{{#if condition}}class="foo"{{/if}}>{{!-- comment--}}</span>',
'<span {{#if condition}} class="foo" {{/if}}>{{!-- comment--}}</span>');
test_fragment('<div unformatted="{{#if}}{{!-- comment--}}{{/if}}">{{!-- comment--}}</div>');
test_fragment('<div unformatted="{{#if }} {{!-- comment--}}{{/if}}">{{!-- comment--}}</div>');
test_fragment('<div class="{{#if thingIs "value"}}{{!-- comment--}}{{/if}}"></div>');
test_fragment('<div class="{{#if thingIs \'value\'}}{{!-- comment--}}{{/if}}"></div>');
test_fragment('<div class=\'{{#if thingIs "value"}}{{!-- comment--}}{{/if}}\'></div>');
test_fragment('<div class=\'{{#if thingIs \'value\'}}{{!-- comment--}}{{/if}}\'></div>');

// Handlebars Indenting On - (content = "{pre{{field1}} {{field2}} {{field3}}post")
opts.indent_handlebars = true;
test_fragment('{{page-title}}');
Expand Down Expand Up @@ -574,6 +629,61 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
test_fragment('<div class=\'{{#if thingIs "value"}}{{! \n mult-line\ncomment \n with spacing\n}}{{/if}}\'></div>');
test_fragment('<div class=\'{{#if thingIs \'value\'}}{{! \n mult-line\ncomment \n with spacing\n}}{{/if}}\'></div>');

// Handlebars Indenting On - (content = "{{!-- \n mult-line\ncomment \n with spacing\n--}}")
opts.indent_handlebars = true;
test_fragment('{{page-title}}');
test_fragment('{{#if 0}}{{/if}}');
test_fragment('{{#if 0}}{{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}');
test_fragment('{{#if 0}}\n{{/if}}');
test_fragment(
'{{#if words}}{{/if}}',
'{{#if words}}{{/if}}');
test_fragment(
'{{#if words}}{{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}',
'{{#if words}}{{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}');
test_fragment(
'{{#if words}}{{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}',
'{{#if words}}{{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}');
test_fragment('{{#if 1}}\n <div>\n </div>\n{{/if}}');
test_fragment(
'{{#if 1}}\n<div>\n</div>\n{{/if}}',
'{{#if 1}}\n <div>\n </div>\n{{/if}}');
test_fragment('<div>\n {{#if 1}}\n {{/if}}\n</div>');
test_fragment(
'<div>\n{{#if 1}}\n{{/if}}\n</div>',
'<div>\n {{#if 1}}\n {{/if}}\n</div>');
test_fragment(
'{{#if}}\n{{#each}}\n{{#if}}\n{{!-- \n mult-line\ncomment \n with spacing\n--}}\n{{/if}}\n{{#if}}\n{{!-- \n mult-line\ncomment \n with spacing\n--}}\n{{/if}}\n{{/each}}\n{{/if}}',
'{{#if}}\n {{#each}}\n {{#if}}\n {{!-- \n mult-line\ncomment \n with spacing\n--}}\n {{/if}}\n {{#if}}\n {{!-- \n mult-line\ncomment \n with spacing\n--}}\n {{/if}}\n {{/each}}\n{{/if}}');
test_fragment('{{#if 1}}\n <div>\n </div>\n{{/if}}');
test_fragment(
'{{#if 1}}\n {{!-- \n mult-line\ncomment \n with spacing\n--}}\n {{else}}\n {{!-- \n mult-line\ncomment \n with spacing\n--}}\n{{/if}}',
'{{#if 1}}\n {{!-- \n mult-line\ncomment \n with spacing\n--}}\n{{else}}\n {{!-- \n mult-line\ncomment \n with spacing\n--}}\n{{/if}}');
test_fragment(
'{{#if 1}}\n {{else}}\n {{/if}}',
'{{#if 1}}\n{{else}}\n{{/if}}');
test_fragment(
'{{#if thing}}\n{{#if otherthing}}\n {{!-- \n mult-line\ncomment \n with spacing\n--}}\n {{else}}\n{{!-- \n mult-line\ncomment \n with spacing\n--}}\n {{/if}}\n {{else}}\n{{!-- \n mult-line\ncomment \n with spacing\n--}}\n{{/if}}',
'{{#if thing}}\n {{#if otherthing}}\n {{!-- \n mult-line\ncomment \n with spacing\n--}}\n {{else}}\n {{!-- \n mult-line\ncomment \n with spacing\n--}}\n {{/if}}\n{{else}}\n {{!-- \n mult-line\ncomment \n with spacing\n--}}\n{{/if}}');
test_fragment(
'<div{{somestyle}}></div>',
'<div {{somestyle}}></div>');
test_fragment(
'<div{{#if test}}class="foo"{{/if}}>{{!-- \n mult-line\ncomment \n with spacing\n--}}</div>',
'<div {{#if test}} class="foo" {{/if}}>{{!-- \n mult-line\ncomment \n with spacing\n--}}</div>');
test_fragment(
'<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>{{!-- \n mult-line\ncomment \n with spacing\n--}}</div>',
'<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>{{!-- \n mult-line\ncomment \n with spacing\n--}}</div>');
test_fragment(
'<span{{#if condition}}class="foo"{{/if}}>{{!-- \n mult-line\ncomment \n with spacing\n--}}</span>',
'<span {{#if condition}} class="foo" {{/if}}>{{!-- \n mult-line\ncomment \n with spacing\n--}}</span>');
test_fragment('<div unformatted="{{#if}}{{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}">{{!-- \n mult-line\ncomment \n with spacing\n--}}</div>');
test_fragment('<div unformatted="{{#if }} {{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}">{{!-- \n mult-line\ncomment \n with spacing\n--}}</div>');
test_fragment('<div class="{{#if thingIs "value"}}{{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}"></div>');
test_fragment('<div class="{{#if thingIs \'value\'}}{{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}"></div>');
test_fragment('<div class=\'{{#if thingIs "value"}}{{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}\'></div>');
test_fragment('<div class=\'{{#if thingIs \'value\'}}{{!-- \n mult-line\ncomment \n with spacing\n--}}{{/if}}\'></div>');


reset_options();
//============================================================
Expand Down
10 changes: 10 additions & 0 deletions test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ exports.test_data = {
{ name: "indent_handlebars", value: "true" }
],
content: '{{! comment}}'
}, {
options: [
{ name: "indent_handlebars", value: "true" }
],
content: '{{!-- comment--}}'
}, {
options: [
{ name: "indent_handlebars", value: "true" }
Expand All @@ -399,6 +404,11 @@ exports.test_data = {
{ name: "indent_handlebars", value: "true" }
],
content: '{{! \\n mult-line\\ncomment \\n with spacing\\n}}'
}, {
options: [
{ name: "indent_handlebars", value: "true" }
],
content: '{{!-- \\n mult-line\\ncomment \\n with spacing\\n--}}'
}],
tests: [
{ fragment: true, unchanged: '{{page-title}}' },
Expand Down

0 comments on commit ec7b247

Please sign in to comment.