Exemplo n.º 1
0
 /**
  * A prolog containing many different declarations. TODO function declarations missing TODO
  * variable declarations missing .
  */
 @org.junit.Test
 public void kVersionProlog5V3() {
   final XQuery query =
       new XQuery(
           "\n"
               + "        xquery version \"3.0\" encoding \"ISO-8859-1\"; \n"
               + "        declare boundary-space preserve; \n"
               + "        declare default collation \"http://www.w3.org/2005/xpath-functions/collation/codepoint\"; \n"
               + "        declare base-uri \"http://example.com/\"; \n"
               + "        declare construction strip; \n"
               + "        declare ordering ordered; \n"
               + "        declare default order empty greatest; \n"
               + "        declare copy-namespaces no-preserve, no-inherit; \n"
               + "        declare namespace ex = \"http://example.com/a/Namespace\"; \n"
               + "        declare default element namespace \"http://example.com/\"; \n"
               + "        declare default function namespace \"http://example.com/\"; \n"
               + "        declare option fn:x-notRecognized \"option content\"; \n"
               + "        1 eq 1",
           ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertBoolean(true));
 }
Exemplo n.º 2
0
 /** A more realitic query with a version decl, no encoding. . */
 @org.junit.Test
 public void prologVersion7V3() {
   final XQuery query =
       new XQuery(
           "\n"
               + "        xquery version \"3.0\"; \n"
               + "        declare boundary-space preserve; \n"
               + "        declare default order empty greatest; \n"
               + "        declare namespace ns = \"http://www.example.org/\"; \n"
               + "        for $b in //book stable order by xs:decimal($b/price[1]) empty greatest \n"
               + "        return $b/title",
           ctx);
   try {
     query.context(node(file("op/union/bib2.xml")));
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(
       assertSerialization(
           "<title>Data on the Web</title><title>TCP/IP Illustrated</title><title>Advanced Programming in the Unix environment</title><title>The Economics of Technology and Content for Digital TV</title>",
           false));
 }
Exemplo n.º 3
0
 /** Higher Order Functions fold-left function. Count the number of words in a sentence.. */
 @org.junit.Test
 public void foldLeft018() {
   final XQuery query =
       new XQuery(
           "\n"
               + "let $text := \"Peter Piper picked a peck of pickled peppers A peck of pickled peppers Peter Piper picked\"\n"
               + "let $tokens := tokenize($text, '\\s')\n"
               + "let $counter := function($result, $word){\n"
               + "  let $word-count := $result[@value = $word]\n"
               + "  return\n"
               + "    if(empty($word-count)) then\n"
               + "      ($result, <word value=\"{$word}\" count=\"1\" />)\n"
               + "    else\n"
               + "    (\n"
               + "      $result except $word-count,\n"
               + "      <word value=\"{$word-count/@value}\" count=\"{number($word-count/@count) + 1}\" />\n"
               + "    )\n"
               + "}\n"
               + "let $words := fold-left($counter, (), $tokens)\n"
               + "return (\n"
               + "  number($words[@value=\"Peter\"]/@count),\n"
               + "  number($words[@value=\"Piper\"]/@count),\n"
               + "  number($words[@value=\"pickled\"]/@count)\n"
               + ")\n"
               + "",
           ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertDeepEq("2, 2, 2"));
 }
Exemplo n.º 4
0
 /** A very simple string-difference function. . */
 @org.junit.Test
 public void k2FunctionCallExpr11() {
   final XQuery query =
       new XQuery(
           "\n"
               + "        declare function local:compare($arg1 as xs:string, $arg2 as xs:string) { \n"
               + "            let $cps1 := string-to-codepoints($arg1), \n"
               + "            $cps2 := string-to-codepoints($arg2) \n"
               + "            return abs(count($cps1) - count($cps2)) + sum(for $x in 1 to min((count($cps1), count($cps2))) \n"
               + "                                                          return if ($cps1[$x] ne $cps2[$x]) then 1 else ()) }; \n"
               + "        local:compare(\"\", \"\"), \n"
               + "        local:compare(\"a\", \"\"), \n"
               + "        local:compare(\"\", \"a\"), \n"
               + "        local:compare(\"a\", \"a\"), \n"
               + "        local:compare(\"\", \"aa\"), \n"
               + "        local:compare(\"aa\", \"ab\"), \n"
               + "        local:compare(\"ba\", \"ba\"), \n"
               + "        local:compare(\"bab\", \"bbb\"), \n"
               + "        local:compare(\"aba\", \"bab\")\n"
               + "     ",
           ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "0 1 1 0 2 1 0 1 3"));
 }
Exemplo n.º 5
0
 /** . */
 @org.junit.Test
 public void treeQueriesResultsQ6() {
   final XQuery query =
       new XQuery(
           "\n"
               + "        declare function local:section-summary($book-or-section as element()*) as element()* { \n"
               + "            for $section in $book-or-section \n"
               + "            return <section> { $section/@* } { $section/title } <figcount> { count($section/figure) } </figcount> { local:section-summary($section/section) } </section> \n"
               + "        }; \n"
               + "        <toc> { \n"
               + "            for $s in /book/section \n"
               + "            return local:section-summary($s) \n"
               + "        } </toc>\n"
               + "      ",
           ctx);
   try {
     query.context(node(file("docs/book.xml")));
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(
       assertSerialization(
           "<toc><section id=\"intro\" difficulty=\"easy\"><title>Introduction</title><figcount>0</figcount><section><title>Audience</title><figcount>0</figcount></section><section><title>Web Data and the Two Cultures</title><figcount>1</figcount></section></section><section id=\"syntax\" difficulty=\"medium\"><title>A Syntax For Data</title><figcount>1</figcount><section><title>Base Types</title><figcount>0</figcount></section><section><title>Representing Relational Databases</title><figcount>1</figcount></section><section><title>Representing Object Databases</title><figcount>0</figcount></section></section></toc>",
           false));
 }
Exemplo n.º 6
0
 /** fold-left-009 author Michael Kay, Saxonica implement eg:distinct-nodes-stable() . */
 @org.junit.Test
 public void foldLeft009() {
   final XQuery query =
       new XQuery(
           "\n"
               + "            declare function local:distinct-nodes-stable($seq as node()*) { \n"
               + "                fold-left( function($foundSoFar as node()*, $this as node()) as node()* { \n"
               + "                if ($foundSoFar intersect $this) \n"
               + "                then $foundSoFar \n"
               + "                else ($foundSoFar, $this) }, (), $seq) \n"
               + "            }; \n"
               + "            let $nodes := (<a/>, <b/>, <c/>, <d/>, <e/>, <f/>) \n"
               + "            let $perm := ($nodes[1], $nodes[2], $nodes[4], $nodes[1], $nodes[2], $nodes[3], $nodes[2], $nodes[1]) \n"
               + "            return local:distinct-nodes-stable($perm)/local-name()\n"
               + "      ",
           ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "a b d c"));
 }
Exemplo n.º 7
0
 /**
  * No function by name fn:format-number() exists in XQuery 1.0 (although one does in XSLT and in
  * XQuery 3.0). .
  */
 @org.junit.Test
 public void kFunctionCallExpr15a() {
   final XQuery query = new XQuery("format-number(3, \"0000\")", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertEq("\"0003\""));
 }
Exemplo n.º 8
0
 /** Test that arguments are atomized - built in function. */
 @org.junit.Test
 public void functionCall001() {
   final XQuery query = new XQuery("concat(<a>X</a>, <a>Y</a>)", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "XY"));
 }
Exemplo n.º 9
0
 /** Evaluation of an "fn:codepoint-equal" whose arguments use fn:string() for a string. . */
 @org.junit.Test
 public void fnCodepointEqual9() {
   final XQuery query = new XQuery("fn:codepoint-equal(fn:string(\"aa\"),fn:string(\"aa\"))", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertBoolean(true));
 }
Exemplo n.º 10
0
 /**
  * Evaluates The "exactly-one" function with the arguments set as follows: $arg = xs:integer(mid
  * range) .
  */
 @org.junit.Test
 public void fnExactlyOneintg1args2() {
   final XQuery query = new XQuery("fn:exactly-one(xs:integer(\"830993497117024304\"))", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "830993497117024304"));
 }
Exemplo n.º 11
0
 /** A function call containing an invalid QName as name. . */
 @org.junit.Test
 public void kFunctionCallExpr6() {
   final XQuery query = new XQuery("f:f:()", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test((error("XPST0003") || error("XPST0081")));
 }
Exemplo n.º 12
0
 /** No function by name fn:sub-sequence() exists(although one by name fn:subsequence does). . */
 @org.junit.Test
 public void kFunctionCallExpr28() {
   final XQuery query = new XQuery("fn:sub-sequence(\"http:/example.com/\", 1, 1)", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(error("XPST0017"));
 }
Exemplo n.º 13
0
 /** Function by name fn:generate-id() does exist in XQuery 3.0. . */
 @org.junit.Test
 public void kFunctionCallExpr25a() {
   final XQuery query = new XQuery("generate-id(<a/>) castable as xs:NCName", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertBoolean(true));
 }
Exemplo n.º 14
0
 /** A test whose essence is: `exactly-one(error())`. . */
 @org.junit.Test
 public void kSeqExactlyOneFunc6() {
   final XQuery query = new XQuery("exactly-one(error())", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(error("FOER0000"));
 }
Exemplo n.º 15
0
 /**
  * Evaluates The "exactly-one" function with the arguments set as follows: $arg =
  * xs:unsignedShort(upper bound) .
  */
 @org.junit.Test
 public void fnExactlyOneusht1args3() {
   final XQuery query = new XQuery("fn:exactly-one(xs:unsignedShort(\"65535\"))", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "65535"));
 }
Exemplo n.º 16
0
 /** A test whose essence is: `count(exactly-one( "one" )) eq 1`. . */
 @org.junit.Test
 public void kSeqExactlyOneFunc5() {
   final XQuery query = new XQuery("count(exactly-one( \"one\" )) eq 1", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertBoolean(true));
 }
Exemplo n.º 17
0
 /**
  * Evaluates The "exactly-one" function with the arguments set as follows: $arg =
  * xs:unsignedLong(upper bound) .
  */
 @org.junit.Test
 public void fnExactlyOneulng1args3() {
   final XQuery query = new XQuery("fn:exactly-one(xs:unsignedLong(\"184467440737095516\"))", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "184467440737095516"));
 }
Exemplo n.º 18
0
 /**
  * Evaluates The "exactly-one" function with the arguments set as follows: $arg =
  * xs:positiveInteger(lower bound) .
  */
 @org.junit.Test
 public void fnExactlyOnepint1args1() {
   final XQuery query = new XQuery("fn:exactly-one(xs:positiveInteger(\"1\"))", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "1"));
 }
Exemplo n.º 19
0
 /**
  * Evaluates The "exactly-one" function with the arguments set as follows: $arg = xs:long(upper
  * bound) .
  */
 @org.junit.Test
 public void fnExactlyOnelng1args3() {
   final XQuery query = new XQuery("fn:exactly-one(xs:long(\"92233720368547758\"))", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "92233720368547758"));
 }
Exemplo n.º 20
0
 /** Test that arguments are atomized - constructor function. */
 @org.junit.Test
 public void functionCall002() {
   final XQuery query = new XQuery("xs:boolean(<a>0</a>)", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertBoolean(false));
 }
Exemplo n.º 21
0
 /** No function by name fn:unparsed-entity-uri() exists(although one does in XSLT). . */
 @org.junit.Test
 public void kFunctionCallExpr23() {
   final XQuery query = new XQuery("unparsed-entity-uri(\"example.com/file.ext\")", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(error("XPST0017"));
 }
Exemplo n.º 22
0
 /** Error XTDE1340 component in picture string not available in value. */
 @org.junit.Test
 public void formatTime817err() {
   final XQuery query = new XQuery("format-time(current-time(), '[bla]', 'en', (), ())", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test((error("XTDE1340") || error("FOFD1340")));
 }
Exemplo n.º 23
0
 /** No function by name fn:system-property() exists(although one does in XSL-T). . */
 @org.junit.Test
 public void kFunctionCallExpr26() {
   final XQuery query = new XQuery("system-property(\"xsl:vendor\")", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(error("XPST0017"));
 }
Exemplo n.º 24
0
 /** Function unparsed-entity-public-id() is not available in XQuery. . */
 @org.junit.Test
 public void k2FunctionCallExpr5() {
   final XQuery query = new XQuery("unparsed-entity-public-id(\"str\")", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(error("XPST0017"));
 }
Exemplo n.º 25
0
 /** A test whose essence is: `prefix-does-not-exist:func-does-not-exist(1, 2, 3)`. . */
 @org.junit.Test
 public void kFunctionCallExpr5() {
   final XQuery query = new XQuery("prefix-does-not-exist:func-does-not-exist(1, 2, 3)", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(error("XPST0081"));
 }
Exemplo n.º 26
0
 /**
  * Evaluation of an "fn:codepoint-equal" with one argument set to empty sequence Use fn:count to
  * avoid empty file. .
  */
 @org.junit.Test
 public void fnCodepointEqual2b() {
   final XQuery query = new XQuery("fn:codepoint-equal((), \"\")", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertEmpty());
 }
Exemplo n.º 27
0
 /** wrong number of args to format-time(). */
 @org.junit.Test
 public void formatTimeInptEr3() {
   final XQuery query = new XQuery("format-time(current-time(), '[bla]', 'en', (), (), 6)", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(error("XPST0017"));
 }
Exemplo n.º 28
0
 /**
  * Evaluates The "exactly-one" function with the arguments set as follows: $arg = xs:int(upper
  * bound) .
  */
 @org.junit.Test
 public void fnExactlyOneint1args3() {
   final XQuery query = new XQuery("fn:exactly-one(xs:int(\"2147483647\"))", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "2147483647"));
 }
Exemplo n.º 29
0
 /** Function key() is not available in XQuery. . */
 @org.junit.Test
 public void k2FunctionCallExpr9() {
   final XQuery query = new XQuery("key(\"id\")", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(error("XPST0017"));
 }
Exemplo n.º 30
0
 /** Evaluation of an "fn:codepoint-equal" with wrong argument type (only second argument). . */
 @org.junit.Test
 public void fnCodepointEqual11() {
   final XQuery query = new XQuery("fn:codepoint-equal(\"aa\",xs:integer(1))", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(error("XPTY0004"));
 }