diff --git a/content/templates.xqm b/content/templates.xqm index f3fe689..e284161 100644 --- a/content/templates.xqm +++ b/content/templates.xqm @@ -358,6 +358,8 @@ declare %private function templates:cast($values as item()*, $targetType as xs:s xs:dateTime($value) case "xs:time" return xs:time($value) + case "xs:boolean" return + xs:boolean($value) case "element()" return parse-xml($value)/* case "text()" return diff --git a/gulpfile.js b/gulpfile.js index 393062c..3b776b2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -31,7 +31,7 @@ const existClient = createClient(connectionOptions); const static = [ "content/*", - "test/xqs/*{.xq,.xql}" + "test/xqs/*{.xq,.xqm}" ] // test application metadata diff --git a/test/app/modules/view.xql b/test/app/modules/view.xql index 380f6d3..7140182 100644 --- a/test/app/modules/view.xql +++ b/test/app/modules/view.xql @@ -98,6 +98,15 @@ function test:date($node as node(), $model as map(*), $date as xs:date) { day-from-date($date) }; +declare + %templates:wrap +function test:boolean($node as node(), $model as map(*), $boolean as xs:boolean) { + if ($boolean instance of xs:boolean) then + "yes" + else + "no" +}; + declare function test:custom-model($node as node(), $model as map(*)) { $model?('my-model-item') }; diff --git a/test/app/types-fail.html b/test/app/types-fail.html index f50a724..9a06044 100644 --- a/test/app/types-fail.html +++ b/test/app/types-fail.html @@ -5,5 +5,6 @@

+

\ No newline at end of file diff --git a/test/app/types.html b/test/app/types.html index f50a724..9a06044 100644 --- a/test/app/types.html +++ b/test/app/types.html @@ -5,5 +5,6 @@

+

\ No newline at end of file diff --git a/test/mocha/rest_spec.js b/test/mocha/rest_spec.js index 3791ef4..e0587ff 100644 --- a/test/mocha/rest_spec.js +++ b/test/mocha/rest_spec.js @@ -88,7 +88,8 @@ describe('expand HTML template types.html', function () { params: { n1: 20, n2: 30.25, - date: '2021-02-07+01:00' + date: '2021-02-07+01:00', + boolean: 'true' } }); const { window } = new JSDOM(res.data); @@ -109,6 +110,10 @@ describe('expand HTML template types.html', function () { it('converts dates', async function () { expect(document.querySelector('p.date').innerHTML).to.equal('7'); }); + + it('converts booleans', async function () { + expect(document.querySelector('p.boolean').innerHTML).to.equal('yes'); + }); }); describe('expand HTML template types-fail.html', function () { @@ -118,11 +123,12 @@ describe('expand HTML template types-fail.html', function () { params: { n1: 'abc', n2: 30.25, - date: '2021-02-07+01:00' + date: '2021-02-07+01:00', + boolean: 'true' } }) .catch(error => { - expect(error.response.status).to.equal(400); + expect(error.response.status).to.be.oneOf([400, 500]); expect(error.response.data).to.contain('templates:TypeError'); }); }); @@ -134,7 +140,7 @@ describe('expand HTML template missing-tmpl.html', function () { it("reports missing template functions", async function () { return axiosInstance.get("missing-tmpl.html") .catch((error) => { - expect(error.response.status).to.equal(400); + expect(error.response.status).to.be.oneOf([400, 500]); expect(error.response.data).to.contain("templates:NotFound"); }); }); @@ -296,7 +302,7 @@ describe('Fail if template is missing', function() { it('fails if template could not be found', function () { return axiosInstance.get('template-missing.html') .catch(error => { - expect(error.response.status).to.equal(400); + expect(error.response.status).to.be.oneOf([400, 500]); expect(error.response.data).to.contain('templates:NotFound'); }); }); diff --git a/test/xqs/test-runner.xq b/test/xqs/test-runner.xq index ab9b0fe..ae89eee 100644 --- a/test/xqs/test-runner.xq +++ b/test/xqs/test-runner.xq @@ -7,12 +7,12 @@ xquery version "3.1"; : @see http://www.exist-db.org/exist/apps/doc/xqsuite :) import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql"; -import module namespace tests="http://exist-db.org/templating/tests" at "test-suite.xql"; +import module namespace tests="http://exist-db.org/templating/tests" at "test-suite.xqm"; declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; declare option output:method "json"; declare option output:media-type "application/json"; test:suite( - inspect:module-functions(xs:anyURI("test-suite.xql")) + inspect:module-functions(xs:anyURI("test-suite.xqm")) ) diff --git a/test/xqs/test-suite.xql b/test/xqs/test-suite.xqm similarity index 100% rename from test/xqs/test-suite.xql rename to test/xqs/test-suite.xqm