Added some newline tests

This commit is contained in:
Liam Newman 2018-05-07 18:56:25 -07:00
parent ef7e2cdd61
commit 66383d7938
3 changed files with 135 additions and 19 deletions

View File

@ -1026,9 +1026,18 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
// -- output --
'/* header */\n' +
'.tabs {}');
t(
'/* header */\n' +
'\n' +
'.tabs {}\n',
// -- output --
'/* header */\n' +
'.tabs {}');
t(
'.tabs {\n' +
'\n' +
'/* non-header */\n' +
'\n' +
'width:10px;}',
// -- output --
'.tabs {\n' +
@ -1039,7 +1048,9 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
t('// comment');
t(
'.selector1 {\n' +
'\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n' +
'\tmargin: 0;\n' +
'\n' +
'/* This is a comment including an url http://domain.com/path/to/file.ext */\n' +
'}',
// -- output --
'.selector1 {\n' +
@ -1050,7 +1061,9 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
// single line comment support (less/sass)
t(
'.tabs{\n' +
'\n' +
'// comment\n' +
'\n' +
'width:10px;\n' +
'}',
// -- output --
@ -1123,7 +1136,7 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
//============================================================
// Comments
// Comments with preserve newlines option on
reset_options();
opts.preserve_newlines = true;
t('/* header comment newlines on */');
@ -1134,35 +1147,58 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
'\t/* test */\n' +
'}');
t(
'.tabs{/* test */}',
'.tabs{\n' +
'\n' +
'/* test */\n' +
'\n' +
'}',
// -- output --
'.tabs {\n' +
'\n' +
'\t/* test */\n' +
'\n' +
'}');
t(
'/* header */.tabs {}',
// -- output --
'/* header */\n' +
'.tabs {}');
t(
'/* header */\n' +
'\n' +
'.tabs {}\n',
// -- output --
'/* header */\n' +
'\n' +
'.tabs {}');
t(
'.tabs {\n' +
'\n' +
'/* non-header */\n' +
'\n' +
'width:10px;}',
// -- output --
'.tabs {\n' +
'\n' +
'\t/* non-header */\n' +
'\n' +
'\twidth: 10px;\n' +
'}');
t('/* header');
t('// comment');
t(
'.selector1 {\n' +
'\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n' +
'\tmargin: 0;\n' +
'\n' +
'/* This is a comment including an url http://domain.com/path/to/file.ext */\n' +
'\n' +
'}',
// -- output --
'.selector1 {\n' +
'\tmargin: 0;\n' +
'\n' +
'\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n' +
'\n' +
'}');
// single line comment support (less/sass)
@ -1238,6 +1274,18 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
'\t// comment follows rule\n' +
'\t// another comment new line\n' +
'}');
// #736
t(
'/*\n' +
' * comment\n' +
' */\n' +
'\n' +
'\n' +
'/* another comment */\n' +
'\n' +
'\n' +
'body {}');
//============================================================

View File

@ -984,9 +984,18 @@ class CSSBeautifierTest(unittest.TestCase):
# -- output --
'/* header */\n' +
'.tabs {}')
t(
'/* header */\n' +
'\n' +
'.tabs {}\n',
# -- output --
'/* header */\n' +
'.tabs {}')
t(
'.tabs {\n' +
'\n' +
'/* non-header */\n' +
'\n' +
'width:10px;}',
# -- output --
'.tabs {\n' +
@ -997,7 +1006,9 @@ class CSSBeautifierTest(unittest.TestCase):
t('// comment')
t(
'.selector1 {\n' +
'\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n' +
'\tmargin: 0;\n' +
'\n' +
'/* This is a comment including an url http://domain.com/path/to/file.ext */\n' +
'}',
# -- output --
'.selector1 {\n' +
@ -1008,7 +1019,9 @@ class CSSBeautifierTest(unittest.TestCase):
# single line comment support (less/sass)
t(
'.tabs{\n' +
'\n' +
'// comment\n' +
'\n' +
'width:10px;\n' +
'}',
# -- output --
@ -1081,7 +1094,7 @@ class CSSBeautifierTest(unittest.TestCase):
#============================================================
# Comments
# Comments with preserve newlines option on
self.reset_options();
self.options.preserve_newlines = true
t('/* header comment newlines on */')
@ -1092,35 +1105,58 @@ class CSSBeautifierTest(unittest.TestCase):
'\t/* test */\n' +
'}')
t(
'.tabs{/* test */}',
'.tabs{\n' +
'\n' +
'/* test */\n' +
'\n' +
'}',
# -- output --
'.tabs {\n' +
'\n' +
'\t/* test */\n' +
'\n' +
'}')
t(
'/* header */.tabs {}',
# -- output --
'/* header */\n' +
'.tabs {}')
t(
'/* header */\n' +
'\n' +
'.tabs {}\n',
# -- output --
'/* header */\n' +
'\n' +
'.tabs {}')
t(
'.tabs {\n' +
'\n' +
'/* non-header */\n' +
'\n' +
'width:10px;}',
# -- output --
'.tabs {\n' +
'\n' +
'\t/* non-header */\n' +
'\n' +
'\twidth: 10px;\n' +
'}')
t('/* header')
t('// comment')
t(
'.selector1 {\n' +
'\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n' +
'\tmargin: 0;\n' +
'\n' +
'/* This is a comment including an url http://domain.com/path/to/file.ext */\n' +
'\n' +
'}',
# -- output --
'.selector1 {\n' +
'\tmargin: 0;\n' +
'\n' +
'\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n' +
'\n' +
'}')
# single line comment support (less/sass)
@ -1196,6 +1232,18 @@ class CSSBeautifierTest(unittest.TestCase):
'\t// comment follows rule\n' +
'\t// another comment new line\n' +
'}')
# #736
t(
'/*\n' +
' * comment\n' +
' */\n' +
'\n' +
'\n' +
'/* another comment */\n' +
'\n' +
'\n' +
'body {}')
#============================================================

View File

@ -305,16 +305,18 @@ exports.test_data = {
{ input: '.tabs{/* test */}', output: '.tabs {\n\t/* test */\n}' },
{ input: '.tabs{/* test */}', output: '.tabs {\n\t/* test */\n}' },
{ input: '/* header */.tabs {}', output: '/* header */\n.tabs {}' },
{ input: '.tabs {\n/* non-header */\nwidth:10px;}', output: '.tabs {\n\t/* non-header */\n\twidth: 10px;\n}' },
{ input: '/* header */\n\n.tabs {}\n', output: '/* header */\n.tabs {}' },
{ input: '.tabs {\n\n/* non-header */\n\nwidth:10px;}', output: '.tabs {\n\t/* non-header */\n\twidth: 10px;\n}' },
{ unchanged: '/* header' },
{ unchanged: '// comment' }, {
input: '.selector1 {\n\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n}',
{ unchanged: '// comment' },
{
input: '.selector1 {\n\tmargin: 0;\n\n/* This is a comment including an url http://domain.com/path/to/file.ext */\n}',
output: '.selector1 {\n\tmargin: 0;\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n}'
},
{
comment: "single line comment support (less/sass)",
input: '.tabs{\n// comment\nwidth:10px;\n}',
input: '.tabs{\n\n// comment\n\nwidth:10px;\n}',
output: '.tabs {\n\t// comment\n\twidth: 10px;\n}'
},
{ input: '.tabs{// comment\nwidth:10px;\n}', output: '.tabs {\n\t// comment\n\twidth: 10px;\n}' },
@ -330,7 +332,7 @@ exports.test_data = {
],
},
{
name: "Comments",
name: "Comments with preserve newlines option on",
description: "With preserve newlines option on",
options: [
{ name: "preserve_newlines", value: "true" }
@ -338,13 +340,15 @@ exports.test_data = {
tests: [
{ unchanged: '/* header comment newlines on */' },
{ input: '.tabs{/* test */}', output: '.tabs {\n\t/* test */\n}' },
{ input: '.tabs{/* test */}', output: '.tabs {\n\t/* test */\n}' },
{ input: '.tabs{\n\n/* test */\n\n}', output: '.tabs {\n\n\t/* test */\n\n}' },
{ input: '/* header */.tabs {}', output: '/* header */\n.tabs {}' },
{ input: '.tabs {\n/* non-header */\nwidth:10px;}', output: '.tabs {\n\t/* non-header */\n\twidth: 10px;\n}' },
{ input: '/* header */\n\n.tabs {}\n', output: '/* header */\n\n.tabs {}' },
{ input: '.tabs {\n\n/* non-header */\n\nwidth:10px;}', output: '.tabs {\n\n\t/* non-header */\n\n\twidth: 10px;\n}' },
{ unchanged: '/* header' },
{ unchanged: '// comment' }, {
input: '.selector1 {\n\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n}',
output: '.selector1 {\n\tmargin: 0;\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n}'
{ unchanged: '// comment' },
{
input: '.selector1 {\n\tmargin: 0;\n\n/* This is a comment including an url http://domain.com/path/to/file.ext */\n\n}',
output: '.selector1 {\n\tmargin: 0;\n\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n\n}'
},
{
@ -361,7 +365,23 @@ exports.test_data = {
{
input: '.tabs{width: 10px;\n// comment follows rule\n// another comment new line\n}',
output: '.tabs {\n\twidth: 10px;\n\t// comment follows rule\n\t// another comment new line\n}'
}
},
{
comment: "#736",
unchanged: [
'/*',
' * comment',
' */',
'',
'',
'/* another comment */',
'',
'',
'body {}'
]
},
],
},
{