Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 283214 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/xml/xpath2/processor/testsuite/core/CondExprTest.java (-23 / +24 lines)
Lines 26-32 Link Here
26
      String inputFile = "/TestSources/emptydoc.xml";
26
      String inputFile = "/TestSources/emptydoc.xml";
27
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr006.xq";
27
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr006.xq";
28
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr006.xml";
28
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr006.xml";
29
      String expectedResult = getExpectedResult(resultFile);
29
      String expectedResult = getExpectedResult(resultFile, "out");
30
      URL fileURL = bundle.getEntry(inputFile);
30
      URL fileURL = bundle.getEntry(inputFile);
31
      loadDOMDocument(fileURL);
31
      loadDOMDocument(fileURL);
32
      
32
      
Lines 35-41 Link Here
35
35
36
      DynamicContext dc = setupDynamicContext(schema);
36
      DynamicContext dc = setupDynamicContext(schema);
37
37
38
      String xpath = "if (1 != 0) then if (4 != 5) then 1 else 2 else 3";
38
      String xpath = extractXPathExpression(xqFile, inputFile, "out");
39
      String actual = null;
39
      String actual = null;
40
      try {
40
      try {
41
	   	  XPath path = compileXPath(dc, xpath);
41
	   	  XPath path = compileXPath(dc, xpath);
Lines 43-50 Link Here
43
	      Evaluator eval = new DefaultEvaluator(dc, domDoc);
43
	      Evaluator eval = new DefaultEvaluator(dc, domDoc);
44
	      ResultSequence rs = eval.evaluate(path);
44
	      ResultSequence rs = eval.evaluate(path);
45
         
45
         
46
          actual = "<out>" + buildResultString(rs) + "</out>";
46
	      actual = buildResultString(rs);
47
	
47
	      
48
      } catch (XPathParserException ex) {
48
      } catch (XPathParserException ex) {
49
    	 actual = ex.code();
49
    	 actual = ex.code();
50
      } catch (StaticError ex) {
50
      } catch (StaticError ex) {
Lines 63-69 Link Here
63
      String inputFile = "/TestSources/emptydoc.xml";
63
      String inputFile = "/TestSources/emptydoc.xml";
64
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr010.xq";
64
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr010.xq";
65
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr010.xml";
65
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr010.xml";
66
      String expectedResult = getExpectedResult(resultFile);
66
      String expectedResult = getExpectedResult(resultFile, "out");
67
      URL fileURL = bundle.getEntry(inputFile);
67
      URL fileURL = bundle.getEntry(inputFile);
68
      loadDOMDocument(fileURL);
68
      loadDOMDocument(fileURL);
69
      
69
      
Lines 72-78 Link Here
72
72
73
      DynamicContext dc = setupDynamicContext(schema);
73
      DynamicContext dc = setupDynamicContext(schema);
74
74
75
      String xpath = "if (2 != 4) then 1 else 0";
75
      String xpath = extractXPathExpression(xqFile, inputFile, "out");
76
      String actual = null;
76
      String actual = null;
77
      try {
77
      try {
78
	   	  XPath path = compileXPath(dc, xpath);
78
	   	  XPath path = compileXPath(dc, xpath);
Lines 80-87 Link Here
80
	      Evaluator eval = new DefaultEvaluator(dc, domDoc);
80
	      Evaluator eval = new DefaultEvaluator(dc, domDoc);
81
	      ResultSequence rs = eval.evaluate(path);
81
	      ResultSequence rs = eval.evaluate(path);
82
         
82
         
83
          actual = "<out>" + buildResultString(rs) + "</out>";
83
	      actual = buildResultString(rs);
84
	
84
	      
85
      } catch (XPathParserException ex) {
85
      } catch (XPathParserException ex) {
86
    	 actual = ex.code();
86
    	 actual = ex.code();
87
      } catch (StaticError ex) {
87
      } catch (StaticError ex) {
Lines 100-106 Link Here
100
      String inputFile = "/TestSources/emptydoc.xml";
100
      String inputFile = "/TestSources/emptydoc.xml";
101
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr011.xq";
101
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr011.xq";
102
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr011.xml";
102
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr011.xml";
103
      String expectedResult = getExpectedResult(resultFile);
103
      String expectedResult = getExpectedResult(resultFile, "out");
104
      URL fileURL = bundle.getEntry(inputFile);
104
      URL fileURL = bundle.getEntry(inputFile);
105
      loadDOMDocument(fileURL);
105
      loadDOMDocument(fileURL);
106
      
106
      
Lines 109-115 Link Here
109
109
110
      DynamicContext dc = setupDynamicContext(schema);
110
      DynamicContext dc = setupDynamicContext(schema);
111
111
112
      String xpath = "fn:string-length(if (2 != 3) then 'foo' else 'expanded-foo')";
112
      String xpath = extractXPathExpression(xqFile, inputFile, "out");
113
      String actual = null;
113
      String actual = null;
114
      try {
114
      try {
115
	   	  XPath path = compileXPath(dc, xpath);
115
	   	  XPath path = compileXPath(dc, xpath);
Lines 117-124 Link Here
117
	      Evaluator eval = new DefaultEvaluator(dc, domDoc);
117
	      Evaluator eval = new DefaultEvaluator(dc, domDoc);
118
	      ResultSequence rs = eval.evaluate(path);
118
	      ResultSequence rs = eval.evaluate(path);
119
         
119
         
120
          actual = "<out>" + buildResultString(rs) + "</out>";
120
	      actual = buildResultString(rs);
121
	
121
	      
122
      } catch (XPathParserException ex) {
122
      } catch (XPathParserException ex) {
123
    	 actual = ex.code();
123
    	 actual = ex.code();
124
      } catch (StaticError ex) {
124
      } catch (StaticError ex) {
Lines 137-143 Link Here
137
      String inputFile = "/TestSources/xq311A.xml";
137
      String inputFile = "/TestSources/xq311A.xml";
138
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr012.xq";
138
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr012.xq";
139
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr012.xml";
139
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr012.xml";
140
      String expectedResult = getExpectedResult(resultFile);
140
      String expectedResult = getExpectedResult(resultFile, "out");
141
      URL fileURL = bundle.getEntry(inputFile);
141
      URL fileURL = bundle.getEntry(inputFile);
142
      loadDOMDocument(fileURL);
142
      loadDOMDocument(fileURL);
143
      
143
      
Lines 146-152 Link Here
146
146
147
      DynamicContext dc = setupDynamicContext(schema);
147
      DynamicContext dc = setupDynamicContext(schema);
148
148
149
      String xpath = extractXPathExpression(xqFile, inputFile);
149
      String xpath = extractXPathExpression(xqFile, inputFile, "out");
150
      String actual = null;
150
      String actual = null;
151
      try {
151
      try {
152
	   	  XPath path = compileXPath(dc, xpath);
152
	   	  XPath path = compileXPath(dc, xpath);
Lines 174-180 Link Here
174
      String inputFile = "/TestSources/xq311A.xml";
174
      String inputFile = "/TestSources/xq311A.xml";
175
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr013.xq";
175
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr013.xq";
176
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr013.xml";
176
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr013.xml";
177
      String expectedResult = getExpectedResult(resultFile);
177
      String expectedResult = getExpectedResult(resultFile, "out");
178
      URL fileURL = bundle.getEntry(inputFile);
178
      URL fileURL = bundle.getEntry(inputFile);
179
      loadDOMDocument(fileURL);
179
      loadDOMDocument(fileURL);
180
      
180
      
Lines 183-189 Link Here
183
183
184
      DynamicContext dc = setupDynamicContext(schema);
184
      DynamicContext dc = setupDynamicContext(schema);
185
185
186
      String xpath = extractXPathExpression(xqFile, inputFile);
186
      String xpath = extractXPathExpression(xqFile, inputFile, "out");
187
      String actual = null;
187
      String actual = null;
188
      try {
188
      try {
189
	   	  XPath path = compileXPath(dc, xpath);
189
	   	  XPath path = compileXPath(dc, xpath);
Lines 211-217 Link Here
211
      String inputFile = "/TestSources/xq311A.xml";
211
      String inputFile = "/TestSources/xq311A.xml";
212
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr014.xq";
212
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr014.xq";
213
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr014.xml";
213
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr014.xml";
214
      String expectedResult = getExpectedResult(resultFile);
214
      String expectedResult = getExpectedResult(resultFile, "out");
215
      URL fileURL = bundle.getEntry(inputFile);
215
      URL fileURL = bundle.getEntry(inputFile);
216
      loadDOMDocument(fileURL);
216
      loadDOMDocument(fileURL);
217
      
217
      
Lines 220-226 Link Here
220
220
221
      DynamicContext dc = setupDynamicContext(schema);
221
      DynamicContext dc = setupDynamicContext(schema);
222
222
223
      String xpath = extractXPathExpression(xqFile, inputFile);
223
      String xpath = extractXPathExpression(xqFile, inputFile, "out");
224
      String actual = null;
224
      String actual = null;
225
      try {
225
      try {
226
	   	  XPath path = compileXPath(dc, xpath);
226
	   	  XPath path = compileXPath(dc, xpath);
Lines 248-254 Link Here
248
      String inputFile = "/TestSources/emptydoc.xml";
248
      String inputFile = "/TestSources/emptydoc.xml";
249
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr015.xq";
249
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr015.xq";
250
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr015.xml";
250
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr015.xml";
251
      String expectedResult = getExpectedResult(resultFile);
251
      String expectedResult = getExpectedResult(resultFile, "out");
252
      URL fileURL = bundle.getEntry(inputFile);
252
      URL fileURL = bundle.getEntry(inputFile);
253
      loadDOMDocument(fileURL);
253
      loadDOMDocument(fileURL);
254
      
254
      
Lines 257-263 Link Here
257
257
258
      DynamicContext dc = setupDynamicContext(schema);
258
      DynamicContext dc = setupDynamicContext(schema);
259
259
260
      String xpath = extractXPathExpression(xqFile, inputFile);
260
      String xpath = extractXPathExpression(xqFile, inputFile, "out");
261
      String actual = null;
261
      String actual = null;
262
      try {
262
      try {
263
	   	  XPath path = compileXPath(dc, xpath);
263
	   	  XPath path = compileXPath(dc, xpath);
Lines 322-328 Link Here
322
      String inputFile = "/TestSources/fsx.xml";
322
      String inputFile = "/TestSources/fsx.xml";
323
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr017.xq";
323
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr017.xq";
324
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr017.xml";
324
      String resultFile = "/ExpectedTestResults/Expressions/CondExpr/CondExpr017.xml";
325
      String expectedResult = getExpectedResult(resultFile);
325
      String expectedResult = getExpectedResult(resultFile, "out");
326
      URL fileURL = bundle.getEntry(inputFile);
326
      URL fileURL = bundle.getEntry(inputFile);
327
      loadDOMDocument(fileURL);
327
      loadDOMDocument(fileURL);
328
      
328
      
Lines 331-337 Link Here
331
331
332
      DynamicContext dc = setupDynamicContext(schema);
332
      DynamicContext dc = setupDynamicContext(schema);
333
333
334
      String xpath = extractXPathExpression(xqFile, inputFile);
334
      String xpath = extractXPathExpression(xqFile, inputFile, "out");
335
335
      String actual = null;
336
      String actual = null;
336
      try {
337
      try {
337
	   	  XPath path = compileXPath(dc, xpath);
338
	   	  XPath path = compileXPath(dc, xpath);
Lines 354-360 Link Here
354
355
355
   }
356
   }
356
357
357
   //If where branches return different valid types.
358
//If where branches return different valid types.
358
   public void test_CondExpr018() throws Exception {
359
   public void test_CondExpr018() throws Exception {
359
      String inputFile = "/TestSources/fsx.xml";
360
      String inputFile = "/TestSources/fsx.xml";
360
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr018.xq";
361
      String xqFile = "/Queries/XQuery/Expressions/CondExpr/CondExpr018.xq";
(-)src/org/eclipse/wst/xml/xpath2/processor/test/AbstractPsychoPathTest.java (-2 / +34 lines)
Lines 217-222 Link Here
217
		return content;
217
		return content;
218
	}
218
	}
219
219
220
	public String unwrapResult(String expectedResult, String elemName) {
221
		return trimSurrounding(expectedResult, "<"+ elemName + ">", "</" + elemName + ">");
222
	}
223
	
224
	protected String getExpectedResult(String resultFile, String elemName) {
225
		return unwrapResult(getExpectedResult(resultFile), elemName);
226
	}
227
220
	public String extractXPathExpression(String xqFile, String inputFile) {
228
	public String extractXPathExpression(String xqFile, String inputFile) {
221
		// get the xpath2 expr from xq file, first
229
		// get the xpath2 expr from xq file, first
222
		char[] cbuf = new char[2048];//
230
		char[] cbuf = new char[2048];//
Lines 247-254 Link Here
247
			//
255
			//
248
			assertTrue(content.lastIndexOf(S_COMMENT2) != -1);// assert to get
256
			assertTrue(content.lastIndexOf(S_COMMENT2) != -1);// assert to get
249
			xpath2Expr = content.substring(content.lastIndexOf(S_COMMENT2) + 2)
257
			xpath2Expr = content.substring(content.lastIndexOf(S_COMMENT2) + 2)
250
					.trim();
258
					.trim();			
251
252
			xqreader.close();
259
			xqreader.close();
253
			isxq.close();
260
			isxq.close();
254
		} catch (IOException e) {
261
		} catch (IOException e) {
Lines 258-263 Link Here
258
		return xpath2Expr;
265
		return xpath2Expr;
259
	}
266
	}
260
267
268
	protected String extractXPathExpression(String xqFile, String inputFile,
269
			String tagName) {
270
		return unwrapQuery(extractXPathExpression(xqFile, inputFile), tagName);
271
	}
272
273
	protected String unwrapQuery(String xpath2Expr, String tag) {
274
		String str = "<" + tag + ">";
275
		String endStr = "</" + tag + ">";
276
		String withoutTag = trimSurrounding(xpath2Expr, str, endStr);
277
		if (withoutTag != xpath2Expr) {
278
			// also trim off the braces { }
279
			xpath2Expr = trimSurrounding(withoutTag, "{", "}");
280
		}
281
		return xpath2Expr;
282
	}
283
284
	protected String trimSurrounding(String xpath2Expr, String str, String endStr) {
285
		int indexOfStart = xpath2Expr.indexOf(str);
286
		int indexOfEnd = xpath2Expr.indexOf(endStr);
287
		if (indexOfStart >= 0 && indexOfEnd >= 0) {
288
			xpath2Expr = xpath2Expr.substring(indexOfStart + str.length(), indexOfEnd).trim(); 
289
		}
290
		return xpath2Expr;
291
	}
292
261
	protected void setupNamespace(String content) {
293
	protected void setupNamespace(String content) {
262
		Pattern p = Pattern.compile(REGEX_DN);
294
		Pattern p = Pattern.compile(REGEX_DN);
263
		Matcher m = p.matcher(content);
295
		Matcher m = p.matcher(content);

Return to bug 283214