|
From: <el...@us...> - 2011-02-25 09:52:45
|
Revision: 13846
http://exist.svn.sourceforge.net/exist/?rev=13846&view=rev
Author: ellefj
Date: 2011-02-25 09:52:38 +0000 (Fri, 25 Feb 2011)
Log Message:
-----------
[ignore] xq3 switch expression finalised. Test version 3. Also in test files.
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/xquery/SwitchExpression.java
branches/adam/eXist-xq3/test/src/xquery/xquery3/xq3_switch.xml
Added Paths:
-----------
branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/SwitchTest.java
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/SwitchExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/SwitchExpression.java 2011-02-24 20:55:49 UTC (rev 13845)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/SwitchExpression.java 2011-02-25 09:52:38 UTC (rev 13846)
@@ -27,6 +27,8 @@
import org.exist.dom.DocumentSet;
import org.exist.dom.QName;
+import org.exist.xquery.ErrorCodes.EXistErrorCode;
+import org.exist.xquery.ErrorCodes.ErrorCode;
import org.exist.xquery.functions.FunDeepEqual;
import org.exist.xquery.util.ExpressionDumper;
import org.exist.xquery.value.AtomicValue;
@@ -81,6 +83,12 @@
public Sequence eval(Sequence contextSequence, Item contextItem)
throws XPathException {
+ if(getContext().getXQueryVersion() < 30){
+ ErrorCode ec = new EXistErrorCode("EXXQDY0002", "The switch expression is supported "
+ + "for xquery version \"3.0\" and later.");
+ throw new XPathException(ec, ec.getDescription(), null);
+ }
+
if (contextItem != null)
contextSequence = contextItem.toSequence();
Item opItem = operand.eval(contextSequence).itemAt(0);
Added: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/SwitchTest.java
===================================================================
--- branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/SwitchTest.java (rev 0)
+++ branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/SwitchTest.java 2011-02-25 09:52:38 UTC (rev 13846)
@@ -0,0 +1,128 @@
+/*
+ * eXist Open Source Native XML Database
+ * Copyright (C) 2011 The eXist Project
+ * http://exist-db.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $Id$
+ */
+package org.exist.xquery.functions.xquery3;
+
+import org.junit.Ignore;
+import org.xmldb.api.base.ResourceSet;
+
+import org.exist.test.EmbeddedExistTester;
+import org.exist.xquery.ErrorCodes;
+import org.exist.xquery.XPathException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author ljo
+ */
+public class SwitchTest extends EmbeddedExistTester {
+
+ public SwitchTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ System.out.println("***********************");
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ // *******************************************
+
+ @Test
+ public void oneCaseCaseMatch() {
+ String query = "xquery version '3.0';"
+ + "let $animal := 'Cat' return"
+ + "switch ($animal)"
+ + "case 'Cow' return 'Moo'"
+ + "case 'Cat' return 'Meow'"
+ + "case 'Duck' return 'Quack'"
+ + "default return 'Odd noise!'";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+ assertEquals("Meow", r);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+
+ }
+
+ @Test
+ public void twoCaseDefault() {
+ String query = "xquery version '3.0';"
+ + "let $animal := 'Cat' return"
+ + "switch ($animal)"
+ + "case 'Cow' case 'Calf' return 'Moo'"
+ + "default return 'No Bull?'";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+ assertEquals("No Bull?", r);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+
+ }
+
+
+ @Test
+ public void twoCaseCaseMatch() {
+ String query = "xquery version '3.0';"
+ + "let $animal := 'Calf' return"
+ + "switch ($animal)"
+ + "case 'Cow' case 'Calf' return 'Moo'"
+ + "case 'Cat' return 'Meow'"
+ + "case 'Duck' return 'Quack'"
+ + "default return 'Odd noise!'";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+ assertEquals("Moo",r);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+
+ }
+}
Property changes on: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/SwitchTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: branches/adam/eXist-xq3/test/src/xquery/xquery3/xq3_switch.xml
===================================================================
--- branches/adam/eXist-xq3/test/src/xquery/xquery3/xq3_switch.xml 2011-02-24 20:55:49 UTC (rev 13845)
+++ branches/adam/eXist-xq3/test/src/xquery/xquery3/xq3_switch.xml 2011-02-25 09:52:38 UTC (rev 13846)
@@ -53,6 +53,7 @@
<task>A switch expression with all string case alternatives
</task>
<code><![CDATA[
+ xquery version "3.0";
let $animal := "Cat"
return
switch ($animal)
@@ -68,6 +69,7 @@
<task>A switch with multiple case clauses with one return
</task>
<code><![CDATA[
+ xquery version "3.0";
let $animal := "Calf"
return
switch ($animal)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|