aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/xquery/test
diff options
context:
space:
mode:
Diffstat (limited to 'imports/codemirror/mode/xquery/test')
-rw-r--r--imports/codemirror/mode/xquery/test/index.html27
-rw-r--r--imports/codemirror/mode/xquery/test/testBase.js42
-rw-r--r--imports/codemirror/mode/xquery/test/testEmptySequenceKeyword.js16
-rw-r--r--imports/codemirror/mode/xquery/test/testMultiAttr.js16
-rw-r--r--imports/codemirror/mode/xquery/test/testNamespaces.js91
-rw-r--r--imports/codemirror/mode/xquery/test/testProcessingInstructions.js16
-rw-r--r--imports/codemirror/mode/xquery/test/testQuotes.js19
7 files changed, 227 insertions, 0 deletions
diff --git a/imports/codemirror/mode/xquery/test/index.html b/imports/codemirror/mode/xquery/test/index.html
new file mode 100644
index 00000000..ba82e54f
--- /dev/null
+++ b/imports/codemirror/mode/xquery/test/index.html
@@ -0,0 +1,27 @@
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3<html>
4 <head>
5 <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css"/>
6 <script src="http://code.jquery.com/jquery-latest.js"> </script>
7 <script type="text/javascript" src="http://code.jquery.com/qunit/qunit-git.js"></script>
8
9 <script src="../../../lib/codemirror.js"></script>
10 <script src="../xquery.js"></script>
11
12 <script type="text/javascript" src="testBase.js"></script>
13 <script type="text/javascript" src="testMultiAttr.js"></script>
14 <script type="text/javascript" src="testQuotes.js"></script>
15 <script type="text/javascript" src="testEmptySequenceKeyword.js"></script>
16 <script type="text/javascript" src="testProcessingInstructions.js"></script>
17 <script type="text/javascript" src="testNamespaces.js"></script>
18 </head>
19 <body>
20 <h1 id="qunit-header">XQuery CodeMirror Mode</h1>
21 <h2 id="qunit-banner"></h2>
22 <h2 id="qunit-userAgent"></h2>
23 <ol id="qunit-tests">
24 </ol>
25 <div id="sandbox" style="right:5000px; position:absolute; "></div>
26 </body>
27</html>
diff --git a/imports/codemirror/mode/xquery/test/testBase.js b/imports/codemirror/mode/xquery/test/testBase.js
new file mode 100644
index 00000000..d40e9eea
--- /dev/null
+++ b/imports/codemirror/mode/xquery/test/testBase.js
@@ -0,0 +1,42 @@
1 $(document).ready(function(){
2 module("testBase");
3 test("eviltest", function() {
4 expect(1);
5
6 var input = 'xquery version &quot;1.0-ml&quot;;\
7 (: this is\
8 : a \
9 "comment" :)\
10 let $let := &lt;x attr=&quot;value&quot;&gt;&quot;test&quot;&lt;func&gt;function() $var {function()} {$var}&lt;/func&gt;&lt;/x&gt;\
11 let $joe:=1\
12 return element element {\
13 attribute attribute { 1 },\
14 element test { &#39;a&#39; }, \
15 attribute foo { &quot;bar&quot; },\
16 fn:doc()[ foo/@bar eq $let ],\
17 //x } \
18 \
19 (: a more \'evil\' test :)\
20 (: Modified Blakeley example (: with nested comment :) ... :)\
21 declare private function local:declare() {()};\
22 declare private function local:private() {()};\
23 declare private function local:function() {()};\
24 declare private function local:local() {()};\
25 let $let := &lt;let&gt;let $let := &quot;let&quot;&lt;/let&gt;\
26 return element element {\
27 attribute attribute { try { xdmp:version() } catch($e) { xdmp:log($e) } },\
28 attribute fn:doc { &quot;bar&quot; castable as xs:string },\
29 element text { text { &quot;text&quot; } },\
30 fn:doc()[ child::eq/(@bar | attribute::attribute) eq $let ],\
31 //fn:doc\
32 }';
33 var expected = '<span class="cm-keyword">xquery</span> <span class="cm-keyword">version</span> <span class="cm-string">"1.0-ml"</span><span class="cm-variable cm-def">;</span> <span class="cm-comment">(: this is : a "comment" :)</span> <span class="cm-keyword">let</span> <span class="cm-variable">$let</span> <span class="cm-keyword">:=</span> <span class="cm-tag">&lt;x </span><span class="cm-attribute">attr</span>=<span class="cm-string">"value"</span><span class="cm-tag">&gt;</span><span class="cm-word">"test"</span><span class="cm-tag">&lt;func&gt;</span><span class="cm-word">function()</span> <span class="cm-word">$var</span> {<span class="cm-keyword">function</span>()} {<span class="cm-variable">$var</span>}<span class="cm-tag">&lt;/func&gt;&lt;/x&gt;</span> <span class="cm-keyword">let</span> <span class="cm-variable">$joe</span><span class="cm-keyword">:=</span><span class="cm-atom">1</span> <span class="cm-keyword">return</span> <span class="cm-keyword">element</span> <span class="cm-word">element</span> { <span class="cm-keyword">attribute</span> <span class="cm-word">attribute</span> { <span class="cm-atom">1</span> }, <span class="cm-keyword">element</span> <span class="cm-word">test</span> { <span class="cm-string">\'a\'</span> }, <span class="cm-keyword">attribute</span> <span class="cm-word">foo</span> { <span class="cm-string">"bar"</span> }, <span class="cm-variable cm-def">fn:doc</span>()[ <span class="cm-word">foo</span><span class="cm-keyword">/</span><span class="cm-word">@bar</span> <span class="cm-keyword">eq</span> <span class="cm-variable">$let</span> ], <span class="cm-keyword">//</span><span class="cm-word">x</span> } <span class="cm-comment">(: a more \'evil\' test :)</span> <span class="cm-comment">(: Modified Blakeley example (: with nested comment :) ... :)</span> <span class="cm-keyword">declare</span> <span class="cm-keyword">private</span> <span class="cm-keyword">function</span> <span class="cm-variable cm-def">local:declare</span>() {()}<span class="cm-word">;</span> <span class="cm-keyword">declare</span> <span class="cm-keyword">private</span> <span class="cm-keyword">function</span> <span class="cm-variable cm-def">local:private</span>() {()}<span class="cm-word">;</span> <span class="cm-keyword">declare</span> <span class="cm-keyword">private</span> <span class="cm-keyword">function</span> <span class="cm-variable cm-def">local:function</span>() {()}<span class="cm-word">;</span> <span class="cm-keyword">declare</span> <span class="cm-keyword">private</span> <span class="cm-keyword">function</span> <span class="cm-variable cm-def">local:local</span>() {()}<span class="cm-word">;</span> <span class="cm-keyword">let</span> <span class="cm-variable">$let</span> <span class="cm-keyword">:=</span> <span class="cm-tag">&lt;let&gt;</span><span class="cm-word">let</span> <span class="cm-word">$let</span> <span class="cm-word">:=</span> <span class="cm-word">"let"</span><span class="cm-tag">&lt;/let&gt;</span> <span class="cm-keyword">return</span> <span class="cm-keyword">element</span> <span class="cm-word">element</span> { <span class="cm-keyword">attribute</span> <span class="cm-word">attribute</span> { <span class="cm-keyword">try</span> { <span class="cm-variable cm-def">xdmp:version</span>() } <span class="cm-keyword">catch</span>(<span class="cm-variable">$e</span>) { <span class="cm-variable cm-def">xdmp:log</span>(<span class="cm-variable">$e</span>) } }, <span class="cm-keyword">attribute</span> <span class="cm-word">fn:doc</span> { <span class="cm-string">"bar"</span> <span class="cm-word">castable</span> <span class="cm-keyword">as</span> <span class="cm-atom">xs:string</span> }, <span class="cm-keyword">element</span> <span class="cm-word">text</span> { <span class="cm-keyword">text</span> { <span class="cm-string">"text"</span> } }, <span class="cm-variable cm-def">fn:doc</span>()[ <span class="cm-qualifier">child::</span><span class="cm-word">eq</span><span class="cm-keyword">/</span>(<span class="cm-word">@bar</span> <span class="cm-keyword">|</span> <span class="cm-qualifier">attribute::</span><span class="cm-word">attribute</span>) <span class="cm-keyword">eq</span> <span class="cm-variable">$let</span> ], <span class="cm-keyword">//</span><span class="cm-word">fn:doc</span> }';
34
35 $("#sandbox").html('<textarea id="editor">' + input + '</textarea>');
36 var editor = CodeMirror.fromTextArea($("#editor")[0]);
37 var result = $(".CodeMirror-lines div div pre")[0].innerHTML;
38
39 equal(result, expected);
40 $("#editor").html("");
41 });
42 });
diff --git a/imports/codemirror/mode/xquery/test/testEmptySequenceKeyword.js b/imports/codemirror/mode/xquery/test/testEmptySequenceKeyword.js
new file mode 100644
index 00000000..39ed0905
--- /dev/null
+++ b/imports/codemirror/mode/xquery/test/testEmptySequenceKeyword.js
@@ -0,0 +1,16 @@
1$(document).ready(function(){
2 module("testEmptySequenceKeyword");
3 test("testEmptySequenceKeyword", function() {
4 expect(1);
5
6 var input = '"foo" instance of empty-sequence()';
7 var expected = '<span class="cm-string">"foo"</span> <span class="cm-keyword">instance</span> <span class="cm-keyword">of</span> <span class="cm-keyword">empty-sequence</span>()';
8
9 $("#sandbox").html('<textarea id="editor">' + input + '</textarea>');
10 var editor = CodeMirror.fromTextArea($("#editor")[0]);
11 var result = $(".CodeMirror-lines div div pre")[0].innerHTML;
12
13 equal(result, expected);
14 $("#editor").html("");
15 });
16});
diff --git a/imports/codemirror/mode/xquery/test/testMultiAttr.js b/imports/codemirror/mode/xquery/test/testMultiAttr.js
new file mode 100644
index 00000000..8e98c47d
--- /dev/null
+++ b/imports/codemirror/mode/xquery/test/testMultiAttr.js
@@ -0,0 +1,16 @@
1 $(document).ready(function(){
2 module("testMultiAttr");
3 test("test1", function() {
4 expect(1);
5
6 var expected = '<span class="cm-tag">&lt;p </span><span class="cm-attribute">a1</span>=<span class="cm-string">"foo"</span> <span class="cm-attribute">a2</span>=<span class="cm-string">"bar"</span><span class="cm-tag">&gt;</span><span class="cm-word">hello</span> <span class="cm-word">world</span><span class="cm-tag">&lt;/p&gt;</span>';
7
8 $("#sandbox").html('<textarea id="editor"></textarea>');
9 $("#editor").html('<p a1="foo" a2="bar">hello world</p>');
10 var editor = CodeMirror.fromTextArea($("#editor")[0]);
11 var result = $(".CodeMirror-lines div div pre")[0].innerHTML;
12
13 equal(result, expected);
14 $("#editor").html("");
15 });
16 }); \ No newline at end of file
diff --git a/imports/codemirror/mode/xquery/test/testNamespaces.js b/imports/codemirror/mode/xquery/test/testNamespaces.js
new file mode 100644
index 00000000..4efea63e
--- /dev/null
+++ b/imports/codemirror/mode/xquery/test/testNamespaces.js
@@ -0,0 +1,91 @@
1$(document).ready(function(){
2 module("test namespaces");
3
4// --------------------------------------------------------------------------------
5// this test is based on this:
6//http://mbrevoort.github.com/CodeMirror2/#!exprSeqTypes/PrologExpr/VariableProlog/ExternalVariablesWith/K2-ExternalVariablesWith-10.xq
7// --------------------------------------------------------------------------------
8 test("test namespaced variable", function() {
9 expect(1);
10
11 var input = 'declare namespace e = "http://example.com/ANamespace";\
12declare variable $e:exampleComThisVarIsNotRecognized as element(*) external;';
13
14 var expected = '<span class="cm-keyword">declare</span> <span class="cm-keyword">namespace</span> <span class="cm-word">e</span> <span class="cm-keyword">=</span> <span class="cm-string">"http://example.com/ANamespace"</span><span class="cm-word">;declare</span> <span class="cm-keyword">variable</span> <span class="cm-variable">$e:exampleComThisVarIsNotRecognized</span> <span class="cm-keyword">as</span> <span class="cm-keyword">element</span>(<span class="cm-keyword">*</span>) <span class="cm-word">external;</span>';
15
16 $("#sandbox").html('<textarea id="editor">' + input + '</textarea>');
17 var editor = CodeMirror.fromTextArea($("#editor")[0]);
18 var result = $(".CodeMirror-lines div div pre")[0].innerHTML;
19
20 equal(result, expected);
21 $("#editor").html("");
22 });
23
24
25// --------------------------------------------------------------------------------
26// this test is based on:
27// http://mbrevoort.github.com/CodeMirror2/#!Basics/EQNames/eqname-002.xq
28// --------------------------------------------------------------------------------
29 test("test EQName variable", function() {
30 expect(1);
31
32 var input = 'declare variable $"http://www.example.com/ns/my":var := 12;\
33<out>{$"http://www.example.com/ns/my":var}</out>';
34
35 var expected = '<span class="cm-keyword">declare</span> <span class="cm-keyword">variable</span> <span class="cm-variable">$"http://www.example.com/ns/my":var</span> <span class="cm-keyword">:=</span> <span class="cm-atom">12</span><span class="cm-word">;</span><span class="cm-tag">&lt;out&gt;</span>{<span class="cm-variable">$"http://www.example.com/ns/my":var</span>}<span class="cm-tag">&lt;/out&gt;</span>';
36
37 $("#sandbox").html('<textarea id="editor">' + input + '</textarea>');
38 var editor = CodeMirror.fromTextArea($("#editor")[0]);
39 var result = $(".CodeMirror-lines div div pre")[0].innerHTML;
40
41 equal(result, expected);
42 $("#editor").html("");
43 });
44
45// --------------------------------------------------------------------------------
46// this test is based on:
47// http://mbrevoort.github.com/CodeMirror2/#!Basics/EQNames/eqname-003.xq
48// --------------------------------------------------------------------------------
49 test("test EQName function", function() {
50 expect(1);
51
52 var input = 'declare function "http://www.example.com/ns/my":fn ($a as xs:integer) as xs:integer {\
53 $a + 2\
54};\
55<out>{"http://www.example.com/ns/my":fn(12)}</out>';
56
57 var expected = '<span class="cm-keyword">declare</span> <span class="cm-keyword">function</span> <span class="cm-variable cm-def">"http://www.example.com/ns/my":fn</span> (<span class="cm-variable">$a</span> <span class="cm-keyword">as</span> <span class="cm-atom">xs:integer</span>) <span class="cm-keyword">as</span> <span class="cm-atom">xs:integer</span> { <span class="cm-variable">$a</span> <span class="cm-keyword">+</span> <span class="cm-atom">2</span>}<span class="cm-word">;</span><span class="cm-tag">&lt;out&gt;</span>{<span class="cm-variable cm-def">"http://www.example.com/ns/my":fn</span>(<span class="cm-atom">12</span>)}<span class="cm-tag">&lt;/out&gt;</span>';
58
59 $("#sandbox").html('<textarea id="editor">' + input + '</textarea>');
60 var editor = CodeMirror.fromTextArea($("#editor")[0]);
61 var result = $(".CodeMirror-lines div div pre")[0].innerHTML;
62
63 equal(result, expected);
64