forked from jdavisclark/JsFormat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fixes jdavisclark#71 and jdavisclark#59
- Loading branch information
1 parent
5622eb5
commit b6fa9e0
Showing
28 changed files
with
1,876 additions
and
1,129 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,116 @@ | |
class CSSBeautifierTest(unittest.TestCase): | ||
|
||
def resetOptions(self): | ||
self.options = cssbeautifier.default_options() | ||
self.options.indent_size = 1 | ||
self.options.indent_char = '\t' | ||
self.options.selector_separator_newline = True | ||
self.options.end_with_newline = False | ||
false = False | ||
true = True | ||
self.options = cssbeautifier.default_options() | ||
self.options.indent_size = 1 | ||
self.options.indent_char = '\t' | ||
self.options.selector_separator_newline = true | ||
self.options.end_with_newline = false | ||
self.options.newline_between_rules = false | ||
|
||
def testGenerated(self): | ||
self.resetOptions() | ||
test_fragment = self.decodesto | ||
t = self.decodesto | ||
|
||
false = False | ||
true = True | ||
|
||
self.options.indent_size = 1 | ||
self.options.indent_char = '\t' | ||
self.options.selector_separator_newline = true | ||
self.options.end_with_newline = false | ||
self.options.newline_between_rules = false | ||
|
||
# End With Newline - (eof = "\n") | ||
self.options.end_with_newline = true | ||
test_fragment('', '\n') | ||
test_fragment(' .tabs{}', ' .tabs {}\n') | ||
test_fragment(' \n\n.tabs{}\n\n\n\n', ' .tabs {}\n') | ||
test_fragment('\n') | ||
|
||
# End With Newline - (eof = "") | ||
self.options.end_with_newline = false | ||
test_fragment('') | ||
test_fragment(' .tabs{}', ' .tabs {}') | ||
test_fragment(' \n\n.tabs{}\n\n\n\n', ' .tabs {}') | ||
test_fragment('\n', '') | ||
|
||
# Empty braces | ||
t('.tabs{}', '.tabs {}') | ||
t('.tabs { }', '.tabs {}') | ||
t('.tabs { }', '.tabs {}') | ||
t('.tabs \n{\n \n }', '.tabs {}') | ||
|
||
# | ||
t('#cboxOverlay {\n\tbackground: url(images/overlay.png) repeat 0 0;\n\topacity: 0.9;\n\tfilter: alpha(opacity = 90);\n}', '#cboxOverlay {\n\tbackground: url(images/overlay.png) repeat 0 0;\n\topacity: 0.9;\n\tfilter: alpha(opacity=90);\n}') | ||
|
||
# Newline Between Rules - (separator = "\n") | ||
self.options.newline_between_rules = true | ||
t('.div {}\n.span {}', '.div {}\n\n.span {}') | ||
t('.div{}\n \n.span{}', '.div {}\n\n.span {}') | ||
t('.div {} \n \n.span { } \n', '.div {}\n\n.span {}') | ||
t('.div {\n \n} \n .span {\n } ', '.div {}\n\n.span {}') | ||
t('.selector1 {\n\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n}\n.div{height:15px;}', '.selector1 {\n\tmargin: 0;\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n}\n\n.div {\n\theight: 15px;\n}') | ||
t('.tabs{width:10px;//end of line comment\nheight:10px;//another\n}\n.div{height:15px;}', '.tabs {\n\twidth: 10px; //end of line comment\n\theight: 10px; //another\n}\n\n.div {\n\theight: 15px;\n}') | ||
t('#foo {\n\tbackground-image: url([email protected]);\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div{height:15px;}', '#foo {\n\tbackground-image: url([email protected]);\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n\n.div {\n\theight: 15px;\n}') | ||
t('@media screen {\n\t#foo:hover {\n\t\tbackground-image: url([email protected]);\n\t}\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div{height:15px;}', '@media screen {\n\t#foo:hover {\n\t\tbackground-image: url([email protected]);\n\t}\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n\n.div {\n\theight: 15px;\n}') | ||
t('@font-face {\n\tfont-family: "Bitstream Vera Serif Bold";\n\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n}\n@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo.png);\n\t}\n\t@media screen and (min-device-pixel-ratio: 2) {\n\t\t@font-face {\n\t\t\tfont-family: "Helvetica Neue"\n\t\t}\n\t\t#foo:hover {\n\t\t\tbackground-image: url([email protected]);\n\t\t}\n\t}\n}', '@font-face {\n\tfont-family: "Bitstream Vera Serif Bold";\n\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n}\n\n@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo.png);\n\t}\n\t@media screen and (min-device-pixel-ratio: 2) {\n\t\t@font-face {\n\t\t\tfont-family: "Helvetica Neue"\n\t\t}\n\t\t#foo:hover {\n\t\t\tbackground-image: url([email protected]);\n\t\t}\n\t}\n}') | ||
t('a:first-child{color:red;div:first-child{color:black;}}\n.div{height:15px;}', 'a:first-child {\n\tcolor: red;\n\tdiv:first-child {\n\t\tcolor: black;\n\t}\n}\n\n.div {\n\theight: 15px;\n}') | ||
|
||
# Newline Between Rules - (separator = "") | ||
self.options.newline_between_rules = false | ||
t('.div {}\n.span {}') | ||
t('.div{}\n \n.span{}', '.div {}\n.span {}') | ||
t('.div {} \n \n.span { } \n', '.div {}\n.span {}') | ||
t('.div {\n \n} \n .span {\n } ', '.div {}\n.span {}') | ||
t('.selector1 {\n\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n}\n.div{height:15px;}', '.selector1 {\n\tmargin: 0;\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n}\n.div {\n\theight: 15px;\n}') | ||
t('.tabs{width:10px;//end of line comment\nheight:10px;//another\n}\n.div{height:15px;}', '.tabs {\n\twidth: 10px; //end of line comment\n\theight: 10px; //another\n}\n.div {\n\theight: 15px;\n}') | ||
t('#foo {\n\tbackground-image: url([email protected]);\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div{height:15px;}', '#foo {\n\tbackground-image: url([email protected]);\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div {\n\theight: 15px;\n}') | ||
t('@media screen {\n\t#foo:hover {\n\t\tbackground-image: url([email protected]);\n\t}\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div{height:15px;}', '@media screen {\n\t#foo:hover {\n\t\tbackground-image: url([email protected]);\n\t}\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div {\n\theight: 15px;\n}') | ||
t('@font-face {\n\tfont-family: "Bitstream Vera Serif Bold";\n\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n}\n@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo.png);\n\t}\n\t@media screen and (min-device-pixel-ratio: 2) {\n\t\t@font-face {\n\t\t\tfont-family: "Helvetica Neue"\n\t\t}\n\t\t#foo:hover {\n\t\t\tbackground-image: url([email protected]);\n\t\t}\n\t}\n}') | ||
t('a:first-child{color:red;div:first-child{color:black;}}\n.div{height:15px;}', 'a:first-child {\n\tcolor: red;\n\tdiv:first-child {\n\t\tcolor: black;\n\t}\n}\n.div {\n\theight: 15px;\n}') | ||
|
||
# Functions braces | ||
t('.tabs(){}', '.tabs() {}') | ||
t('.tabs (){}', '.tabs () {}') | ||
t('.tabs (pa, pa(1,2)), .cols { }', '.tabs (pa, pa(1, 2)),\n.cols {}') | ||
t('.tabs(pa, pa(1,2)), .cols { }', '.tabs(pa, pa(1, 2)),\n.cols {}') | ||
t('.tabs ( ) { }', '.tabs () {}') | ||
t('.tabs( ) { }', '.tabs() {}') | ||
t('.tabs (t, t2) \n{\n key: val(p1 ,p2); \n }', '.tabs (t, t2) {\n\tkey: val(p1, p2);\n}') | ||
t('.box-shadow(@shadow: 0 1px 3px rgba(0, 0, 0, .25)) {\n\t-webkit-box-shadow: @shadow;\n\t-moz-box-shadow: @shadow;\n\tbox-shadow: @shadow;\n}') | ||
|
||
# Comments | ||
t('/* test */') | ||
t('.tabs{/* test */}', '.tabs {\n\t/* test */\n}') | ||
t('.tabs{/* test */}', '.tabs {\n\t/* test */\n}') | ||
t('/* header */.tabs {}', '/* header */\n\n.tabs {}') | ||
t('.tabs {\n/* non-header */\nwidth:10px;}', '.tabs {\n\t/* non-header */\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}', '.selector1 {\n\tmargin: 0;\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n}') | ||
|
||
# single line comment support (less/sass) | ||
t('.tabs{\n// comment\nwidth:10px;\n}', '.tabs {\n\t// comment\n\twidth: 10px;\n}') | ||
t('.tabs{// comment\nwidth:10px;\n}', '.tabs {\n\t// comment\n\twidth: 10px;\n}') | ||
t('//comment\n.tabs{width:10px;}', '//comment\n.tabs {\n\twidth: 10px;\n}') | ||
t('.tabs{//comment\n//2nd single line comment\nwidth:10px;}', '.tabs {\n\t//comment\n\t//2nd single line comment\n\twidth: 10px;\n}') | ||
t('.tabs{width:10px;//end of line comment\n}', '.tabs {\n\twidth: 10px; //end of line comment\n}') | ||
t('.tabs{width:10px;//end of line comment\nheight:10px;}', '.tabs {\n\twidth: 10px; //end of line comment\n\theight: 10px;\n}') | ||
t('.tabs{width:10px;//end of line comment\nheight:10px;//another\n}', '.tabs {\n\twidth: 10px; //end of line comment\n\theight: 10px; //another\n}') | ||
|
||
# Psuedo-classes vs Variables | ||
t('@page :first {}') | ||
|
||
# Assume the colon goes with the @name. If we're in LESS, this is required regardless of the at-string. | ||
t('@page:first {}', '@page: first {}') | ||
t('@page: first {}') | ||
|
||
# | ||
|
||
|
||
def testNewline(self): | ||
self.resetOptions() | ||
|
@@ -51,30 +156,6 @@ def testBasics(self): | |
t(" \t \na, img {padding: 0.2px}", " \t a,\n \t img {\n \t \tpadding: 0.2px\n \t }") | ||
t("\n\n a, img {padding: 0.2px}", "a,\nimg {\n\tpadding: 0.2px\n}") | ||
|
||
|
||
def testComments(self): | ||
self.resetOptions() | ||
t = self.decodesto | ||
|
||
t("/* test */", "/* test */") | ||
t(".tabs{/* test */}", ".tabs {\n\t/* test */\n}") | ||
t("/* header */.tabs {}", "/* header */\n\n.tabs {}") | ||
t("/* header", "/* header"); | ||
t("// comment", "// comment"); | ||
t(".selector1 {\n\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n}", | ||
".selector1 {\n\tmargin: 0;\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n}") | ||
|
||
#single line comment support (less/sass) | ||
t(".tabs{\n// comment\nwidth:10px;\n}", ".tabs {\n\t// comment\n\twidth: 10px;\n}") | ||
t(".tabs{// comment\nwidth:10px;\n}", ".tabs {\n\t// comment\n\twidth: 10px;\n}") | ||
t("//comment\n.tabs{width:10px;}", "//comment\n.tabs {\n\twidth: 10px;\n}") | ||
t(".tabs{//comment\n//2nd single line comment\nwidth:10px;}", ".tabs {\n\t//comment\n\t//2nd single line comment\n\twidth: 10px;\n}") | ||
t(".tabs{width:10px;//end of line comment\n}", ".tabs {\n\twidth: 10px; //end of line comment\n}") | ||
t(".tabs{width:10px;//end of line comment\nheight:10px;}", ".tabs {\n\twidth: 10px; //end of line comment\n\theight: 10px;\n}") | ||
t(".tabs{width:10px;//end of line comment\nheight:10px;//another\n}", ".tabs {\n\twidth: 10px; //end of line comment\n\theight: 10px; //another\n}") | ||
|
||
|
||
|
||
def testSeperateSelectors(self): | ||
self.resetOptions() | ||
t = self.decodesto | ||
|
Oops, something went wrong.