Skip to content

Commit

Permalink
test: Add tests for computed elements (#787)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Vogel <31311694+johannes-vogel@users.noreply.github.com>
  • Loading branch information
BobdenOs and johannes-vogel authored Sep 2, 2024
1 parent 7b4f8ae commit f70abcb
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion db-service/lib/cqn4sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ function cqn4sql(originalQuery, model) {
res = getTransformedTokenStream([value], baseLink)[0]
} else if (xpr) {
res = { xpr: getTransformedTokenStream(value.xpr, baseLink) }
} else if (val) {
} else if (val !== undefined) {
res = { val }
} else if (func) {
res = { args: getTransformedFunctionArgs(value.args, baseLink), func: value.func }
Expand Down
30 changes: 30 additions & 0 deletions test/compliance/resources/db/complex/computed.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace complex.computed;

entity static {
value : Integer;
integer : Integer = 1;
double : Double = 0.1;
string : String = '';
}

entity dynamic {
integer : Integer;
@(Core.Computed: true,readonly)
![case] : String = (
case
when
integer = 0
then
'zero'
when
integer = 1
then
'one'
when
integer = 2
then
'two'
end
);
lambda : String = (integer = 0 ? 'none' : 'some')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = [
{
integer: 0,
'=case': 'zero',
'=lambda': 'none',
},
{
integer: 1,
'=case': 'one',
'=lambda': 'some',
},
{
integer: 2,
'=case': 'two',
'=lambda': 'some',
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = [
{
'=integer': 1,
'=double': 0.1,
'=string': '',
}
]
1 change: 1 addition & 0 deletions test/compliance/resources/db/complex/index.cds
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace complex;

using from './computed';
using from './associations';
using from './associationsUnmanaged';

0 comments on commit f70abcb

Please sign in to comment.