Skip to content

Commit 1531ba8

Browse files
committed
[test] function types in enclosed expressions
Many new tests added as jUnit and XQSuite tests. Some of them must be skipped/ignored since they are still an issue.
1 parent 7f17e44 commit 1531ba8

File tree

2 files changed

+109
-44
lines changed

2 files changed

+109
-44
lines changed

exist-core/src/test/java/org/exist/xquery/FunctionTypeInElementContent.java

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.exist.test.ExistXmldbEmbeddedServer;
2525
import org.junit.ClassRule;
26+
import org.junit.Ignore;
2627
import org.junit.Test;
2728
import org.xmldb.api.base.XMLDBException;
2829
import org.xmldb.api.modules.XQueryService;
@@ -45,12 +46,20 @@ public void arrayLiteral() throws XMLDBException {
4546
assertCompilationSuccess(query);
4647
}
4748

49+
/**
50+
* TODO: remove empty sequence after https://github.com/eXist-db/exist/issues/3472 is fixed
51+
*/
4852
@Test
4953
public void arrayConstructor() throws XMLDBException {
5054
final String query = "element test { array { () } }";
5155
assertCompilationSuccess(query);
5256
}
5357

58+
@Test
59+
public void sequenceOfItems() throws XMLDBException {
60+
final String query = "element test { (1, map {})[1] }";
61+
assertCompilationSuccess(query);
62+
}
5463

5564
@Test
5665
public void partialBuiltIn() throws XMLDBException {
@@ -59,6 +68,31 @@ public void partialBuiltIn() throws XMLDBException {
5968
assertCompilationError(query, error);
6069
}
6170

71+
/**
72+
* TODO: Investigate does still throw without location info
73+
*/
74+
@Ignore
75+
@Test
76+
public void functionReference() throws XMLDBException {
77+
final String query = "element test { sum#0 }";
78+
final String error = "err:XQTY0105 Function types are not allowed in element content. Got function(*) [at line 1, column 16, source: element test { sum#0 }]";
79+
assertCompilationError(query, error);
80+
}
81+
82+
/**
83+
* Does not throw at compile time
84+
*/
85+
@Ignore
86+
@Test
87+
public void functionVariable() throws XMLDBException {
88+
final String query = "let $f := function () { () } return element test { $f }";
89+
final String error = "err:XQTY0105 Function types are not allowed in element content. Got function(*) [at line 1, column 16, source: element test { sum(?) }]";
90+
assertCompilationError(query, error);
91+
}
92+
93+
/**
94+
* TODO: remove empty sequence after https://github.com/eXist-db/exist/issues/3551 is fixed
95+
*/
6296
@Test
6397
public void userDefinedFunction() throws XMLDBException {
6498
final String query = "element test { function () { () } }";
@@ -74,28 +108,52 @@ public void mapConstructor() throws XMLDBException {
74108
assertCompilationError(query, error);
75109
}
76110

77-
// -- no error is thrown at compile time
78-
// @Test
79-
// public void mapConstructorInSequence() throws XMLDBException {
80-
// final String query = "element test {\n" +
81-
// " \"a\",\n" +
82-
// " map {}\n" +
83-
// "}";
84-
// final String error = "err:XQTY0105 Function types are not allowed in element content. Got map(*) [at line 1, column 14, source: element test { map {} }]";
85-
// assertCompilationError(query, error);
86-
// }
87-
88-
89-
// -- no error is thrown at compile time nor run time
90-
// @Test
91-
// public void arrayInSequence() throws XMLDBException {
92-
// final String query = "element test {\n" +
93-
// " \"a\",\n" +
94-
// " []\n" +
95-
// "}";
96-
// final String error = "err:XQTY0105 Function types are not allowed in element content. Got map(*) [at line 1, column 14, source: element test { map {} }]";
97-
// assertCompilationError(query, error);
98-
// }
111+
/**
112+
* sequence in enclosed expression with only a function type
113+
*/
114+
@Ignore
115+
@Test
116+
public void sequenceOfMaps() throws XMLDBException {
117+
final String query = "element test { (map {}) }";
118+
final String error = "An exception occurred during query execution: err:XQTY0105 Function types are not allowed in element content. Got map(*) [source: element foo { (map{}) }]";
119+
assertCompilationError(query, error);
120+
}
121+
122+
/**
123+
* there is an edge case which would evaluate to empty sequence
124+
* but should arguably still throw
125+
* Does still throw without location info
126+
* TODO: add (sub-expression) location
127+
*/
128+
@Test
129+
public void sequenceOfMapsEdgeCase() throws XMLDBException {
130+
final String query = "element test { (map {})[2] }";
131+
final String error = "err:XQTY0105 Function types are not allowed in element content. Got map(*) [source: element test { (map {})[2] }]";
132+
assertCompilationError(query, error);
133+
}
134+
135+
/**
136+
* -- no error is thrown at compile time
137+
* TODO: add (sub-expression) location
138+
*/
139+
@Test
140+
public void ArrayOfMaps() throws XMLDBException {
141+
final String query = "element test { [map {}] }";
142+
final String error = "An exception occurred during query execution: err:XQTY0105 Function types are not allowed in element content. Got map(*) [source: element test { [map{}] }]";
143+
assertCompilationError(query, error);
144+
};
145+
146+
/**
147+
* This could throw at compile time, but does not
148+
* TODO: add (sub-expression) location
149+
*/
150+
@Ignore
151+
@Test
152+
public void mapConstructorInSubExpression() throws XMLDBException {
153+
final String query = "element test { \"a\", map {} }";
154+
final String error = "err:XQTY0105 Function types are not allowed in element content. Got map(*) [at line 1, column 20, source: element test { map {} }]";
155+
assertCompilationError(query, error);
156+
}
99157

100158
private void assertCompilationError(final String query, final String error) throws XMLDBException {
101159
final XQueryService service = (XQueryService)existEmbeddedServer.getRoot().getService("XQueryService", "1.0");

exist-core/src/test/xquery/errors.xql

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -330,38 +330,45 @@ function et:issue3473c() {
330330
: related to https://github.com/eXist-db/exist/issues/3474
331331
:)
332332
declare
333-
%test:assertEquals(339)
334-
%test:pending("expression seems to swallow subexpression location")
333+
%test:assertTrue
334+
%test:pending("location info still missing")
335+
function et:subexpression-in-enclosed-expression-evaluates-to-map() {
336+
try {
337+
element test { 1, map {} }
338+
}
339+
catch err:XQTY0105 {
340+
exists($err:line-number) and
341+
$err:line-number > 0 and
342+
exists($err:column-number) and
343+
$err:column-number > 0
344+
}
345+
};
346+
347+
declare
348+
%test:assertTrue
349+
%test:pending("location info still missing")
335350
function et:enclosed-expression-evaluates-to-map() {
336351
try {
337-
element foo {
338-
(
339-
"a",
340-
map {}
341-
)[2]
342-
}
352+
element test { ( "a", map {} )[2] }
343353
}
344354
catch err:XQTY0105 {
345-
$err:line-number
355+
exists($err:line-number) and
356+
$err:line-number > 0 and
357+
exists($err:column-number) and
358+
$err:column-number > 0
346359
}
347360
};
348361

349-
(:~
350-
: sequnce in enclosed expression with only a function type
351-
: weird edge case which should evaluate to empty sequence
352-
: but should arguably still throw
353-
: related to https://github.com/eXist-db/exist/issues/3474
354-
:)
355362
declare
356-
%test:assertEquals(361)
357-
%test:pending("expression seems to swallow subexpression location")
358-
function et:enclosed-expression-edge-case() {
363+
%test:assertTrue
364+
function et:array-in-enclosed-expression-evaluates-to-map() {
359365
try {
360-
element foo {
361-
(map {})[2]
362-
}
366+
element test { [map {}] }
363367
}
364368
catch err:XQTY0105 {
365-
$err:line-number
369+
exists($err:line-number) and
370+
$err:line-number > 0 and
371+
exists($err:column-number) and
372+
$err:column-number > 0
366373
}
367374
};

0 commit comments

Comments
 (0)