-
-
Notifications
You must be signed in to change notification settings - Fork 189
[feature] XQuery 4.0 type coercion rules #6260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joewiz
wants to merge
2
commits into
eXist-db:develop
Choose a base branch
from
joewiz:feature/xq4-type-promotion
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
exist-core/src/test/xquery/xquery3/xq4-type-promotion-gating.xql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| (: | ||
| : eXist-db Open Source Native XML Database | ||
| : Copyright (C) 2001 The eXist-db Authors | ||
| : | ||
| : info@exist-db.org | ||
| : http://www.exist-db.org | ||
| : | ||
| : This library 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.1 of the License, or (at your option) any later version. | ||
| : | ||
| : This library 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 library; if not, write to the Free Software | ||
| : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| :) | ||
| xquery version "3.1"; | ||
|
|
||
| module namespace tpg="http://exist-db.org/xquery/test/type-promotion-gating"; | ||
|
|
||
| declare namespace test="http://exist-db.org/xquery/xqsuite"; | ||
|
|
||
| (: Helper function that expects xs:anyURI :) | ||
| declare function tpg:expect-uri($uri as xs:anyURI) as xs:string { | ||
| string($uri) | ||
| }; | ||
|
|
||
| (: In XQuery 3.1, string -> anyURI coercion should NOT work :) | ||
| declare | ||
| %test:assertError("XPTY0004") | ||
| function tpg:string-to-anyuri-rejected-in-31() { | ||
| tpg:expect-uri("http://example.com") | ||
| }; |
111 changes: 111 additions & 0 deletions
111
exist-core/src/test/xquery/xquery3/xq4-type-promotion.xql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| (: | ||
| : eXist-db Open Source Native XML Database | ||
| : Copyright (C) 2001 The eXist-db Authors | ||
| : | ||
| : info@exist-db.org | ||
| : http://www.exist-db.org | ||
| : | ||
| : This library 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.1 of the License, or (at your option) any later version. | ||
| : | ||
| : This library 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 library; if not, write to the Free Software | ||
| : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| :) | ||
| xquery version "4.0"; | ||
|
|
||
| module namespace tp="http://exist-db.org/xquery/test/type-promotion"; | ||
|
|
||
| declare namespace test="http://exist-db.org/xquery/xqsuite"; | ||
|
|
||
| (: Helper function that expects xs:anyURI :) | ||
| declare function tp:expect-uri($uri as xs:anyURI) as xs:string { | ||
| string($uri) | ||
| }; | ||
|
|
||
| (: Helper function that expects xs:base64Binary :) | ||
| declare function tp:expect-base64($val as xs:base64Binary) as xs:string { | ||
| string($val) | ||
| }; | ||
|
|
||
| (: Helper function that expects xs:hexBinary :) | ||
| declare function tp:expect-hex($val as xs:hexBinary) as xs:string { | ||
| string($val) | ||
| }; | ||
|
|
||
| (: Helper function that expects xs:decimal :) | ||
| declare function tp:expect-decimal($val as xs:decimal) as xs:decimal { | ||
| $val | ||
| }; | ||
|
|
||
| (: === xs:string -> xs:anyURI implicit casting === :) | ||
|
|
||
| declare | ||
| %test:assertEquals("http://example.com") | ||
| function tp:string-to-anyuri-coercion() { | ||
| tp:expect-uri("http://example.com") | ||
| }; | ||
|
|
||
| declare | ||
| %test:assertEquals("") | ||
| function tp:empty-string-to-anyuri() { | ||
| tp:expect-uri("") | ||
| }; | ||
|
|
||
| (: === xs:hexBinary <-> xs:base64Binary implicit casting === :) | ||
|
|
||
| declare | ||
| %test:assertEquals("AQID") | ||
| function tp:hex-to-base64-coercion() { | ||
| tp:expect-base64(xs:hexBinary("010203")) | ||
| }; | ||
|
|
||
| declare | ||
| %test:assertEquals("010203") | ||
| function tp:base64-to-hex-coercion() { | ||
| tp:expect-hex(xs:base64Binary("AQID")) | ||
| }; | ||
|
|
||
| (: === Bidirectional numeric implicit casting === :) | ||
|
|
||
| declare | ||
| %test:assertEquals(3.14) | ||
| function tp:double-to-decimal-coercion() { | ||
| tp:expect-decimal(3.14e0) | ||
| }; | ||
|
|
||
| (: === Relabeling: derived atomic types (§3.4.1 item 6) === :) | ||
|
|
||
| (: Helper function that expects xs:positiveInteger :) | ||
| declare function tp:expect-positive-integer($val as xs:positiveInteger) as xs:integer { | ||
| $val | ||
| }; | ||
|
|
||
| declare | ||
| %test:assertEquals(42) | ||
| function tp:integer-to-positive-integer-relabeling() { | ||
| tp:expect-positive-integer(42) | ||
| }; | ||
|
|
||
| declare | ||
| %test:assertError("XPTY0004") | ||
| function tp:negative-integer-to-positive-integer-fails() { | ||
| tp:expect-positive-integer(-5) | ||
| }; | ||
|
|
||
| (: === Version gating: ensure coercion only works in XQ4 === :) | ||
| (: These tests run in this 4.0 module, so they should pass :) | ||
|
|
||
| declare | ||
| %test:assertTrue | ||
| function tp:string-to-anyuri-instance-check() { | ||
| let $result := tp:expect-uri("test") | ||
| return $result instance of xs:string | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.