Skip to content

Commit

Permalink
Merge pull request #24 from joewiz/fix-boolean
Browse files Browse the repository at this point in the history
Fix boolean parameter casting
  • Loading branch information
line-o authored May 15, 2023
2 parents 4382633 + c988ff3 commit c0f6e4b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions content/templates.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const existClient = createClient(connectionOptions);

const static = [
"content/*",
"test/xqs/*{.xq,.xql}"
"test/xqs/*{.xq,.xqm}"
]

// test application metadata
Expand Down
9 changes: 9 additions & 0 deletions test/app/modules/view.xql
Original file line number Diff line number Diff line change
Expand Up @@ -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')
};
Expand Down
1 change: 1 addition & 0 deletions test/app/types-fail.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<body>
<p data-template="test:numbers" class="numbers"></p>
<p data-template="test:date" class="date"></p>
<p data-template="test:boolean" class="boolean"></p>
</body>
</html>
1 change: 1 addition & 0 deletions test/app/types.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<body>
<p data-template="test:numbers" class="numbers"></p>
<p data-template="test:date" class="date"></p>
<p data-template="test:boolean" class="boolean"></p>
</body>
</html>
16 changes: 11 additions & 5 deletions test/mocha/rest_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 () {
Expand All @@ -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');
});
});
Expand All @@ -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");
});
});
Expand Down Expand Up @@ -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');
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/xqs/test-runner.xq
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
)
File renamed without changes.

0 comments on commit c0f6e4b

Please sign in to comment.