diff --git a/CHANGELOG.md b/CHANGELOG.md index dd795cbba2..5e0fec2d06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,40 @@ # Prism Changelog +## 1.2.0 (2015-10-07) + +### New components + +* __Batch__ ([#781](https://github.com/PrismJS/prism/issues/781)) [[`eab5b06`](https://github.com/PrismJS/prism/commit/eab5b06)] + +### Updated components + +* __ASP.NET__: + * Simplified pattern for ` + + + + + + +
+
+ +

Previewer: Gradient

+

Previewer for CSS gradients.

+
+ +
+

How to use

+ +

You don't need to do anything. With this plugin loaded, a previewer will appear on hovering the gradient values in code blocks.

+

Vendor-prefixed gradients are converted to W3C-valid ones, except the old Webkit syntax (-webkit-gradient(linear, ...) and -webkit-gradient(radial, ...)) is not supported.

+

This plugin is compatible with CSS, Less, Sass, Scss and Stylus.

+
+ +
+

Examples

+ +

CSS

+
div {
+	background: -moz-linear-gradient(left,  #cb60b3 0%, #c146a1 50%, #a80077 51%, #db36a4 100%); /* FF3.6+ */
+	background: -webkit-linear-gradient(left,  #cb60b3 0%,#c146a1 50%,#a80077 51%,#db36a4 100%); /* Chrome10+,Safari5.1+ */
+	background: -o-linear-gradient(left,  #cb60b3 0%,#c146a1 50%,#a80077 51%,#db36a4 100%); /* Opera 11.10+ */
+	background: -ms-linear-gradient(left,  #cb60b3 0%,#c146a1 50%,#a80077 51%,#db36a4 100%); /* IE10+ */
+	background: linear-gradient(to right,  #cb60b3 0%,#c146a1 50%,#a80077 51%,#db36a4 100%); /* W3C */
+}
+ +

Less

+
@gradient: linear-gradient(135deg,  #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%);
+#header a {
+	background: -moz-linear-gradient(-45deg,  #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* FF3.6+ */
+	background: -webkit-linear-gradient(-45deg,  #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Chrome10+,Safari5.1+ */
+	background: -o-linear-gradient(-45deg,  #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Opera 11.10+ */
+	background: -ms-linear-gradient(-45deg,  #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* IE10+ */
+	background: linear-gradient(135deg,  #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* W3C */
+}
+ +

Sass

+
$gradient: linear-gradient(135deg,  #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%)
+@mixin foobar
+	background: -moz-radial-gradient(center, ellipse cover,  #f2f6f8 0%, #d8e1e7 50%, #b5c6d0 51%, #e0eff9 100%)
+	background: radial-gradient(ellipse at center,  #f2f6f8 0%,#d8e1e7 50%,#b5c6d0 51%,#e0eff9 100%)
+
+ +

Scss

+
$gradient: linear-gradient(135deg,  #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%);
+$attr: background;
+.foo {
+    #{$attr}-image: repeating-linear-gradient(10deg, rgba(255,0,0,0), rgba(255,0,0,1) 10px, rgba(255,0,0,0) 20px);
+}
+ +

Stylus

+
gradient = linear-gradient(135deg,  #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%)
+.foo
+	background-image: repeating-radial-gradient(circle, rgba(255,0,0,0), rgba(255,0,0,1) 10px, rgba(255,0,0,0) 20px)
+
+ +
+ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/previewer-gradient/prism-previewer-gradient.css b/plugins/previewer-gradient/prism-previewer-gradient.css new file mode 100644 index 0000000000..6152a6ef41 --- /dev/null +++ b/plugins/previewer-gradient/prism-previewer-gradient.css @@ -0,0 +1,27 @@ +.prism-previewer-gradient { + background-image: linear-gradient(45deg, #bbb 25%, transparent 25%, transparent 75%, #bbb 75%, #bbb), linear-gradient(45deg, #bbb 25%, #eee 25%, #eee 75%, #bbb 75%, #bbb); + background-size: 10px 10px; + background-position: 0 0, 5px 5px; + + width: 64px; + margin-left: -32px; +} +.prism-previewer-gradient:before { + content: none; +} +.prism-previewer-gradient div { + position: absolute; + top: -5px; + left: -5px; + right: -5px; + bottom: -5px; + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + border-radius: 10px; + border: 5px solid #fff; + -webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.5) inset, 0 0 10px rgba(0, 0, 0, 0.75); + -moz-box-shadow: 0 0 3px rgba(0, 0, 0, 0.5) inset, 0 0 10px rgba(0, 0, 0, 0.75); + -ms-box-shadow: 0 0 3px rgba(0, 0, 0, 0.5) inset, 0 0 10px rgba(0, 0, 0, 0.75); + -o-box-shadow: 0 0 3px rgba(0, 0, 0, 0.5) inset, 0 0 10px rgba(0, 0, 0, 0.75); + box-shadow: 0 0 3px rgba(0, 0, 0, 0.5) inset, 0 0 10px rgba(0, 0, 0, 0.75); +} \ No newline at end of file diff --git a/plugins/previewer-gradient/prism-previewer-gradient.js b/plugins/previewer-gradient/prism-previewer-gradient.js new file mode 100644 index 0000000000..11c2d0619e --- /dev/null +++ b/plugins/previewer-gradient/prism-previewer-gradient.js @@ -0,0 +1,216 @@ +(function() { + + if ( + typeof self !== 'undefined' && !self.Prism || + typeof global !== 'undefined' && !global.Prism + ) { + return; + } + + var languages = { + 'css': true, + 'less': true, + 'sass': [ + { + lang: 'sass', + before: 'punctuation', + inside: 'inside', + root: Prism.languages.sass && Prism.languages.sass['variable-line'] + }, + { + lang: 'sass', + before: 'punctuation', + inside: 'inside', + root: Prism.languages.sass && Prism.languages.sass['property-line'] + } + ], + 'scss': true, + 'stylus': [ + { + lang: 'stylus', + before: 'func', + inside: 'rest', + root: Prism.languages.stylus && Prism.languages.stylus['property-declaration'].inside + }, + { + lang: 'stylus', + before: 'func', + inside: 'rest', + root: Prism.languages.stylus && Prism.languages.stylus['variable-declaration'].inside + } + ] + }; + + Prism.hooks.add('before-highlight', function (env) { + if (env.language && languages[env.language] && !languages[env.language].initialized) { + var lang = languages[env.language]; + if (Prism.util.type(lang) !== 'Array') { + lang = [lang]; + } + lang.forEach(function(lang) { + var before, inside, root, skip; + if (lang === true) { + // Insert before color previewer if it exists + before = Prism.plugins.Previewer && Prism.plugins.Previewer.byType['color'] ? 'color' : 'important'; + inside = env.language; + lang = env.language; + } else { + before = lang.before || 'important'; + inside = lang.inside || lang.lang; + root = lang.root || Prism.languages; + skip = lang.skip; + lang = env.language; + } + + if (!skip && Prism.languages[lang]) { + Prism.languages.insertBefore(inside, before, { + 'gradient': { + pattern: /(?:\b|\B-[a-z]{1,10}-)(?:repeating-)?(?:linear|radial)-gradient\((?:(?:rgb|hsl)a?\(.+?\)|[^\)])+\)/gi, + inside: { + 'function': /[\w-]+(?=\()/, + 'punctuation': /[(),]/ + } + } + }, root); + env.grammar = Prism.languages[lang]; + + languages[env.language] = {initialized: true}; + } + }); + } + }); + + // Stores already processed gradients so that we don't + // make the conversion every time the previewer is shown + var cache = {}; + + /** + * Returns a W3C-valid linear gradient + * @param {string} prefix Vendor prefix if any ("-moz-", "-webkit-", etc.) + * @param {string} func Gradient function name ("linear-gradient") + * @param {string[]} values Array of the gradient function parameters (["0deg", "red 0%", "blue 100%"]) + */ + var convertToW3CLinearGradient = function(prefix, func, values) { + // Default value for angle + var angle = '180deg'; + + if (/^(?:-?\d*\.?\d+(?:deg|rad)|to\b|top|right|bottom|left)/.test(values[0])) { + angle = values.shift(); + if (angle.indexOf('to ') < 0) { + // Angle uses old keywords + // W3C syntax uses "to" + opposite keywords + if (angle.indexOf('top') >= 0) { + if (angle.indexOf('left') >= 0) { + angle = 'to bottom right'; + } else if (angle.indexOf('right') >= 0) { + angle = 'to bottom left'; + } else { + angle = 'to bottom'; + } + } else if (angle.indexOf('bottom') >= 0) { + if (angle.indexOf('left') >= 0) { + angle = 'to top right'; + } else if (angle.indexOf('right') >= 0) { + angle = 'to top left'; + } else { + angle = 'to top'; + } + } else if (angle.indexOf('left') >= 0) { + angle = 'to right'; + } else if (angle.indexOf('right') >= 0) { + angle = 'to left'; + } else if (prefix) { + // Angle is shifted by 90deg in prefixed gradients + if (angle.indexOf('deg') >= 0) { + angle = (90 - parseFloat(angle)) + 'deg'; + } else if (angle.indexOf('rad') >= 0) { + angle = (Math.PI / 2 - parseFloat(angle)) + 'rad'; + } + } + } + } + + return func + '(' + angle + ',' + values.join(',') + ')'; + }; + + /** + * Returns a W3C-valid radial gradient + * @param {string} prefix Vendor prefix if any ("-moz-", "-webkit-", etc.) + * @param {string} func Gradient function name ("linear-gradient") + * @param {string[]} values Array of the gradient function parameters (["0deg", "red 0%", "blue 100%"]) + */ + var convertToW3CRadialGradient = function(prefix, func, values) { + if (values[0].indexOf('at') < 0) { + // Looks like old syntax + + // Default values + var position = 'center'; + var shape = 'ellipse'; + var size = 'farthest-corner'; + + if (/\bcenter|top|right|bottom|left\b|^\d+/.test(values[0])) { + // Found a position + // Remove angle value, if any + position = values.shift().replace(/\s*-?\d+(?:rad|deg)\s*/, ''); + } + if (/\bcircle|ellipse|closest|farthest|contain|cover\b/.test(values[0])) { + // Found a shape and/or size + var shapeSizeParts = values.shift().split(/\s+/); + if (shapeSizeParts[0] && (shapeSizeParts[0] === 'circle' || shapeSizeParts[0] === 'ellipse')) { + shape = shapeSizeParts.shift(); + } + if (shapeSizeParts[0]) { + size = shapeSizeParts.shift(); + } + + // Old keywords are converted to their synonyms + if (size === 'cover') { + size = 'farthest-corner'; + } else if (size === 'contain') { + size = 'clothest-side'; + } + } + + return func + '(' + shape + ' ' + size + ' at ' + position + ',' + values.join(',') + ')'; + } + return func + '(' + values.join(',') + ')'; + }; + + /** + * Converts a gradient to a W3C-valid one + * Does not support old webkit syntax (-webkit-gradient(linear...) and -webkit-gradient(radial...)) + * @param {string} gradient The CSS gradient + */ + var convertToW3CGradient = function(gradient) { + if (cache[gradient]) { + return cache[gradient]; + } + var parts = gradient.match(/^(\b|\B-[a-z]{1,10}-)((?:repeating-)?(?:linear|radial)-gradient)/); + // "", "-moz-", etc. + var prefix = parts && parts[1]; + // "linear-gradient", "radial-gradient", etc. + var func = parts && parts[2]; + + var values = gradient.replace(/^(?:\b|\B-[a-z]{1,10}-)(?:repeating-)?(?:linear|radial)-gradient\(|\)$/g, '').split(/\s*,\s*/); + + if (func.indexOf('linear') >= 0) { + return cache[gradient] = convertToW3CLinearGradient(prefix, func, values); + } else if (func.indexOf('radial') >= 0) { + return cache[gradient] = convertToW3CRadialGradient(prefix, func, values); + } + return cache[gradient] = func + '(' + values.join(',') + ')'; + }; + + + + if (Prism.plugins.Previewer) { + new Prism.plugins.Previewer('gradient', function(value) { + this.firstChild.style.backgroundImage = ''; + this.firstChild.style.backgroundImage = convertToW3CGradient(value); + return !!this.firstChild.style.backgroundImage; + }, '*', function () { + this._elt.innerHTML = '
'; + }); + } + +}()); \ No newline at end of file diff --git a/plugins/previewer-gradient/prism-previewer-gradient.min.js b/plugins/previewer-gradient/prism-previewer-gradient.min.js new file mode 100644 index 0000000000..28d222d034 --- /dev/null +++ b/plugins/previewer-gradient/prism-previewer-gradient.min.js @@ -0,0 +1 @@ +!function(){if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var e={css:!0,less:!0,sass:[{lang:"sass",before:"punctuation",inside:"inside",root:Prism.languages.sass&&Prism.languages.sass["variable-line"]},{lang:"sass",before:"punctuation",inside:"inside",root:Prism.languages.sass&&Prism.languages.sass["property-line"]}],scss:!0,stylus:[{lang:"stylus",before:"func",inside:"rest",root:Prism.languages.stylus&&Prism.languages.stylus["property-declaration"].inside},{lang:"stylus",before:"func",inside:"rest",root:Prism.languages.stylus&&Prism.languages.stylus["variable-declaration"].inside}]};Prism.hooks.add("before-highlight",function(i){if(i.language&&e[i.language]&&!e[i.language].initialized){var t=e[i.language];"Array"!==Prism.util.type(t)&&(t=[t]),t.forEach(function(t){var r,s,a,n;t===!0?(r=Prism.plugins.Previewer&&Prism.plugins.Previewer.byType.color?"color":"important",s=i.language,t=i.language):(r=t.before||"important",s=t.inside||t.lang,a=t.root||Prism.languages,n=t.skip,t=i.language),!n&&Prism.languages[t]&&(Prism.languages.insertBefore(s,r,{gradient:{pattern:/(?:\b|\B-[a-z]{1,10}-)(?:repeating-)?(?:linear|radial)-gradient\((?:(?:rgb|hsl)a?\(.+?\)|[^\)])+\)/gi,inside:{"function":/[\w-]+(?=\()/,punctuation:/[(),]/}}},a),i.grammar=Prism.languages[t],e[i.language]={initialized:!0})})}});var i={},t=function(e,i,t){var r="180deg";return/^(?:-?\d*\.?\d+(?:deg|rad)|to\b|top|right|bottom|left)/.test(t[0])&&(r=t.shift(),r.indexOf("to ")<0&&(r.indexOf("top")>=0?r=r.indexOf("left")>=0?"to bottom right":r.indexOf("right")>=0?"to bottom left":"to bottom":r.indexOf("bottom")>=0?r=r.indexOf("left")>=0?"to top right":r.indexOf("right")>=0?"to top left":"to top":r.indexOf("left")>=0?r="to right":r.indexOf("right")>=0?r="to left":e&&(r.indexOf("deg")>=0?r=90-parseFloat(r)+"deg":r.indexOf("rad")>=0&&(r=Math.PI/2-parseFloat(r)+"rad")))),i+"("+r+","+t.join(",")+")"},r=function(e,i,t){if(t[0].indexOf("at")<0){var r="center",s="ellipse",a="farthest-corner";if(/\bcenter|top|right|bottom|left\b|^\d+/.test(t[0])&&(r=t.shift().replace(/\s*-?\d+(?:rad|deg)\s*/,"")),/\bcircle|ellipse|closest|farthest|contain|cover\b/.test(t[0])){var n=t.shift().split(/\s+/);!n[0]||"circle"!==n[0]&&"ellipse"!==n[0]||(s=n.shift()),n[0]&&(a=n.shift()),"cover"===a?a="farthest-corner":"contain"===a&&(a="clothest-side")}return i+"("+s+" "+a+" at "+r+","+t.join(",")+")"}return i+"("+t.join(",")+")"},s=function(e){if(i[e])return i[e];var s=e.match(/^(\b|\B-[a-z]{1,10}-)((?:repeating-)?(?:linear|radial)-gradient)/),a=s&&s[1],n=s&&s[2],l=e.replace(/^(?:\b|\B-[a-z]{1,10}-)(?:repeating-)?(?:linear|radial)-gradient\(|\)$/g,"").split(/\s*,\s*/);return i[e]=n.indexOf("linear")>=0?t(a,n,l):n.indexOf("radial")>=0?r(a,n,l):n+"("+l.join(",")+")"};Prism.plugins.Previewer&&new Prism.plugins.Previewer("gradient",function(e){return this.firstChild.style.backgroundImage="",this.firstChild.style.backgroundImage=s(e),!!this.firstChild.style.backgroundImage},"*",function(){this._elt.innerHTML="
"})}}(); \ No newline at end of file diff --git a/plugins/previewer-time/index.html b/plugins/previewer-time/index.html new file mode 100644 index 0000000000..eb0ac21309 --- /dev/null +++ b/plugins/previewer-time/index.html @@ -0,0 +1,85 @@ + + + + + + + Previewer: Time ▲ Prism plugins + + + + + + + + + + + + +
+
+ +

Previewer: Time

+

Previewer for CSS times.

+
+ +
+

How to use

+ +

You don't need to do anything. With this plugin loaded, a previewer will appear on hovering the time values in code blocks.

+

This plugin is compatible with CSS, Less, Sass, Scss and Stylus.

+
+ +
+

Examples

+ +

CSS

+
div {
+	transition: all linear 3s;
+}
+ +

Less

+
@time: 1s;
+#header a {
+	transition: all linear 2s;
+}
+ +

Sass

+
$time: 3s
+@mixin foobar
+	transition: all linear 800ms
+.foo
+	transition: all linear 0.8s
+
+ +

Scss

+
$time: 1s;
+.foo {
+	transition: all linear 10s
+}
+ +

Stylus

+
time = 3s
+.foo
+	transition: all linear 0.5s
+
+ +
+ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/previewer-time/prism-previewer-time.css b/plugins/previewer-time/prism-previewer-time.css new file mode 100644 index 0000000000..d0363a2a3b --- /dev/null +++ b/plugins/previewer-time/prism-previewer-time.css @@ -0,0 +1,90 @@ +@-webkit-keyframes prism-previewer-time { + 0% { + stroke-dasharray: 0, 500; + stroke-dashoffset: 0; + } + 50% { + stroke-dasharray: 100, 500; + stroke-dashoffset: 0; + } + 100% { + stroke-dasharray: 0, 500; + stroke-dashoffset: -100; + } +} + +@-o-keyframes prism-previewer-time { + 0% { + stroke-dasharray: 0, 500; + stroke-dashoffset: 0; + } + 50% { + stroke-dasharray: 100, 500; + stroke-dashoffset: 0; + } + 100% { + stroke-dasharray: 0, 500; + stroke-dashoffset: -100; + } +} + +@-moz-keyframes prism-previewer-time { + 0% { + stroke-dasharray: 0, 500; + stroke-dashoffset: 0; + } + 50% { + stroke-dasharray: 100, 500; + stroke-dashoffset: 0; + } + 100% { + stroke-dasharray: 0, 500; + stroke-dashoffset: -100; + } +} + +@keyframes prism-previewer-time { + 0% { + stroke-dasharray: 0, 500; + stroke-dashoffset: 0; + } + 50% { + stroke-dasharray: 100, 500; + stroke-dashoffset: 0; + } + 100% { + stroke-dasharray: 0, 500; + stroke-dashoffset: -100; + } +} + +.prism-previewer-time:before { + -webkit-border-radius: 50%; + -moz-border-radius: 50%; + border-radius: 50%; + background: #fff; +} +.prism-previewer-time:after { + margin-top: 4px; +} +.prism-previewer-time svg { + width: 32px; + height: 32px; + -webkit-transform: rotate(-90deg); + -moz-transform: rotate(-90deg); + -ms-transform: rotate(-90deg); + -o-transform: rotate(-90deg); + transform: rotate(-90deg); +} +.prism-previewer-time circle { + fill: transparent; + stroke: hsl(200, 10%, 20%); + stroke-opacity: 0.9; + stroke-width: 32; + stroke-dasharray: 0, 500; + stroke-dashoffset: 0; + -webkit-animation: prism-previewer-time linear infinite 3s; + -moz-animation: prism-previewer-time linear infinite 3s; + -o-animation: prism-previewer-time linear infinite 3s; + animation: prism-previewer-time linear infinite 3s; +} \ No newline at end of file diff --git a/plugins/previewer-time/prism-previewer-time.js b/plugins/previewer-time/prism-previewer-time.js new file mode 100644 index 0000000000..c72f8bb230 --- /dev/null +++ b/plugins/previewer-time/prism-previewer-time.js @@ -0,0 +1,98 @@ +(function() { + + if ( + typeof self !== 'undefined' && !self.Prism || + typeof global !== 'undefined' && !global.Prism + ) { + return; + } + + var languages = { + 'css': true, + 'less': true, + 'markup': { + lang: 'markup', + before: 'punctuation', + inside: 'inside', + root: Prism.languages.markup && Prism.languages.markup['tag'].inside['attr-value'] + }, + 'sass': [ + { + lang: 'sass', + inside: 'inside', + root: Prism.languages.sass && Prism.languages.sass['property-line'] + }, + { + lang: 'sass', + before: 'operator', + inside: 'inside', + root: Prism.languages.sass && Prism.languages.sass['variable-line'] + } + ], + 'scss': true, + 'stylus': [ + { + lang: 'stylus', + before: 'hexcode', + inside: 'rest', + root: Prism.languages.stylus && Prism.languages.stylus['property-declaration'].inside + }, + { + lang: 'stylus', + before: 'hexcode', + inside: 'rest', + root: Prism.languages.stylus && Prism.languages.stylus['variable-declaration'].inside + } + ] + }; + + Prism.hooks.add('before-highlight', function (env) { + if (env.language && languages[env.language] && !languages[env.language].initialized) { + var lang = languages[env.language]; + if (Prism.util.type(lang) !== 'Array') { + lang = [lang]; + } + lang.forEach(function(lang) { + var before, inside, root, skip; + if (lang === true) { + before = 'important'; + inside = env.language; + lang = env.language; + } else { + before = lang.before || 'important'; + inside = lang.inside || lang.lang; + root = lang.root || Prism.languages; + skip = lang.skip; + lang = env.language; + } + + if (!skip && Prism.languages[lang]) { + Prism.languages.insertBefore(inside, before, { + 'time': /(?:\b|\B-|(?=\B\.))\d*\.?\d+m?s\b/i + }, root); + env.grammar = Prism.languages[lang]; + + languages[env.language] = {initialized: true}; + } + }); + } + }); + + if (Prism.plugins.Previewer) { + new Prism.plugins.Previewer('time', function(value) { + var num = parseFloat(value); + var unit = value.match(/[a-z]+$/i); + if (!num || !unit) { + return false; + } + unit = unit[0]; + this.querySelector('circle').style.animationDuration = 2 * num + unit; + return true; + }, '*', function () { + this._elt.innerHTML = '' + + '' + + ''; + }); + } + +}()); \ No newline at end of file diff --git a/plugins/previewer-time/prism-previewer-time.min.js b/plugins/previewer-time/prism-previewer-time.min.js new file mode 100644 index 0000000000..0256b4a853 --- /dev/null +++ b/plugins/previewer-time/prism-previewer-time.min.js @@ -0,0 +1 @@ +!function(){if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var s={css:!0,less:!0,markup:{lang:"markup",before:"punctuation",inside:"inside",root:Prism.languages.markup&&Prism.languages.markup.tag.inside["attr-value"]},sass:[{lang:"sass",inside:"inside",root:Prism.languages.sass&&Prism.languages.sass["property-line"]},{lang:"sass",before:"operator",inside:"inside",root:Prism.languages.sass&&Prism.languages.sass["variable-line"]}],scss:!0,stylus:[{lang:"stylus",before:"hexcode",inside:"rest",root:Prism.languages.stylus&&Prism.languages.stylus["property-declaration"].inside},{lang:"stylus",before:"hexcode",inside:"rest",root:Prism.languages.stylus&&Prism.languages.stylus["variable-declaration"].inside}]};Prism.hooks.add("before-highlight",function(e){if(e.language&&s[e.language]&&!s[e.language].initialized){var a=s[e.language];"Array"!==Prism.util.type(a)&&(a=[a]),a.forEach(function(a){var i,r,n,l;a===!0?(i="important",r=e.language,a=e.language):(i=a.before||"important",r=a.inside||a.lang,n=a.root||Prism.languages,l=a.skip,a=e.language),!l&&Prism.languages[a]&&(Prism.languages.insertBefore(r,i,{time:/(?:\b|\B-|(?=\B\.))\d*\.?\d+m?s\b/i},n),e.grammar=Prism.languages[a],s[e.language]={initialized:!0})})}}),Prism.plugins.Previewer&&new Prism.plugins.Previewer("time",function(s){var e=parseFloat(s),a=s.match(/[a-z]+$/i);return e&&a?(a=a[0],this.querySelector("circle").style.animationDuration=2*e+a,!0):!1},"*",function(){this._elt.innerHTML=''})}}(); \ No newline at end of file diff --git a/prism.js b/prism.js index f1df17747f..71642871dc 100644 --- a/prism.js +++ b/prism.js @@ -518,14 +518,9 @@ Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css if (Prism.languages.markup) { Prism.languages.insertBefore('markup', 'tag', { 'style': { - pattern: /[\w\W]*?<\/style>/i, - inside: { - 'tag': { - pattern: /|<\/style>/i, - inside: Prism.languages.markup.tag.inside - }, - rest: Prism.languages.css - }, + pattern: /()[\w\W]*?(?=<\/style>)/i, + lookbehind: true, + inside: Prism.languages.css, alias: 'language-css' } }); @@ -586,7 +581,7 @@ Prism.languages.clike = { ********************************************** */ Prism.languages.javascript = Prism.languages.extend('clike', { - 'keyword': /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)\b/, + 'keyword': /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/, 'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/, // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444) 'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i @@ -621,14 +616,9 @@ Prism.languages.insertBefore('javascript', 'class-name', { if (Prism.languages.markup) { Prism.languages.insertBefore('markup', 'tag', { 'script': { - pattern: /[\w\W]*?<\/script>/i, - inside: { - 'tag': { - pattern: /|<\/script>/i, - inside: Prism.languages.markup.tag.inside - }, - rest: Prism.languages.javascript - }, + pattern: /()[\w\W]*?(?=<\/script>)/i, + lookbehind: true, + inside: Prism.languages.javascript, alias: 'language-javascript' } }); diff --git a/test-suite.html b/test-suite.html index 906fe81a06..b84ee46c47 100644 --- a/test-suite.html +++ b/test-suite.html @@ -26,6 +26,13 @@

Running the test suite

Running the test suite is simple: just call npm test.

All test files are run in isolation. A new prism instance is created for each test case. This will slow the test runner a bit down, but we can be sure that nothing leaks into the next test case.

+ +
+

Running tests for specific languages

+ +

To run the tests only for one language, you can use the language parameter: npm test -- --language=markup.

+

You can even specify multiple languages: npm test -- --language=markup --language=css.

+
@@ -139,6 +146,7 @@

Internal structure

+ diff --git a/tests/helper/test-discovery.js b/tests/helper/test-discovery.js index 741dc7591b..622b619271 100644 --- a/tests/helper/test-discovery.js +++ b/tests/helper/test-discovery.js @@ -25,6 +25,26 @@ module.exports = { return testSuite; }, + /** + * Loads the list of available tests that match the given languages + * + * @param {string} rootDir + * @param {string|string[]} languages + * @returns {Object.} + */ + loadSomeTests: function (rootDir, languages) { + var testSuite = {}; + var self = this; + + this.getSomeDirectories(rootDir, languages).forEach( + function (language) { + testSuite[language] = self.getAllFiles(path.join(rootDir, language)); + } + ); + + return testSuite; + }, + /** * Returns a list of all (sub)directories (just the directory names, not full paths) @@ -41,6 +61,38 @@ module.exports = { ); }, + /** + * Returns a list of all (sub)directories (just the directory names, not full paths) + * in the given src directory, matching the given languages + * + * @param {string} src + * @param {string|string[]} languages + * @returns {Array.} + */ + getSomeDirectories: function (src, languages) { + var self = this; + return fs.readdirSync(src).filter( + function (file) { + return fs.statSync(path.join(src, file)).isDirectory() && self.directoryMatches(file, languages); + } + ); + }, + + /** + * Returns whether a directory matches one of the given languages. + * @param {string} directory + * @param {string|string[]} languages + */ + directoryMatches: function (directory, languages) { + if (!Array.isArray(languages)) { + languages = [languages]; + } + var dirLanguages = directory.split(/!?\+!?/); + return dirLanguages.some(function (lang) { + return languages.indexOf(lang) >= 0; + }); + }, + /** * Returns a list of all full file paths to all files in the given src directory diff --git a/tests/languages/bash/arithmetic_environment_feature.test b/tests/languages/bash/arithmetic_environment_feature.test new file mode 100644 index 0000000000..a9c5663dc1 --- /dev/null +++ b/tests/languages/bash/arithmetic_environment_feature.test @@ -0,0 +1,53 @@ +(( 4 + 5 )) +$((5 * 7)) +"foo $((5 * 7)) bar" +for (( NUM=1 ; NUM<=1000 ; NUM++ )) + +---------------------------------------------------- + +[ + ["variable", [ + ["punctuation", "(("], + ["number", "4"], + ["operator", "+"], + ["number", "5"], + ["punctuation", "))"] + ]], + ["variable", [ + ["variable", "$(("], + ["number", "5"], + ["operator", "*"], + ["number", "7"], + ["variable", "))"] + ]], + ["string", [ + "\"foo ", + ["variable", [ + ["variable", "$(("], + ["number", "5"], + ["operator", "*"], + ["number", "7"], + ["variable", "))"] + ]], + " bar\"" + ]], + ["keyword", "for"], + ["variable", [ + ["punctuation", "(("], + " NUM", + ["operator", "="], + ["number", "1"], + ["punctuation", ";"], + " NUM", + ["operator", "<="], + ["number", "1000"], + ["punctuation", ";"], + " NUM", + ["operator", "++"], + ["punctuation", "))"] + ]] +] + +---------------------------------------------------- + +Checks arithmetic environments \ No newline at end of file diff --git a/tests/languages/bash/command_substitution_feature.test b/tests/languages/bash/command_substitution_feature.test new file mode 100644 index 0000000000..f849829b14 --- /dev/null +++ b/tests/languages/bash/command_substitution_feature.test @@ -0,0 +1,34 @@ +$(echo foo) +`echo foo` +"$(echo foo) bar" + +---------------------------------------------------- + +[ + ["variable", [ + ["variable", "$("], + ["keyword", "echo"], + " foo", + ["variable", ")"] + ]], + ["variable", [ + ["variable", "`"], + ["keyword", "echo"], + " foo", + ["variable", "`"] + ]], + ["string", [ + "\"", + ["variable", [ + ["variable", "$("], + ["keyword", "echo"], + " foo", + ["variable", ")"] + ]], + " bar\"" + ]] +] + +---------------------------------------------------- + +Checks for command substitution. \ No newline at end of file diff --git a/tests/languages/bash/keyword_feature.test b/tests/languages/bash/keyword_feature.test index ce35561519..b3bacf55af 100644 --- a/tests/languages/bash/keyword_feature.test +++ b/tests/languages/bash/keyword_feature.test @@ -3,7 +3,7 @@ for break continue while in case function select do done until echo exit return set declare - +. : ---------------------------------------------------- [ @@ -11,7 +11,8 @@ return set declare ["keyword", "for"], ["keyword", "break"], ["keyword", "continue"], ["keyword", "while"], ["keyword", "in"], ["keyword", "case"], ["keyword", "function"], ["keyword", "select"], ["keyword", "do"], ["keyword", "done"], ["keyword", "until"], ["keyword", "echo"], ["keyword", "exit"], - ["keyword", "return"], ["keyword", "set"], ["keyword", "declare"] + ["keyword", "return"], ["keyword", "set"], ["keyword", "declare"], + ["keyword", "."], ["keyword", ":"] ] ---------------------------------------------------- diff --git a/tests/languages/bash/string_feature.test b/tests/languages/bash/string_feature.test index 343ccc4c78..62abaf3765 100644 --- a/tests/languages/bash/string_feature.test +++ b/tests/languages/bash/string_feature.test @@ -6,6 +6,8 @@ bar" 'foo bar' +"'foo'" +'"bar"' "$@" "${foo}" << STRING_END @@ -16,28 +18,40 @@ STRING_END foo $@ bar EOF +<< 'EOF' +'single quoted string' +"double quoted string" +EOF +<< "EOF" +foo +bar +EOF ---------------------------------------------------- [ ["string", ["\"\""]], - ["string", "''"], + ["string", ["''"]], ["string", ["\"foo\""]], - ["string", "'foo'"], + ["string", ["'foo'"]], ["string", ["\"foo\r\nbar\""]], - ["string", "'foo\r\nbar'"], + ["string", ["'foo\r\nbar'"]], + ["string", ["\"'foo'\""]], + ["string", ["'\"bar\"'"]], ["string", [ "\"", ["variable", "$@"], "\"" ]], ["string", [ "\"", ["variable", "${foo}"], "\"" ]], - ["operator", "<"], - ["operator", "<"], + ["operator", "<<"], ["string", ["STRING_END\r\nfoo\r\nbar\r\nSTRING_END"]], - ["operator", "<"], - ["operator", "<"], - ["string", ["EOF\r\nfoo ", ["variable", "$@"], "\r\nbar\r\nEOF"]] + ["operator", "<<"], + ["string", ["EOF\r\nfoo ", ["variable", "$@"], "\r\nbar\r\nEOF"]], + ["operator", "<<"], + ["string", ["'EOF'\r\n'single quoted string'\r\n\"double quoted string\"\r\nEOF"]], + ["operator", "<<"], + ["string", ["\"EOF\"\r\nfoo\r\nbar\r\nEOF"]] ] ---------------------------------------------------- diff --git a/tests/languages/batch/command_feature.test b/tests/languages/batch/command_feature.test new file mode 100644 index 0000000000..350788a8bd --- /dev/null +++ b/tests/languages/batch/command_feature.test @@ -0,0 +1,103 @@ +FOR /l %%a in (5,-1,1) do (TITLE %title% -- closing in %%as) +SET title=%~n0 +echo.Hello World +@ECHO OFF +if not defined ProgressFormat set "ProgressFormat=[PPPP]" +EXIT /b +set /a ProgressCnt+=1 +IF "%~1" NEQ "" (SET %~1=%new%) ELSE (echo.%new%) + +---------------------------------------------------- + +[ + ["command", [ + ["keyword", "FOR"], + ["parameter", ["/l"]], + ["variable", "%%a"], + ["keyword", "in"], + ["punctuation", "("], + ["number", "5"], ["punctuation", ","], + ["number", "-1"], ["punctuation", ","], + ["number", "1"], ["punctuation", ")"], + ["keyword", "do"] + ]], + ["punctuation", "("], + ["command", [ + ["keyword", "TITLE"], + ["variable", "%title%"], + " -- closing in ", + ["variable", "%%as"] + ]], + ["punctuation", ")"], + + ["command", [ + ["keyword", "SET"], + ["variable", "title"], + ["operator", "="], + ["variable", "%~n0"] + ]], + + ["command", [ + ["keyword", "echo"], + ".Hello World" + ]], + + ["operator", "@"], + ["command", [ + ["keyword", "ECHO"], + " OFF" + ]], + + ["command", [ + ["keyword", "if"], + ["keyword", "not"], + ["keyword", "defined"], + " ProgressFormat" + ]], + ["command", [ + ["keyword", "set"], + ["string", "\"ProgressFormat=[PPPP]\""] + ]], + + ["command", [ + ["keyword", "EXIT"], + ["parameter", ["/b"]] + ]], + + ["command", [ + ["keyword", "set"], + ["parameter", ["/a"]], + ["variable", "ProgressCnt"], + ["operator", "+="], + ["number", "1"] + ]], + + ["command", [ + ["keyword", "IF"], + ["string", "\"%~1\""], + ["operator", "NEQ"], + ["string", "\"\""] + ]], + ["punctuation", "("], + ["command", [ + ["keyword", "SET"], + ["variable", "%~1"], + ["operator", "="], + ["variable", "%new%"] + ]], + ["punctuation", ")"], + ["command", [ + ["keyword", "ELSE"] + ]], + ["punctuation", "("], + ["command", [ + ["keyword", "echo"], + ".", + ["variable", "%new%"] + ]], + ["punctuation", ")"] +] + +---------------------------------------------------- + +Checks for commands. \ No newline at end of file diff --git a/tests/languages/batch/comment_feature.test b/tests/languages/batch/comment_feature.test new file mode 100644 index 0000000000..83759d8e86 --- /dev/null +++ b/tests/languages/batch/comment_feature.test @@ -0,0 +1,18 @@ +:: +:: Foobar +REM Foobar +rem foo^ +bar + +---------------------------------------------------- + +[ + ["comment", "::"], + ["comment", ":: Foobar"], + ["comment", "REM Foobar"], + ["comment", "rem foo^\r\nbar"] +] + +---------------------------------------------------- + +Checks for comments. \ No newline at end of file diff --git a/tests/languages/batch/label_feature.test b/tests/languages/batch/label_feature.test new file mode 100644 index 0000000000..a672ba0cc3 --- /dev/null +++ b/tests/languages/batch/label_feature.test @@ -0,0 +1,13 @@ +:foo +:Foo_Bar + +---------------------------------------------------- + +[ + ["label", ":foo"], + ["label", ":Foo_Bar"] +] + +---------------------------------------------------- + +Checks for labels. \ No newline at end of file diff --git a/tests/languages/bison/c_feature.test b/tests/languages/bison/c_feature.test index a131ec3d84..4d8be839d5 100644 --- a/tests/languages/bison/c_feature.test +++ b/tests/languages/bison/c_feature.test @@ -21,7 +21,7 @@ exp: ["bison", [ ["c", [ ["delimiter", "%{"], - ["macro", ["#include ", ["string", ""]]], + ["macro", ["#", ["directive", "include"], ["string", ""]]], ["delimiter", "%}"] ]], ["keyword", "%code"], diff --git a/tests/languages/c/macro_feature.test b/tests/languages/c/macro_feature.test index f537cb72c0..2860f544c7 100644 --- a/tests/languages/c/macro_feature.test +++ b/tests/languages/c/macro_feature.test @@ -1,17 +1,41 @@ # include #define PG_locked 0 -#foo \ -bar + +#elif +#else +#endif +#error +#ifdef +#ifndef +#if +#import +#include +#line +#pragma +#undef +#using ---------------------------------------------------- [ ["macro", [ - "# include ", + "# ", ["directive", "include"], ["string", ""] ]], - ["macro", ["#define PG_locked 0"]], - ["macro", ["#foo \\\r\nbar"]] + ["macro", ["#", ["directive", "define"], " PG_locked 0"]], + ["macro", ["#", ["directive", "elif"]]], + ["macro", ["#", ["directive", "else"]]], + ["macro", ["#", ["directive", "endif"]]], + ["macro", ["#", ["directive", "error"]]], + ["macro", ["#", ["directive", "ifdef"]]], + ["macro", ["#", ["directive", "ifndef"]]], + ["macro", ["#", ["directive", "if"]]], + ["macro", ["#", ["directive", "import"]]], + ["macro", ["#", ["directive", "include"]]], + ["macro", ["#", ["directive", "line"]]], + ["macro", ["#", ["directive", "pragma"]]], + ["macro", ["#", ["directive", "undef"]]], + ["macro", ["#", ["directive", "using"]]] ] ---------------------------------------------------- diff --git a/tests/languages/csharp/preprocessor_feature.test b/tests/languages/csharp/preprocessor_feature.test index b87a253701..93ad4903ab 100644 --- a/tests/languages/csharp/preprocessor_feature.test +++ b/tests/languages/csharp/preprocessor_feature.test @@ -2,12 +2,32 @@ #if DEBUG #endif +#elif +#else +#endregion +#error +#line +#pragma +#region +#undef +#warning + ---------------------------------------------------- [ - ["preprocessor", "#define DEBUG"], - ["preprocessor", "#if DEBUG"], - ["preprocessor", "#endif"] + ["preprocessor", ["#", ["directive", "define"], " DEBUG"]], + ["preprocessor", ["#", ["directive", "if"], " DEBUG"]], + ["preprocessor", ["#", ["directive", "endif"]]], + + ["preprocessor", ["#", ["directive", "elif"]]], + ["preprocessor", ["#", ["directive", "else"]]], + ["preprocessor", ["#", ["directive", "endregion"]]], + ["preprocessor", ["#", ["directive", "error"]]], + ["preprocessor", ["#", ["directive", "line"]]], + ["preprocessor", ["#", ["directive", "pragma"]]], + ["preprocessor", ["#", ["directive", "region"]]], + ["preprocessor", ["#", ["directive", "undef"]]], + ["preprocessor", ["#", ["directive", "warning"]]] ] ---------------------------------------------------- diff --git a/tests/languages/fsharp/preprocessor_feature.test b/tests/languages/fsharp/preprocessor_feature.test index 0bb16a6a24..4ee06395f4 100644 --- a/tests/languages/fsharp/preprocessor_feature.test +++ b/tests/languages/fsharp/preprocessor_feature.test @@ -2,12 +2,19 @@ #else #endif +#light +#line +#nowarn + ---------------------------------------------------- [ - ["preprocessor", "#if foo"], - ["preprocessor", "#else"], - ["preprocessor", "#endif"] + ["preprocessor", ["#", ["directive", "if"], " foo"]], + ["preprocessor", ["#", ["directive", "else"]]], + ["preprocessor", ["#", ["directive", "endif"]]], + ["preprocessor", ["#", ["directive", "light"]]], + ["preprocessor", ["#", ["directive", "line"]]], + ["preprocessor", ["#", ["directive", "nowarn"]]] ] ---------------------------------------------------- diff --git a/tests/languages/javascript/boolean_feature.test b/tests/languages/javascript/boolean_feature.test new file mode 100644 index 0000000000..4019c444f8 --- /dev/null +++ b/tests/languages/javascript/boolean_feature.test @@ -0,0 +1,13 @@ +true +false + +---------------------------------------------------- + +[ + ["boolean", "true"], + ["boolean", "false"] +] + +---------------------------------------------------- + +Checks for booleans. \ No newline at end of file diff --git a/tests/languages/javascript/keyword_feature.test b/tests/languages/javascript/keyword_feature.test index 13f7bf7136..13b88875d0 100644 --- a/tests/languages/javascript/keyword_feature.test +++ b/tests/languages/javascript/keyword_feature.test @@ -1,12 +1,12 @@ as; async; await; break; case; catch; class; const; continue; debugger; default; delete; do; else; enum; -export; extends; false; finally; for; +export; extends; finally; for; from; function; get; if; implements; import; in; instanceof; interface; let; new; null; of; package; private; protected; public; return; set; static; -super; switch; this; throw; true; +super; switch; this; throw; try; typeof; var; void; while; with; yield; @@ -30,7 +30,6 @@ with; yield; ["keyword", "enum"], ["punctuation", ";"], ["keyword", "export"], ["punctuation", ";"], ["keyword", "extends"], ["punctuation", ";"], - ["keyword", "false"], ["punctuation", ";"], ["keyword", "finally"], ["punctuation", ";"], ["keyword", "for"], ["punctuation", ";"], ["keyword", "from"], ["punctuation", ";"], @@ -57,7 +56,6 @@ with; yield; ["keyword", "switch"], ["punctuation", ";"], ["keyword", "this"], ["punctuation", ";"], ["keyword", "throw"], ["punctuation", ";"], - ["keyword", "true"], ["punctuation", ";"], ["keyword", "try"], ["punctuation", ";"], ["keyword", "typeof"], ["punctuation", ";"], ["keyword", "var"], ["punctuation", ";"], diff --git a/tests/languages/jsx/tag_feature.test b/tests/languages/jsx/tag_feature.test index 7d523beaa7..6a4a8c5b3f 100644 --- a/tests/languages/jsx/tag_feature.test +++ b/tests/languages/jsx/tag_feature.test @@ -35,7 +35,7 @@ var myElement = ; ["script", [ ["punctuation", "="], ["punctuation", "{"], - ["keyword", "true"], + ["boolean", "true"], ["punctuation", "}"] ]], ["punctuation", "/>"] diff --git a/tests/languages/markup!+css/css_inclusion.test b/tests/languages/markup!+css/css_inclusion.test index b606f11470..6296fcef0a 100644 --- a/tests/languages/markup!+css/css_inclusion.test +++ b/tests/languages/markup!+css/css_inclusion.test @@ -9,37 +9,37 @@ foo { ---------------------------------------------------- [ - ["style", [ + ["tag", [ ["tag", [ - ["tag", [ - ["punctuation", "<"], - "style" - ]], - ["attr-name", [ - "type" - ]], - ["attr-value", [ - ["punctuation", "="], - ["punctuation", "\""], - "text/css", - ["punctuation", "\""] - ]], - ["punctuation", ">"] + ["punctuation", "<"], + "style" ]], + ["attr-name", [ + "type" + ]], + ["attr-value", [ + ["punctuation", "="], + ["punctuation", "\""], + "text/css", + ["punctuation", "\""] + ]], + ["punctuation", ">"] + ]], + ["style", [ ["selector", "foo"], ["punctuation", "{"], ["property", "bar"], ["punctuation", ":"], " baz", ["punctuation", ";"], - ["punctuation", "}"], + ["punctuation", "}"] + ]], + ["tag", [ ["tag", [ - ["tag", [ - ["punctuation", ""] - ]] + ["punctuation", ""] ]], ["tag", [ diff --git a/tests/languages/markup!+javascript/javascript_inclusion.test b/tests/languages/markup!+javascript/javascript_inclusion.test index 0aeeb0e01a..ef9a0ce9f5 100644 --- a/tests/languages/markup!+javascript/javascript_inclusion.test +++ b/tests/languages/markup!+javascript/javascript_inclusion.test @@ -6,51 +6,53 @@ ---------------------------------------------------- [ - ["script", [ + + ["tag", [ ["tag", [ - ["tag", [ - ["punctuation", "<"], - "script" - ]], - ["attr-name", [ - "type" - ]], - ["attr-value", [ - ["punctuation", "="], - ["punctuation", "\""], - "text/javascript", - ["punctuation", "\""] - ]], - ["punctuation", ">"] + ["punctuation", "<"], + "script" + ]], + ["attr-name", [ + "type" + ]], + ["attr-value", [ + ["punctuation", "="], + ["punctuation", "\""], + "text/javascript", + ["punctuation", "\""] ]], + ["punctuation", ">"] + ]], + ["script", [ ["function", "foo"], ["punctuation", "("], - ["punctuation", ")"], + ["punctuation", ")"] + ]], + ["tag", [ ["tag", [ - ["tag", [ - ["punctuation", ""] - ]] + ["punctuation", ""] ]], - ["script", [ + + ["tag", [ ["tag", [ - ["tag", [ - ["punctuation", "<"], - "script" - ]], - ["punctuation", ">"] + ["punctuation", "<"], + "script" ]], - ["string", "\"foo bar\""], + ["punctuation", ">"] + ]], + ["script", [ + ["string", "\"foo bar\""] + ]], + ["tag", [ ["tag", [ - ["tag", [ - ["punctuation", ""] - ]] - ]] + ["punctuation", ""] + ]] ] ---------------------------------------------------- diff --git a/tests/languages/markup+javascript+csharp+aspnet/script_feature.test b/tests/languages/markup+javascript+csharp+aspnet/script_feature.test index 80c1ef80a2..aa07913e92 100644 --- a/tests/languages/markup+javascript+csharp+aspnet/script_feature.test +++ b/tests/languages/markup+javascript+csharp+aspnet/script_feature.test @@ -1,51 +1,52 @@ - + ---------------------------------------------------- [ + ["tag", [ + ["tag", [ + ["punctuation", "<"], + "script" + ]], + ["attr-name", [ + "runat" + ]], + ["attr-value", [ + ["punctuation", "="], + ["punctuation", "\""], + "server", + ["punctuation", "\""] + ]], + ["punctuation", ">"] + ]], ["asp script", [ + ["preprocessor", ["#", ["directive", "pragma"]]] + ]], + ["tag", [ ["tag", [ - ["tag", [ - ["punctuation", "<"], - "script" - ]], - ["attr-name", [ - "runat" - ]], - ["attr-value", [ - ["punctuation", "="], - ["punctuation", "\""], - "server", - ["punctuation", "\""] - ]], - ["punctuation", ">"] + ["punctuation", ""] + ]], + + ["tag", [ ["tag", [ - ["tag", [ - ["punctuation", ""] - ]] + ["punctuation", "<"], + "script" + ]], + ["punctuation", ">"] ]], ["script", [ + ["regex", "/foo/"] + ]], + ["tag", [ ["tag", [ - ["tag", [ - ["punctuation", "<"], - "script" - ]], - ["punctuation", ">"] + ["punctuation", ""] - ]] + ["punctuation", ">"] ]] ] diff --git a/tests/run.js b/tests/run.js index 5e0050487f..30f165d7aa 100644 --- a/tests/run.js +++ b/tests/run.js @@ -3,9 +3,15 @@ var TestDiscovery = require("./helper/test-discovery"); var TestCase = require("./helper/test-case"); var path = require("path"); +var argv = require("yargs").argv; -// load complete test suite -var testSuite = TestDiscovery.loadAllTests(__dirname + "/languages"); +var testSuite; +if (argv.language) { + testSuite = TestDiscovery.loadSomeTests(__dirname + "/languages", argv.language); +} else { + // load complete test suite + testSuite = TestDiscovery.loadAllTests(__dirname + "/languages"); +} // define tests for all tests in all languages in the test suite for (var language in testSuite) { @@ -15,6 +21,8 @@ for (var language in testSuite) { (function (language, testFiles) { describe("Testing language '" + language + "'", function () { + this.timeout(10000); + testFiles.forEach( function (filePath) { var fileName = path.basename(filePath, path.extname(filePath));