|
|
@@ -1,77 +1,64 @@ |
|
|
// Initiate ModeTest and set defaults |
|
|
var MT = ModeTest; |
|
|
MT.modeName = "xquery"; |
|
|
MT.modeOptions = {}; |
|
|
// Don't take these too seriously -- the expected results appear to be |
|
|
// based on the results of actual runs without any serious manual |
|
|
// verification. If a change you made causes them to fail, the test is |
|
|
// as likely to wrong as the code. |
|
|
|
|
|
MT.testMode("eviltest", |
|
|
'xquery version "1.0-ml";\ |
|
|
(: this is\ |
|
|
: a \ |
|
|
"comment" :)\ |
|
|
let $let := <x attr="value">"test"<func>function() $var {function()} {$var}</func></x>\ |
|
|
let $joe:=1\ |
|
|
return element element {\ |
|
|
attribute attribute { 1 },\ |
|
|
element test { 'a' }, \ |
|
|
attribute foo { "bar" },\ |
|
|
fn:doc()[ foo/@bar eq $let ],\ |
|
|
//x } \ |
|
|
\ |
|
|
(: a more \'evil\' test :)\ |
|
|
(: Modified Blakeley example (: with nested comment :) ... :)\ |
|
|
declare private function local:declare() {()};\ |
|
|
declare private function local:private() {()};\ |
|
|
declare private function local:function() {()};\ |
|
|
declare private function local:local() {()};\ |
|
|
let $let := <let>let $let := "let"</let>\ |
|
|
return element element {\ |
|
|
attribute attribute { try { xdmp:version() } catch($e) { xdmp:log($e) } },\ |
|
|
attribute fn:doc { "bar" castable as xs:string },\ |
|
|
element text { text { "text" } },\ |
|
|
fn:doc()[ child::eq/(@bar | attribute::attribute) eq $let ],\ |
|
|
//fn:doc\ |
|
|
}', ["keyword","xquery",null," ","keyword","version",null," ","variable",""1","keyword",".","atom","0","keyword","-","variable","ml"","def variable",";",null," ","comment","(: this is : a \"comment\" :)",null," ","keyword","let",null," ","variable","$let",null," ","keyword",":=",null," ","variable","<x",null," ","variable","attr","keyword","=","variable",""value">"test"<func>","def variable",";function","","()",null," ","variable","$var",null," ","","{","keyword","function","","()}",null," ","","{","variable","$var","","}","variable","<","keyword","/","variable","func><","keyword","/","variable","x>",null," ","keyword","let",null," ","variable","$joe","keyword",":=","atom","1",null," ","keyword","return",null," ","keyword","element",null," ","variable","element",null," ","","{",null," ","keyword","attribute",null," ","variable","attribute",null," ","","{",null," ","atom","1",null," ","","},",null," ","keyword","element",null," ","variable","test",null," ","","{",null," ","variable","'a'",null," ","","},",null," ","keyword","attribute",null," ","variable","foo",null," ","","{",null," ","variable",""bar"",null," ","","},",null," ","def variable","fn:doc","","()[",null," ","variable","foo","keyword","/","variable","@bar",null," ","keyword","eq",null," ","variable","$let",null," ","","],",null," ","keyword","//","variable","x",null," ","","}",null," ","comment","(: a more 'evil' test :)",null," ","comment","(: Modified Blakeley example (: with nested comment :) ... :)",null," ","keyword","declare",null," ","keyword","private",null," ","keyword","function",null," ","def variable","local:declare","","()",null," ","","{()}","variable",";",null," ","keyword","declare",null," ","keyword","private",null," ","keyword","function",null," ","def variable","local:private","","()",null," ","","{()}","variable",";",null," ","keyword","declare",null," ","keyword","private",null," ","keyword","function",null," ","def variable","local:function","","()",null," ","","{()}","variable",";",null," ","keyword","declare",null," ","keyword","private",null," ","keyword","function",null," ","def variable","local:local","","()",null," ","","{()}","variable",";",null," ","keyword","let",null," ","variable","$let",null," ","keyword",":=",null," ","variable","<let>let",null," ","variable","$let",null," ","keyword",":=",null," ","variable",""let"<","keyword","/let","variable",">",null," ","keyword","return",null," ","keyword","element",null," ","variable","element",null," ","","{",null," ","keyword","attribute",null," ","variable","attribute",null," ","","{",null," ","keyword","try",null," ","","{",null," ","def variable","xdmp:version","","()",null," ","","}",null," ","keyword","catch","","(","variable","$e","",")",null," ","","{",null," ","def variable","xdmp:log","","(","variable","$e","",")",null," ","","}",null," ","","},",null," ","keyword","attribute",null," ","variable","fn:doc",null," ","","{",null," ","variable",""bar"",null," ","variable","castable",null," ","keyword","as",null," ","atom","xs:string",null," ","","},",null," ","keyword","element",null," ","variable","text",null," ","","{",null," ","keyword","text",null," ","","{",null," ","variable",""text"",null," ","","}",null," ","","},",null," ","def variable","fn:doc","","()[",null," ","qualifier","child::","variable","eq","keyword","/","","(","variable","@bar",null," ","keyword","|",null," ","qualifier","attribute::","variable","attribute","",")",null," ","keyword","eq",null," ","variable","$let",null," ","","],",null," ","keyword","//","variable","fn:doc",null," ","","}"]); |
|
|
(function() { |
|
|
var mode = CodeMirror.getMode({tabSize: 4}, "xquery"); |
|
|
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } |
|
|
|
|
|
MT.testMode("testEmptySequenceKeyword", |
|
|
'"foo" instance of empty-sequence()', |
|
|
["string","\"foo\"",null," ","keyword","instance",null," ","keyword","of",null," ","keyword","empty-sequence","","()"]); |
|
|
MT("eviltest", |
|
|
"[keyword xquery] [keyword version] [variable "1][keyword .][atom 0][keyword -][variable ml"][def&variable ;] [comment (: this is : a \"comment\" :)]", |
|
|
" [keyword let] [variable $let] [keyword :=] [variable <x] [variable attr][keyword =][variable "value">"test"<func>][def&variable ;function]() [variable $var] {[keyword function]()} {[variable $var]}[variable <][keyword /][variable func><][keyword /][variable x>]", |
|
|
" [keyword let] [variable $joe][keyword :=][atom 1]", |
|
|
" [keyword return] [keyword element] [variable element] {", |
|
|
" [keyword attribute] [variable attribute] { [atom 1] },", |
|
|
" [keyword element] [variable test] { [variable 'a'] }, [keyword attribute] [variable foo] { [variable "bar"] },", |
|
|
" [def&variable fn:doc]()[[ [variable foo][keyword /][variable @bar] [keyword eq] [variable $let] ]],", |
|
|
" [keyword //][variable x] } [comment (: a more 'evil' test :)]", |
|
|
" [comment (: Modified Blakeley example (: with nested comment :) ... :)]", |
|
|
" [keyword declare] [keyword private] [keyword function] [def&variable local:declare]() {()}[variable ;]", |
|
|
" [keyword declare] [keyword private] [keyword function] [def&variable local:private]() {()}[variable ;]", |
|
|
" [keyword declare] [keyword private] [keyword function] [def&variable local:function]() {()}[variable ;]", |
|
|
" [keyword declare] [keyword private] [keyword function] [def&variable local:local]() {()}[variable ;]", |
|
|
" [keyword let] [variable $let] [keyword :=] [variable <let>let] [variable $let] [keyword :=] [variable "let"<][keyword /let][variable >]", |
|
|
" [keyword return] [keyword element] [variable element] {", |
|
|
" [keyword attribute] [variable attribute] { [keyword try] { [def&variable xdmp:version]() } [keyword catch]([variable $e]) { [def&variable xdmp:log]([variable $e]) } },", |
|
|
" [keyword attribute] [variable fn:doc] { [variable "bar"] [variable castable] [keyword as] [atom xs:string] },", |
|
|
" [keyword element] [variable text] { [keyword text] { [variable "text"] } },", |
|
|
" [def&variable fn:doc]()[[ [qualifier child::][variable eq][keyword /]([variable @bar] [keyword |] [qualifier attribute::][variable attribute]) [keyword eq] [variable $let] ]],", |
|
|
" [keyword //][variable fn:doc]", |
|
|
" }"); |
|
|
|
|
|
MT("testEmptySequenceKeyword", |
|
|
"[string \"foo\"] [keyword instance] [keyword of] [keyword empty-sequence]()"); |
|
|
|
|
|
MT.testMode("testMultiAttr", |
|
|
'<p a1="foo" a2="bar">hello world</p>', |
|
|
["tag","<p ","attribute","a1","","=","string","\"foo\"",null," ","attribute","a2","","=","string","\"bar\"","tag",">","variable","hello",null," ","variable","world","tag","</p>"]); |
|
|
MT("testMultiAttr", |
|
|
"[tag <p ][attribute a1]=[string \"foo\"] [attribute a2]=[string \"bar\"][tag >][variable hello] [variable world][tag </p>]"); |
|
|
|
|
|
MT.testMode("test namespaced variable", |
|
|
'declare namespace e = "http://example.com/ANamespace";\ |
|
|
declare variable $e:exampleComThisVarIsNotRecognized as element(*) external;', |
|
|
["keyword","declare",null," ","keyword","namespace",null," ","variable","e",null," ","keyword","=",null," ","string","\"http://example.com/ANamespace\"","variable",";declare",null," ","keyword","variable",null," ","variable","$e:exampleComThisVarIsNotRecognized",null," ","keyword","as",null," ","keyword","element","","(","keyword","*","",")",null," ","variable","external;"]); |
|
|
MT("test namespaced variable", |
|
|
"[keyword declare] [keyword namespace] [variable e] [keyword =] [string \"http://example.com/ANamespace\"][variable ;declare] [keyword variable] [variable $e:exampleComThisVarIsNotRecognized] [keyword as] [keyword element]([keyword *]) [variable external;]"); |
|
|
|
|
|
MT.testMode("test EQName variable", |
|
|
'declare variable $"http://www.example.com/ns/my":var := 12;\ |
|
|
<out>{$"http://www.example.com/ns/my":var}</out>', |
|
|
["keyword","declare",null," ","keyword","variable",null," ","variable","$\"http://www.example.com/ns/my\":var",null," ","keyword",":=",null," ","atom","12","variable",";","tag","<out>","","{","variable","$\"http://www.example.com/ns/my\":var","","}","tag","</out>"]); |
|
|
MT("test EQName variable", |
|
|
"[keyword declare] [keyword variable] [variable $\"http://www.example.com/ns/my\":var] [keyword :=] [atom 12][variable ;]", |
|
|
"[tag <out>]{[variable $\"http://www.example.com/ns/my\":var]}[tag </out>]"); |
|
|
|
|
|
MT.testMode("test EQName function", |
|
|
'declare function "http://www.example.com/ns/my":fn ($a as xs:integer) as xs:integer {\ |
|
|
$a + 2\ |
|
|
};\ |
|
|
<out>{"http://www.example.com/ns/my":fn(12)}</out>', |
|
|
["keyword","declare",null," ","keyword","function",null," ","def variable","\"http://www.example.com/ns/my\":fn",null," ","","(","variable","$a",null," ","keyword","as",null," ","atom","xs:integer","",")",null," ","keyword","as",null," ","atom","xs:integer",null," ","","{",null," ","variable","$a",null," ","keyword","+",null," ","atom","2","","}","variable",";","tag","<out>","","{","def variable","\"http://www.example.com/ns/my\":fn","","(","atom","12","",")}","tag","</out>"]); |
|
|
MT("test EQName function", |
|
|
"[keyword declare] [keyword function] [def&variable \"http://www.example.com/ns/my\":fn] ([variable $a] [keyword as] [atom xs:integer]) [keyword as] [atom xs:integer] {", |
|
|
" [variable $a] [keyword +] [atom 2]", |
|
|
"}[variable ;]", |
|
|
"[tag <out>]{[def&variable \"http://www.example.com/ns/my\":fn]([atom 12])}[tag </out>]"); |
|
|
|
|
|
MT.testMode("test EQName function with single quotes", |
|
|
'declare function \'http://www.example.com/ns/my\':fn ($a as xs:integer) as xs:integer {\ |
|
|
$a + 2\ |
|
|
};\ |
|
|
<out>{\'http://www.example.com/ns/my\':fn(12)}</out>', |
|
|
["keyword","declare",null," ","keyword","function",null," ","def variable","'http://www.example.com/ns/my':fn",null," ","","(","variable","$a",null," ","keyword","as",null," ","atom","xs:integer","",")",null," ","keyword","as",null," ","atom","xs:integer",null," ","","{",null," ","variable","$a",null," ","keyword","+",null," ","atom","2","","}","variable",";","tag","<out>","","{","def variable","'http://www.example.com/ns/my':fn","","(","atom","12","",")}","tag","</out>"]); |
|
|
MT("test EQName function with single quotes", |
|
|
"[keyword declare] [keyword function] [def&variable 'http://www.example.com/ns/my':fn] ([variable $a] [keyword as] [atom xs:integer]) [keyword as] [atom xs:integer] {", |
|
|
" [variable $a] [keyword +] [atom 2]", |
|
|
"}[variable ;]", |
|
|
"[tag <out>]{[def&variable 'http://www.example.com/ns/my':fn]([atom 12])}[tag </out>]"); |
|
|
|
|
|
MT.testMode("testProcessingInstructions", |
|
|
'data(<?target content?>) instance of xs:string', |
|
|
["def variable","data","","(","comment meta","<?target content?>","",")",null," ","keyword","instance",null," ","keyword","of",null," ","atom","xs:string"]); |
|
|
MT("testProcessingInstructions", |
|
|
"[def&variable data]([comment&meta <?target content?>]) [keyword instance] [keyword of] [atom xs:string]"); |
|
|
|
|
|
MT.testMode("testQuoteEscapeDouble", |
|
|
'let $rootfolder := "c:\\builds\\winnt\\HEAD\\qa\\scripts\\"\ |
|
|
let $keysfolder := concat($rootfolder, "keys\\")\ |
|
|
return\ |
|
|
$keysfolder', |
|
|
["keyword","let",null," ","variable","$rootfolder",null," ","keyword",":=",null," ","string","\"c:\\builds\\winnt\\HEAD\\qa\\scripts\\\"","keyword","let",null," ","variable","$keysfolder",null," ","keyword",":=",null," ","def variable","concat","","(","variable","$rootfolder","",",",null," ","string","\"keys\\\"","",")","variable","return$keysfolder"]); |
|
|
MT("testQuoteEscapeDouble", |
|
|
"[keyword let] [variable $rootfolder] [keyword :=] [string \"c:\\builds\\winnt\\HEAD\\qa\\scripts\\\"]", |
|
|
"[keyword let] [variable $keysfolder] [keyword :=] [def&variable concat]([variable $rootfolder], [string \"keys\\\"])"); |
|
|
})(); |