diff options
Diffstat (limited to 'plugins/textviewer/syntaxhighlighter/tests/cases')
15 files changed, 721 insertions, 0 deletions
diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/001_basic.html b/plugins/textviewer/syntaxhighlighter/tests/cases/001_basic.html new file mode 100644 index 00000000000..1d57334c188 --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/001_basic.html @@ -0,0 +1,42 @@ +<pre id="sh_001_basic" class="brush: js;" title="Title/caption should render"> + /** + * multiline comment + */ + + text + + // single line comment + + text + + "string" text 'string' text "string" + "string with \" escape" text 'string with \' escape' text "string with \" escape" + + var code = '\ + function helloWorld()\ + {\ + // this is great!\ + for(var i = 0; i <= 1; i++)\ + alert("yay");\ + }\ + '; +</pre> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('001_basic'); + + test('basic html check of default elements', function() + { + $sh = $('#sh_001_basic'); + ok_sh($sh); + ok_toolbar($sh); + ok_caption($sh, 'Title/caption should render'); + ok_gutter($sh); + ok_code($sh); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/002_brushes.html b/plugins/textviewer/syntaxhighlighter/tests/cases/002_brushes.html new file mode 100644 index 00000000000..e9c64e2a091 --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/002_brushes.html @@ -0,0 +1,50 @@ +<div id="sh_002_brushes"> + <pre class="brush: applescript;">test</pre> + <pre class="brush: as3;">test</pre> + <pre class="brush: bash;">test</pre> + <pre class="brush: cf;">test</pre> + <pre class="brush: cpp;">test</pre> + <pre class="brush: csharp;">test</pre> + <pre class="brush: css;">test</pre> + <pre class="brush: delphi;">test</pre> + <pre class="brush: diff;">test</pre> + <pre class="brush: erlang;">test</pre> + <pre class="brush: groovy;">test</pre> + <pre class="brush: java;">test</pre> + <pre class="brush: javafx;">test</pre> + <pre class="brush: jscript;">test</pre> + <pre class="brush: perl;">test</pre> + <pre class="brush: php;">test</pre> + <pre class="brush: plain;">test</pre> + <pre class="brush: powershell;">test</pre> + <pre class="brush: python;">test</pre> + <pre class="brush: ruby;">test</pre> + <pre class="brush: sass;">test</pre> + <pre class="brush: scala;">test</pre> + <pre class="brush: sql;">test</pre> + <pre class="brush: vb;">test</pre> + <pre class="brush: xml;">test</pre> +</div> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('002_brushes'); + + test('check that all brushes loaded and rendered', function() + { + $sh = $('#sh_002_brushes'); + + $sh.find('> div > .syntaxhighlighter').each(function() + { + var $sh = $(this).parent(); + ok_sh($sh); + ok_sh($sh); + ok_toolbar($sh); + ok_code($sh); + }); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/003_script_tag.html b/plugins/textviewer/syntaxhighlighter/tests/cases/003_script_tag.html new file mode 100644 index 00000000000..9b442925719 --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/003_script_tag.html @@ -0,0 +1,42 @@ +<div> +<script id="sh_003_script_tag" type="syntaxhighlighter" class="brush: csharp" title="Title/caption should render"><![CDATA[ + partial class Foo + { + function test() + { + yield return; + yield break; + } + } + + function foo() + { + var vector:Vector.<Vector.<String>> = new Vector<Vector.String>>(); + + for (var i = 0; i < 10; i++) + { + /* comments */ + } + } +]]></script> +</div> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('003_script_tag'); + + test('basic html check of default elements', function() + { + $sh = $('#sh_003_script_tag'); + + ok_sh($sh); + ok_toolbar($sh); + ok_caption($sh, 'Title/caption should render'); + ok_gutter($sh); + ok_code($sh); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/004_url_parsing.html b/plugins/textviewer/syntaxhighlighter/tests/cases/004_url_parsing.html new file mode 100644 index 00000000000..d489a66940a --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/004_url_parsing.html @@ -0,0 +1,43 @@ +<pre id="sh_004_url_parsing" class="brush: as3;"> +/** + * Please see <http://www.alexgorbatchev.come/?test=1&y=2> + */ +var home = "http://www.alexgorbatchev.come/?test=1&y=2;test/1/2/3;"; +// < http://www.gnu.org/licenses/?test=1&y=2 >. + +// Test embedded URLs that terminate at a left angle bracket. +// See bug #28: http://bitbucket.org/alexg/syntaxhighlighter/issue/28/ +"<location>http://www.example.com/song2.mp3</location>"; +</pre> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('004_url_parsing'); + + test('check that urls are present', function() + { + $sh = $('#sh_004_url_parsing'); + + ok_sh($sh); + ok_toolbar($sh); + ok_code($sh); + + var expected = [ + 'http://www.alexgorbatchev.come/?test=1&y=2', + 'http://www.alexgorbatchev.come/?test=1&y=2;test/1/2/3;', + 'http://www.gnu.org/licenses/?test=1&y=2', + 'http://bitbucket.org/alexg/syntaxhighlighter/issue/28/', + 'http://www.example.com/song2.mp3' + ]; + + $sh.find('td.code a').each(function(index) + { + equal($(this).attr('href'), expected[index], 'href'); + equal($(this).text(), expected[index], 'text'); + }) + }); +}); +</script>
\ No newline at end of file diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/005_no_gutter.html b/plugins/textviewer/syntaxhighlighter/tests/cases/005_no_gutter.html new file mode 100644 index 00000000000..6e6b1be0799 --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/005_no_gutter.html @@ -0,0 +1,33 @@ +<pre id="sh_005_no_gutter" class="brush: java; gutter: false;"> + public Image getImage(URL url, String name) { + try { + /* + Regular multiline comment. + */ + return getImage(new URL(url, name)); + } catch (MalformedURLException e) { + return null; + } + } +</pre> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('005_no_gutter'); + + test('check that there is no gutter', function() + { + $sh = $('#sh_005_no_gutter'); + + ok_sh($sh); + ok_toolbar($sh); + ok_code($sh); + + ok($sh.find('> .syntaxhighlighter.nogutter').length == 1, '.nogutter present'); + ok($sh.find('> .syntaxhighlighter > table > tbody > tr > .gutter').length == 0, 'Gutter not present'); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/006_pad_line_numbers.html b/plugins/textviewer/syntaxhighlighter/tests/cases/006_pad_line_numbers.html new file mode 100644 index 00000000000..8ebdd55b4ea --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/006_pad_line_numbers.html @@ -0,0 +1,39 @@ +<pre id="sh_006_pad_line_numbers" class="brush: java; pad-line-numbers: true"> +/** + * Returns an Image object that can then be painted on the screen. + * The url argument must specify an absolute {@link URL}. The name + * argument is a specifier that is relative to the url argument. + * + * @param url an absolute URL giving the base location of the image + * @param name the location of the image, relative to the url argument + * @return the image at the specified URL + * @see Image + */ +</pre> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('006_pad_line_numbers'); + + test('check that line numbers are padded with zeroes', function() + { + $sh = $('#sh_006_pad_line_numbers'); + + ok_sh($sh); + ok_toolbar($sh); + ok_gutter($sh); + ok_code($sh); + + $sh.find('.gutter > .line').each(function(index) + { + var text = $(this).text(); + + if (parseInt(text) < 10) + ok(text.charAt(0) == '0', 'Line ' + index + ' has leading zero: ' + text); + }); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/007_collapse.html b/plugins/textviewer/syntaxhighlighter/tests/cases/007_collapse.html new file mode 100644 index 00000000000..2643bb559d9 --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/007_collapse.html @@ -0,0 +1,60 @@ +<pre id="sh_007_collapse_a" class="brush: groovy; collapse: true" title="This is a title for collapsed block"> + /** + * Returns an Image object that can then be painted on the screen. + * The url argument must specify an absolute {@link URL}. The name + * argument is a specifier that is relative to the url argument. + * + * @param url an absolute URL giving the base location of the image + * @param name the location of the image, relative to the url argument + * @return the image at the specified URL + * @see Image + */ +</pre> + +<pre id="sh_007_collapse_b" class="brush: groovy; collapse: true"> + /** + * Returns an Image object that can then be painted on the screen. + * The url argument must specify an absolute {@link URL}. The name + * argument is a specifier that is relative to the url argument. + * + * @param url an absolute URL giving the base location of the image + * @param name the location of the image, relative to the url argument + * @return the image at the specified URL + * @see Image + */ +</pre> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('007_collapse'); + + test('collapsed block with title', function() + { + $sh = $('#sh_007_collapse_a'); + + ok_sh($sh); + ok_toolbar($sh); + ok_collapsed($sh); + + var $title = $sh.find('.toolbar a.toolbar_item.command_expandSource'); + ok($title.length == 1, 'Expand present'); + equal($title.text(), 'This is a title for collapsed block', 'Expand text'); + }); + + test('collapsed block without title', function() + { + $sh = $('#sh_007_collapse_b'); + + ok_sh($sh); + ok_toolbar($sh); + ok_collapsed($sh); + + var $title = $sh.find('.toolbar a.toolbar_item.command_expandSource'); + ok($title.length == 1, 'Expand present'); + equal($title.text(), SyntaxHighlighter.config.strings.expandSource, 'Expand text'); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/007_collapse_interaction.html b/plugins/textviewer/syntaxhighlighter/tests/cases/007_collapse_interaction.html new file mode 100644 index 00000000000..ea72046e66a --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/007_collapse_interaction.html @@ -0,0 +1,44 @@ +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('007_collapse_interaction'); + + function clickA($a) + { + SyntaxHighlighter.toolbar.handler({ + target: $a[0], + preventDefault: function() {} + }); + }; + + test('expand collapsed block with title', function() + { + $sh = $('#sh_007_collapse_a'); + + ok_sh($sh); + ok_toolbar($sh); + ok_collapsed($sh); + + var $a = $sh.find('.toolbar a.toolbar_item.command_expandSource'); + clickA($a); + ok($a.not(':visible'), 'Expand not visible'); + ok_code($sh); + }); + + test('expand collapsed block without title', function() + { + $sh = $('#sh_007_collapse_b'); + + ok_sh($sh); + ok_toolbar($sh); + ok_collapsed($sh); + + var $a = $sh.find('.toolbar a.toolbar_item.command_expandSource'); + clickA($a); + ok($a.not(':visible'), 'Expand not visible'); + ok_code($sh); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/008_first_line.html b/plugins/textviewer/syntaxhighlighter/tests/cases/008_first_line.html new file mode 100644 index 00000000000..169dc38c87e --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/008_first_line.html @@ -0,0 +1,29 @@ +<pre id="sh_008_first_line" class="brush: java; first-line: 10"> + partial class Foo + { + function test() + { + yield return; + } + } +</pre> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('008_first_line'); + + test('check the first line', function() + { + $sh = $('#sh_008_first_line'); + + ok_sh($sh); + ok_toolbar($sh); + ok_gutter($sh); + ok_code($sh); + equals($sh.find('.gutter .index0').text(), '10', 'First line'); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/009_class_name.html b/plugins/textviewer/syntaxhighlighter/tests/cases/009_class_name.html new file mode 100644 index 00000000000..f2437d58bea --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/009_class_name.html @@ -0,0 +1,32 @@ +<pre id="sh_009_class_name" class="brush: java; class-name: 'custom class here'"> + public Image getImage(URL url, String name) { + try { + /* + Regular multiline comment. + */ + return getImage(new URL(url, name)); + } catch (MalformedURLException e) { + return null; + } + } +</pre> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('009_class_name'); + + test('check custom classes', function() + { + $sh = $('#sh_009_class_name'); + + ok_sh($sh); + ok_toolbar($sh); + ok_gutter($sh); + ok_code($sh); + ok($sh.find('.syntaxhighlighter').is('.custom.class.here'), 'Check custom classes'); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/010_highlight.html b/plugins/textviewer/syntaxhighlighter/tests/cases/010_highlight.html new file mode 100644 index 00000000000..64b66130377 --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/010_highlight.html @@ -0,0 +1,70 @@ +<pre id="sh_010_highlight_a" class="brush: groovy; highlight: 2"> + public function validateStrongPassword(password:String):Boolean + { + if (password == null || password.length <= 0) + { + return false; + } + + return STRONG_PASSWORD_PATTERN.test(password); + } +</pre> +<script id="sh_010_highlight_b" type="syntaxhighlighter" class="brush: as3; highlight: [2, 4, 12]"><![CDATA[ + /** + * Checks a password and returns a value indicating whether the password is a "strong" + * password. The criteria for a strong password are: + * + * <ul> + * <li>Minimum 8 characters</li> + * <li>Maxmium 32 characters</li> + * <li>Contains at least one lowercase letter</li> + * <li>Contains at least one uppercase letter</li> + * <li>Contains at least one number or symbol character</li> + * </ul> + * + * @param password The password to check + * + * @return A value indicating whether the password is a strong password (<code>true</code>) + * or not (<code>false</code>). + */ + public function validateStrongPassword(password:String):Boolean + { + if (password == null || password.length <= 0) + { + return false; + } + + return STRONG_PASSWORD_PATTERN.test(password); + } +]]></script> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('010_highlight'); + + test('one highlighted line', function() + { + $sh = $('#sh_010_highlight_a'); + + ok_sh($sh); + ok_toolbar($sh); + ok_code($sh); + ok($sh.find('.gutter .number2').is('.highlighted'), 'Line 2 is highlighted'); + }); + + test('multiple highlighted lines', function() + { + $sh = $('#sh_010_highlight_b'); + + ok_sh($sh); + ok_toolbar($sh); + ok_code($sh); + ok($sh.find('.gutter .number2').is('.highlighted'), 'Line 2 is highlighted'); + ok($sh.find('.gutter .number4').is('.highlighted'), 'Line 4 is highlighted'); + ok($sh.find('.gutter .number12').is('.highlighted'), 'Line 12 is highlighted'); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/011_smart_tabs.html b/plugins/textviewer/syntaxhighlighter/tests/cases/011_smart_tabs.html new file mode 100644 index 00000000000..d6d62fc867b --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/011_smart_tabs.html @@ -0,0 +1,98 @@ +<pre id="sh_011_smart_tabs_a" class="brush: plain;"> + the words in this paragraph + should look like they are + evenly spaced between columns +</pre> + +<pre id="sh_011_smart_tabs_b" class="brush: plain; tab-size: 8;"> + the words in this paragraph + should look like they are + evenly spaced between columns +</pre> + +<pre id="sh_011_smart_tabs_c" class="brush: plain; smart-tabs: false"> + the words in this paragraph + should look out of whack + because smart tabs are disabled +</pre> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('011_smart_tabs'); + + var evenLines = [ + 'the words in this paragraph', + 'should look like they are', + 'evenly spaced between columns' + ], + unevenLines = [ + 'the words in this paragraph', + 'should look out of whack', + 'because smart tabs are disabled' + ] + ; + + function fixSpaces(s) + { + s = encodeURIComponent(s).replace(/%C2%A0/g, '%20'); + return unescape(s).replace(/\s+$/g, ''); + }; + + test('default tab size is 4', function() + { + $sh = $('#sh_011_smart_tabs_a'); + + ok_sh($sh); + ok_toolbar($sh); + ok_code($sh); + + $sh.find('.code .line').each(function(index) + { + var s1 = fixSpaces($(this).text()), + s2 = fixSpaces(evenLines[index]) + ; + + equal(s1, s2, 'Line ' + index); + }); + }); + + test('tab size changed to 8', function() + { + $sh = $('#sh_011_smart_tabs_b'); + + ok_sh($sh); + ok_toolbar($sh); + ok_code($sh); + + $sh.find('.code .line').each(function(index) + { + var s1 = fixSpaces($(this).text()), + s2 = fixSpaces(evenLines[index]) + ; + + equal(s1, s2, 'Line ' + index); + }); + }); + + test('smart tabs are off', function() + { + $sh = $('#sh_011_smart_tabs_c'); + + ok_sh($sh); + ok_toolbar($sh); + ok_code($sh); + + $sh.find('.code .line').each(function(index) + { + var s1 = fixSpaces($(this).text()), + s2 = fixSpaces(unevenLines[index]) + ; + + equal(s1, s2, 'Line ' + index); + }); + }); +}); +</script> diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/012_server_side.html b/plugins/textviewer/syntaxhighlighter/tests/cases/012_server_side.html new file mode 100644 index 00000000000..1bb421737a6 --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/012_server_side.html @@ -0,0 +1,35 @@ +<script id="sh_012_server_side_input" type="text/plain"> +function helloWorld() +{ + // this is great! + for(var i = 0; i <= 1; i++) + alert("yay"); +} +</script> + +<div id="sh_012_server_side_output"> +</div> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('012_server_side'); + + test('generate markup', function() + { + var brush = new SyntaxHighlighter.brushes.JScript(), + code = $('#sh_012_server_side_input').html() + ; + + brush.init({ toolbar: false }); + $sh = $('#sh_012_server_side_output'); + $sh.html(brush.getHtml(code)); + + ok_sh($sh); + ok_gutter($sh); + ok_code($sh); + }); +}); +</script>
\ No newline at end of file diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/013_html_script.html b/plugins/textviewer/syntaxhighlighter/tests/cases/013_html_script.html new file mode 100644 index 00000000000..c0a1201934d --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/013_html_script.html @@ -0,0 +1,34 @@ +<pre id="sh_013_html_script" class="brush: groovy; html-script: true"> +<hello> + <% + package free.cafekiwi.gotapi; + %> +</hello> + +<!-- + Comments here +--> +<%= print(); %> +</pre> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + module('013_html_script'); + + test('check markup', function() + { + $sh = $('#sh_013_html_script'); + + ok_sh($sh); + ok_gutter($sh); + ok_code($sh); + + ok($sh.find('.code .number1 > .htmlscript').length > 0, 'Has .htmlscript on line 1'); + ok($sh.find('.code .number3 > .groovy').length > 0, 'Has .groovy on line 3'); + ok($sh.find('.code .number10 > .groovy').length > 0, 'Has .groovy on line 10'); + }); +}); +</script>
\ No newline at end of file diff --git a/plugins/textviewer/syntaxhighlighter/tests/cases/014_legacy.html b/plugins/textviewer/syntaxhighlighter/tests/cases/014_legacy.html new file mode 100644 index 00000000000..eb4343e2c2d --- /dev/null +++ b/plugins/textviewer/syntaxhighlighter/tests/cases/014_legacy.html @@ -0,0 +1,70 @@ +<pre id="sh_014_legacy_a" name="code" class="plain">basic check</pre> +<pre id="sh_014_legacy_b" name="code" class="plain:nocontrols">no toolbar</pre> +<pre id="sh_014_legacy_c" name="code" class="plain:nogutter">no gutter</pre> +<pre id="sh_014_legacy_d" name="code" class="plain:collapse">collapsed</pre> +<pre id="sh_014_legacy_e" name="code" class="plain:firstline[10]">first line</pre> + +<script type="text/javascript"> +queue(function() +{ + var $sh; + + dp.SyntaxHighlighter.HighlightAll('code'); + + module('014_legacy'); + + test('basic check', function() + { + $sh = $('#sh_014_legacy_a'); + + ok_sh($sh); + ok_toolbar($sh); + ok_code($sh); + }); + + test('no toolbar', function() + { + $sh = $('#sh_014_legacy_b'); + + ok_sh($sh); + ok_code($sh); + ok($sh.find('> .syntaxhighlighter > .toolbar').length == 0, 'Toolbar not present'); + }); + + test('no gutter', function() + { + $sh = $('#sh_014_legacy_c'); + + ok_sh($sh); + ok_toolbar($sh); + ok_code($sh); + + ok($sh.find('> .syntaxhighlighter.nogutter').length == 1, '.nogutter present'); + ok($sh.find('> .syntaxhighlighter > table > tbody > tr > .gutter').length == 0, 'Gutter not present'); + }); + + test('collapsed check', function() + { + $sh = $('#sh_014_legacy_d'); + + ok_sh($sh); + ok_toolbar($sh); + ok_collapsed($sh); + + var $title = $sh.find('.toolbar a.toolbar_item.command_expandSource'); + ok($title.length == 1, 'Expand present'); + equal($title.text(), SyntaxHighlighter.config.strings.expandSource, 'Expand text'); + }); + + test('first line check', function() + { + $sh = $('#sh_014_legacy_e'); + + ok_sh($sh); + ok_toolbar($sh); + ok_gutter($sh); + ok_code($sh); + equals($sh.find('.gutter .index0').text(), '10', 'First line'); + }); +}); +</script> |