コード例 #1
0
ファイル: ProdVersionDecl.java プロジェクト: runeengh/basex
 /**
  * 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));
 }
コード例 #2
0
ファイル: ProdVersionDecl.java プロジェクト: runeengh/basex
 /** 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));
 }
コード例 #3
0
ファイル: FnFoldLeft.java プロジェクト: JohnLeM/basex
 /** 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"));
 }
コード例 #4
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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"));
 }
コード例 #5
0
ファイル: AppUseCaseTREE.java プロジェクト: phspaelti/basex
 /** . */
 @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));
 }
コード例 #6
0
ファイル: FnFoldLeft.java プロジェクト: JohnLeM/basex
 /** 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"));
 }
コード例 #7
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /**
  * 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\""));
 }
コード例 #8
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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"));
 }
コード例 #9
0
ファイル: FnCodepointEqual.java プロジェクト: phspaelti/basex
 /** 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));
 }
コード例 #10
0
ファイル: FnExactlyOne.java プロジェクト: fpapai/basex
 /**
  * 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"));
 }
コード例 #11
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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")));
 }
コード例 #12
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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"));
 }
コード例 #13
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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));
 }
コード例 #14
0
ファイル: FnExactlyOne.java プロジェクト: fpapai/basex
 /** 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"));
 }
コード例 #15
0
ファイル: FnExactlyOne.java プロジェクト: fpapai/basex
 /**
  * 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"));
 }
コード例 #16
0
ファイル: FnExactlyOne.java プロジェクト: fpapai/basex
 /** 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));
 }
コード例 #17
0
ファイル: FnExactlyOne.java プロジェクト: fpapai/basex
 /**
  * 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"));
 }
コード例 #18
0
ファイル: FnExactlyOne.java プロジェクト: fpapai/basex
 /**
  * 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"));
 }
コード例 #19
0
ファイル: FnExactlyOne.java プロジェクト: fpapai/basex
 /**
  * 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"));
 }
コード例 #20
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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));
 }
コード例 #21
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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
ファイル: FnFormatTime.java プロジェクト: fpapai/basex
 /** 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")));
 }
コード例 #23
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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"));
 }
コード例 #25
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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
ファイル: FnCodepointEqual.java プロジェクト: phspaelti/basex
 /**
  * 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());
 }
コード例 #27
0
ファイル: FnFormatTime.java プロジェクト: fpapai/basex
 /** 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
ファイル: FnExactlyOne.java プロジェクト: fpapai/basex
 /**
  * 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"));
 }
コード例 #29
0
ファイル: ProdFunctionCall.java プロジェクト: phspaelti/basex
 /** 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
ファイル: FnCodepointEqual.java プロジェクト: phspaelti/basex
 /** 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"));
 }