https://bugs.webkit.org/show_bug.cgi?id=134005
Patch by Joseph Pecoraro <pecoraro@apple.com> on 2014-10-04
Reviewed by Timothy Hatcher.
Add CSS pretty printing tests. Improve pretty printing of calc()
expressions and media-queries with whitespace around operators
and keywords. Also fix the debug output in the tool for CSS.
* Tools/PrettyPrinting/CodeMirrorFormatters.js:
* Tools/PrettyPrinting/FormatterContentBuilder.js:
(FormatterContentBuilder.prototype._appendIndent):
* Tools/PrettyPrinting/FormatterDebug.js:
(.debugToken):
(Formatter.prototype.debug):
* Tools/PrettyPrinting/css-tests/basic-expected.css: Added.
* Tools/PrettyPrinting/css-tests/basic.css: Added.
* Tools/PrettyPrinting/css-tests/calc-expected.css: Added.
* Tools/PrettyPrinting/css-tests/calc.css: Added.
* Tools/PrettyPrinting/css-tests/media-query-expected.css: Added.
* Tools/PrettyPrinting/css-tests/media-query.css: Added.
* Tools/PrettyPrinting/css-tests/selectors-expected.css: Added.
* Tools/PrettyPrinting/css-tests/selectors.css: Added.
* Tools/PrettyPrinting/index.html:
* UserInterface/Views/CodeMirrorFormatters.js:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174323
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2014-10-04 Joseph Pecoraro <pecoraro@apple.com>
+
+ Web Inspector: Add PrettyPrinter CSS tests
+ https://bugs.webkit.org/show_bug.cgi?id=134005
+
+ Reviewed by Timothy Hatcher.
+
+ Add CSS pretty printing tests. Improve pretty printing of calc()
+ expressions and media-queries with whitespace around operators
+ and keywords. Also fix the debug output in the tool for CSS.
+
+ * Tools/PrettyPrinting/CodeMirrorFormatters.js:
+ * Tools/PrettyPrinting/FormatterContentBuilder.js:
+ (FormatterContentBuilder.prototype._appendIndent):
+ * Tools/PrettyPrinting/FormatterDebug.js:
+ (.debugToken):
+ (Formatter.prototype.debug):
+ * Tools/PrettyPrinting/css-tests/basic-expected.css: Added.
+ * Tools/PrettyPrinting/css-tests/basic.css: Added.
+ * Tools/PrettyPrinting/css-tests/calc-expected.css: Added.
+ * Tools/PrettyPrinting/css-tests/calc.css: Added.
+ * Tools/PrettyPrinting/css-tests/media-query-expected.css: Added.
+ * Tools/PrettyPrinting/css-tests/media-query.css: Added.
+ * Tools/PrettyPrinting/css-tests/selectors-expected.css: Added.
+ * Tools/PrettyPrinting/css-tests/selectors.css: Added.
+ * Tools/PrettyPrinting/index.html:
+ * UserInterface/Views/CodeMirrorFormatters.js:
+
2014-10-04 Brian J. Burg <burg@cs.washington.edu>
Unreviewed, rolling out r174319.
if (!token) {
if (content === "{")
return true;
- return false;
+ return ">+~-*/".indexOf(content) >= 0; // calc() expression or child/sibling selectors
}
if (isComment)
return true;
if (lastContent === ":") // Space in "prop: value" but not in a selectors "a:link" or "div::after" or media queries "(max-device-width:480px)".
return state.state === "prop";
- return false;
+ if (lastContent === ")" && (content !== ")" && content !== ",")) // Space in "not(foo)and" but not at the end of "not(not(foo))"
+ return state.state === "media" || state.state === "media_parens";
+ return ">+~-*/".indexOf(lastContent) >= 0; // calc() expression or child/sibling selectors
}
if (/\bcomment\b/.test(lastToken))
return true;
+ if (/\bkeyword\b/.test(lastToken)) // media-query keywords
+ return state.state === "media" || state.state === "media_parens";
+
return false;
},
const maxCacheIndent = 20;
var max = Math.min(this._indent, maxCacheIndent);
for (var i = this._indentCache.length; i <= max; ++i)
- this._indentCache[i] = this._indentCache[i-1] + this._indentString;
+ this._indentCache[i] = this._indentCache[i - 1] + this._indentString;
// Append indents as needed.
var indent = this._indent;
// Language Specific Info
if (state.lexical) {
+ // JavaScript
debug += "Lexical: " + pad(String(state.lexical.type), 10); // JavaScript
debug += "Prev: " + pad(String(state.lexical.prev ? state.lexical.prev.type : state.lexical.prev), 10, !state.lexical.prev);
+ } else if (state.state) {
+ // CSS
+ debug += "State: " + pad(String(state.state), 16);
}
- else if (state.stack)
- debug += "Stack: " + pad(String(state.stack[state.stack.length-1]), 16); // CSS
// String
debug += "Current: '" + stream.current() + "'\n";
--- /dev/null
+/* RESET */
+html, body, div, ul, ol, li, dl, dt, dd, h1, h2, h3, h4, h5, h6,
+pre, form, p, blockquote, fieldset, input, abbr, article, aside, command,
+details, figcaption, figure, footer, header, hgroup, mark, meter, nav,
+output, progress, section, summary, time {
+ margin: 0;
+ padding: 0;
+}
+
+h1, h2, h3, h4, h5, h6, pre, code, address, caption, cite, code, em, strong,
+th, figcaption {
+ font-size: 1em;
+ font-weight: normal;
+ font-style: normal;
+}
+
+fieldset, iframe {
+ border: none
+}
+
+table {
+ border-collapse: collapse;
+ border-spacing: 0
+}
+
+article, aside, footer, header, hgroup, nav, section, figure, figcaption {
+ display: block;
+}
+
+/* FIXME: extra whitespace */
+caption , th {
+ text-align: left;
+}
+
+/* IMPORTANT */
+/* FIXME: whitespace between "!" and "important" can be improved */
+body {
+ color: red !important;
+}
+
+body {
+ color: red !important;
+}
+
+body {
+ color: red ! important;
+}
+
+/* INLINE COMMENT */
+body {
+ color: red; /* blue */
+}
+
+/* URLS */
+.myimage {
+ background-image: url(http://example.com/image.png), url(two.png)
+}
+
+.myimage {
+ background-image: url("http://example.com/image.png"), url("two.png")
+}
+
+/* PREFIXED SELECTORS AND PROPERTIES */
+.foo -webkit-any(a, b, c) {
+ -webkit-transition: all;
+ color: red
+}
+
+/* PSEUDO SELECTORS */
+a:link, a:visited {
+ color: black
+}
+
+/* PSEUDO ELEMENTS */
+p::before, p::after {
+ content: "test";
+}
+
+/* RGB, HSL */
+body {
+ color: rgb(1, 1, 1);
+ color: rgba(100, 0, 255, 0.5);
+ color: hsl(120, 100%, 50%);
+ color: hsla(120, 60%, 70%, 0.3);
+}
+
+/*
+ * This is a multi-line comment.
+ * - with indentation
+ * - and is generally awesome.
+ */
+body {
+ color: red
+}
+
--- /dev/null
+/* RESET */
+html,body,div,ul,ol,li,dl,dt,dd,h1,h2,h3,h4,h5,h6,pre,form,p,blockquote,fieldset,input,abbr,article,aside,command,details,figcaption,figure,footer,header,hgroup,mark,meter,nav,output,progress,section,summary,time { margin: 0; padding: 0; }
+h1,h2,h3,h4,h5,h6,pre,code,address,caption,cite,code,em,strong,th,figcaption { font-size: 1em; font-weight: normal; font-style: normal; }
+fieldset,iframe{border:none}
+table{border-collapse:collapse;border-spacing:0}
+article,aside,footer,header,hgroup,nav,section,figure,figcaption{display: block;}
+
+/* FIXME: extra whitespace */
+caption , th { text-align: left; }
+
+/* IMPORTANT */
+/* FIXME: whitespace between "!" and "important" can be improved */
+body{color:red!important;}
+body{color:red !important;}
+body{color:red ! important;}
+
+/* INLINE COMMENT */
+body{color:red;/* blue */}
+
+/* URLS */
+.myimage{background-image:url(http://example.com/image.png),url(two.png)}
+.myimage{background-image:url("http://example.com/image.png"),url("two.png")}
+
+/* PREFIXED SELECTORS AND PROPERTIES */
+.foo -webkit-any(a,b,c){-webkit-transition:all;color:red}
+
+/* PSEUDO SELECTORS */
+a:link,a:visited{color:black}
+
+/* PSEUDO ELEMENTS */
+p::before,p::after{content:"test";}
+
+/* RGB, HSL */
+body{color:rgb(1,1,1);color:rgba(100,0,255,0.5);color:hsl(120,100%,50%);color:hsla(120,60%,70%,0.3);}
+
+/*
+ * This is a multi-line comment.
+ * - with indentation
+ * - and is generally awesome.
+ */
+body{color:red}
--- /dev/null
+/* CALC EXPRESSIONS */
+/* FIXME: negative numbers can be improved */
+div {
+ width: -webkit-calc(100% + 80px + 1em);
+}
+
+div {
+ width: -webkit-calc(100% / 6);
+}
+
+div {
+ width: -webkit-calc(10% * 6);
+}
+
+div {
+ width: calc(-960px + 75%);
+}
+
+div {
+ width: calc(100vw-50vw);
+}
+
--- /dev/null
+/* CALC EXPRESSIONS */
+/* FIXME: negative numbers can be improved */
+div{width:-webkit-calc(100%+80px+1em);}
+div{width:-webkit-calc(100%/6);}
+div{width:-webkit-calc(10%*6);}
+div{width:calc(-960px+75%);}
+div{width:calc(100vw-50vw);}
--- /dev/null
+/* MEDIA QUERY INDENTATION */
+@media print {
+ body, #main, #content {
+ color: #000 !important;
+ }
+
+ a, a:link, a:visited {
+ color: #000 !important;
+ text-decoration: none !important;
+ }
+
+ #tabs, #globalheader, #globalfooter, #directorynav, .noprint, .hide {
+ display: none !important;
+ }
+
+ #main a.pdf, #main a.html, #main a.qt, #main a.ical, #main a.dl, #main a.dmg,
+ #main a.zip, #main a.keynote, #main a.audio {
+ padding-left: 0;
+ background-image: none;
+ }
+}
+
+/* MEDIA QUERY */
+@media screen and (max-device-width:480px) {
+ html {
+ -webkit-text-size-adjust: none;
+ }
+}
+
+@media not ((screen) and (print)), (print) {
+ body {
+ color: red
+ }
+}
+
--- /dev/null
+/* MEDIA QUERY INDENTATION */
+@media print{body,#main,#content{color:#000!important;}a,a:link,a:visited{color:#000!important;text-decoration:none!important;}#tabs,#globalheader,#globalfooter,#directorynav,.noprint,.hide{display:none!important;}#main a.pdf,#main a.html,#main a.qt,#main a.ical,#main a.dl,#main a.dmg,#main a.zip,#main a.keynote,#main a.audio{padding-left:0;background-image:none;}}
+
+/* MEDIA QUERY */
+@media screen and(max-device-width:480px){html{-webkit-text-size-adjust:none;}}
+@media not((screen)and(print)),(print){body{color:red}}
--- /dev/null
+/* SHORT SELECTOR, EMPTY CONTENT */
+a {}
+
+/* COMPLEX SELECTOR */
+div div > div#id.foo.bar:hover .something > .child ~ .sibling + .sibling::after {
+ color: red;
+}
+
--- /dev/null
+/* SHORT SELECTOR, EMPTY CONTENT */
+a{}
+
+/* COMPLEX SELECTOR */
+div div>div#id.foo.bar:hover .something>.child~.sibling+.sibling::after{color:red;}
// Button helpers.
var buttons = ["mode", "populate", "run-tests", "clear", "select-output", "run-again"];
function disableButtons() {
- console.log("disableButtons");
buttons.forEach(function(id) {
document.getElementById(id).disabled = true;
});
}
function enableButtons() {
- console.log("enableButtons");
buttons.forEach(function(id) {
document.getElementById(id).disabled = false;
});
]);
}
function runCSSTests(callback) {
- _runTests(callback, []);
+ _runTests(callback, [
+ "css-tests/basic.css",
+ "css-tests/calc.css",
+ "css-tests/media-query.css",
+ "css-tests/selectors.css",
+ ]);
}
function _runTests(callback, manifest) {
var index = -1;
// Load test and expected results.
var test = manifest[index];
- var expected = test.replace(/\.js$/, "-expected.js");
+ var expected = test.replace(/\.([^\.]+)$/, "-expected.$1");
var xhr1 = new XMLHttpRequest;
xhr1.open("GET", test, false);
xhr1.send();
// Compare results.
var pass = builder.formattedContent === expectedData;
results.push("/* " + (pass ? "PASS" : "FAIL") + ": " + test + " */");
+
+ // Output failures to console.
+ if (!pass) {
+ console.log("Test", test, "Expected", expected);
+ console.log("Formatted Output", builder.formattedContent.length);
+ console.log(builder.formattedContent);
+ console.log("Expected Output", expectedData.length);
+ console.log(expectedData);
+ }
+
runNextTest();
}
if (!token) {
if (content === "{")
return true;
- return false;
+ return ">+~-*/".indexOf(content) >= 0; // calc() expression or child/sibling selectors
}
if (isComment)
return true;
if (lastContent === ":") // Space in "prop: value" but not in a selectors "a:link" or "div::after" or media queries "(max-device-width:480px)".
return state.state === "prop";
- return false;
+ if (lastContent === ")" && (content !== ")" && content !== ",")) // Space in "not(foo)and" but not at the end of "not(not(foo))"
+ return state.state === "media" || state.state === "media_parens";
+ return ">+~-*/".indexOf(lastContent) >= 0; // calc() expression or child/sibling selectors
}
if (/\bcomment\b/.test(lastToken))
return true;
+ if (/\bkeyword\b/.test(lastToken)) // media-query keywords
+ return state.state === "media" || state.state === "media_parens";
+
return false;
},