use of org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr in project webtools.sourceediting by eclipse.
the class ForExprWithoutTest method test_ForExpr005.
// For+Return - use sequence(security/right) as the predicate.
public void test_ForExpr005() throws Exception {
String inputFile = "/TestSources/fsx.xml";
String xqFile = "/Queries/XQuery/Expressions/FLWORExpr/ForExpr/ForExpr005.xq";
String resultFile = "/ExpectedTestResults/Expressions/FLWORExpr/ForExpr/ForExpr005.xml";
String expectedResult = getExpectedResult(resultFile);
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
actual = buildXMLResultString(rs);
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertXMLEqual("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr in project webtools.sourceediting by eclipse.
the class ForExprWithoutTest method test_ForExpr014.
// Incorrect syntax for nested loop. Multiple return statements at the same level.
public void test_ForExpr014() throws Exception {
String inputFile = "/TestSources/fsx.xml";
String xqFile = "/Queries/XQuery/Expressions/FLWORExpr/ForExpr/ForExpr014.xq";
String expectedResult = "XPST0003";
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
actual = buildResultString(rs);
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr in project webtools.sourceediting by eclipse.
the class ForExprWithoutTest method test_ForExpr020.
// Multiple variable bindings followed by a trailing ,.
public void test_ForExpr020() throws Exception {
String inputFile = "/TestSources/fsx.xml";
String xqFile = "/Queries/XQuery/Expressions/FLWORExpr/ForExpr/ForExpr020.xq";
String expectedResult = "XPST0003";
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
actual = buildResultString(rs);
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr in project webtools.sourceediting by eclipse.
the class TestWTPDOMXPath2 method test_ForExpr005.
public void test_ForExpr005() throws Exception {
String inputFile = "/TestSources/fsx.xml";
String xqFile = "/Queries/XQuery/Expressions/FLWORExpr/ForExpr/ForExpr005.xq";
String resultFile = "/ExpectedTestResults/Expressions/FLWORExpr/ForExpr/ForExpr005.xml";
String expectedResult = getExpectedResult(resultFile);
URL fileURL = bundle.getEntry(inputFile);
super.domDoc = load(fileURL);
DynamicContext dc = setupDynamicContext(null);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
XPath path = compileXPath(dc, xpath);
Evaluator eval = new DefaultEvaluator(dc, domDoc);
ResultSequence rs = eval.evaluate(path);
actual = buildXMLResultString(rs);
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertXMLEqual("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr in project webtools.sourceediting by eclipse.
the class Normalizer method visit.
/**
* @param fex
* is the For expression.
* @return fex expression.
*/
public Object visit(ForExpr fex) {
ForExpr last = fex;
Expr ret = fex.expr();
int depth = 0;
for (Iterator i = fex.iterator(); i.hasNext(); ) {
VarExprPair ve = (VarExprPair) i.next();
// ok we got nested fors...
if (depth > 0) {
Collection pairs = new ArrayList();
pairs.add(ve);
ForExpr fe = new ForExpr(pairs, ret);
last.set_expr(fe);
last = fe;
}
depth++;
}
// normalize return value, and set it to the last for expr
ret.accept(this);
// get rid of the pairs in the parent (original) for
if (depth > 1)
fex.truncate_pairs();
return fex;
}
Aggregations