예제 #1
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));
 }
예제 #2
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"));
 }
예제 #3
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));
 }
예제 #4
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));
 }
예제 #5
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));
 }
예제 #6
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());
 }
예제 #7
0
 /**
  * Evaluates The "exactly-one" function with the arguments set as follows: $arg = xs:float(upper
  * bound) .
  */
 @org.junit.Test
 public void fnExactlyOneflt1args3() {
   final XQuery query = new XQuery("fn:exactly-one(xs:float(\"3.4028235E38\"))", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "3.4028235E38"));
 }
예제 #8
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")));
 }
예제 #9
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"));
 }
예제 #10
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));
 }
예제 #11
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));
 }
예제 #12
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));
 }
예제 #13
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"));
 }
예제 #14
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"));
 }
예제 #15
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"));
 }
예제 #16
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"));
 }
예제 #17
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"));
 }
예제 #18
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"));
 }
예제 #19
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\""));
 }
예제 #20
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"));
 }
예제 #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"));
 }
예제 #22
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"));
 }
예제 #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"));
 }
예제 #24
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")));
 }
예제 #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"));
 }
예제 #26
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"));
 }
예제 #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"));
 }
예제 #28
0
 /**
  * Evaluates The "exactly-one" function with the arguments set as follows: $arg = xs:decimal(mid
  * range) .
  */
 @org.junit.Test
 public void fnExactlyOnedec1args2() {
   final XQuery query = new XQuery("fn:exactly-one(xs:decimal(\"617375191608514839\"))", ctx);
   try {
     result = new QT3Result(query.value());
   } catch (final Throwable trw) {
     result = new QT3Result(trw);
   } finally {
     query.close();
   }
   test(assertStringValue(false, "617375191608514839"));
 }
예제 #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"));
 }
예제 #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"));
 }