updated gaps
This commit is contained in:
@@ -3,12 +3,6 @@ const CQL = ([cql]) => cds.parse.cql(cql)
|
|||||||
const Foo = { name: 'Foo' }
|
const Foo = { name: 'Foo' }
|
||||||
const Books = { name: 'capire.bookshop.Books' }
|
const Books = { name: 'capire.bookshop.Books' }
|
||||||
|
|
||||||
const is_cds_333 = cds.version >= '3.33.3'
|
|
||||||
if (!is_cds_333) {
|
|
||||||
// Monky-patching v3.33.3 features in older releases
|
|
||||||
const up = UPDATE('x').constructor.prototype
|
|
||||||
up.with = up.set
|
|
||||||
}
|
|
||||||
const { parse:cdr } = cds.ql
|
const { parse:cdr } = cds.ql
|
||||||
|
|
||||||
// while jest has 'test' as alias to 'it', mocha doesn't
|
// while jest has 'test' as alias to 'it', mocha doesn't
|
||||||
@@ -18,48 +12,37 @@ describe('cds.ql → cqn', () => {
|
|||||||
//
|
//
|
||||||
let cqn
|
let cqn
|
||||||
|
|
||||||
describe(`BUGS + GAPS...`, () => {
|
describe.skip(`BUGS + GAPS...`, () => {
|
||||||
!(cdr ? it : it.skip)('should consistently handle *', () => {
|
|
||||||
|
it('should consistently handle *', () => {
|
||||||
expect({
|
expect({
|
||||||
SELECT: { from: { ref: ['Foo'] }, columns: ['*'] },
|
SELECT: { from: { ref: ['Foo'] }, columns: ['*'] },
|
||||||
})
|
})
|
||||||
.to.eql(CQL`SELECT * from Foo`)
|
.to.eql(CQL`SELECT * from Foo`)
|
||||||
.to.eql(CQL`SELECT from Foo{*}`)
|
.to.eql(CQL`SELECT from Foo{*}`)
|
||||||
.to.eql(SELECT('*').from(Foo))
|
.to.eql(SELECT('*').from(Foo))
|
||||||
.to.eql(SELECT.from(Foo, ['*']))
|
.to.eql(SELECT.from(Foo,['*']))
|
||||||
})
|
})
|
||||||
|
|
||||||
!(cdr ? it : it.skip)('should correctly handle { ... and:{...} }', () => {
|
|
||||||
expect(SELECT.from(Foo).where({ x: 1, and: { y: 2, or: { z: 3 } } })).to.eql({
|
it('should consistently handle lists', () => {
|
||||||
SELECT: {
|
const ID = 11, args = [`foo`, "'bar'", 3]
|
||||||
from: { ref: ['Foo'] },
|
const cqn = CQL`SELECT from Foo where ID=11 and x in (foo,'bar',3)`
|
||||||
where: [
|
expect(SELECT.from(Foo).where(`ID=${ID} and x in (${args})`)).to.eql(cqn)
|
||||||
{ ref: ['x'] },
|
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqn)
|
||||||
'=',
|
expect(SELECT.from(Foo).where({ ID, x:args })).to.eql(cqn)
|
||||||
{ val: 1 },
|
|
||||||
'and',
|
|
||||||
'(',
|
|
||||||
{ ref: ['y'] },
|
|
||||||
'=',
|
|
||||||
{ val: 2 },
|
|
||||||
'or',
|
|
||||||
{ ref: ['z'] },
|
|
||||||
'=',
|
|
||||||
{ val: 3 },
|
|
||||||
')',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
describe(`SELECT...`, () => {
|
describe(`SELECT...`, () => {
|
||||||
test('from ( Foo )', () => {
|
test('from ( Foo )', () => {
|
||||||
expect({
|
expect({
|
||||||
SELECT: { from: { ref: ['Foo'] } },
|
SELECT: { from: { ref: ['Foo'] } },
|
||||||
})
|
})
|
||||||
.to.eql(CQL`SELECT from Foo`)
|
.to.eql(CQL`SELECT from Foo`)
|
||||||
.to.eql(SELECT.from(Foo))
|
.to.eql(SELECT.from(Foo))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('from ( ..., <key>)', () => {
|
test('from ( ..., <key>)', () => {
|
||||||
@@ -181,9 +164,8 @@ describe('cds.ql → cqn', () => {
|
|||||||
columns: [{ ref: ['a'] }, { ref: ['b'] }, cdr ? '*' : { ref: ['*'] }],
|
columns: [{ ref: ['a'] }, { ref: ['b'] }, cdr ? '*' : { ref: ['*'] }],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
is_cds_333 &&
|
|
||||||
test('from ( ..., => _.expand ( x=>{...}))', () => {
|
test('from ( ..., => _.expand ( x=>{...}))', () => {
|
||||||
// SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } }
|
// SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } }
|
||||||
expect(
|
expect(
|
||||||
@@ -211,7 +193,6 @@ describe('cds.ql → cqn', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
is_cds_333 &&
|
|
||||||
test('from ( ..., => _.inline ( _=>{...}))', () => {
|
test('from ( ..., => _.inline ( _=>{...}))', () => {
|
||||||
// SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } }
|
// SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } }
|
||||||
expect(
|
expect(
|
||||||
@@ -260,7 +241,30 @@ describe('cds.ql → cqn', () => {
|
|||||||
// same for works distinct
|
// same for works distinct
|
||||||
})
|
})
|
||||||
|
|
||||||
test.skip('where ( ... cql | {x:y} )', () => {
|
it('should correctly handle { ... and:{...} }', () => {
|
||||||
|
expect(SELECT.from(Foo).where({ x: 1, and: { y: 2, or: { z: 3 } } })).to.eql({
|
||||||
|
SELECT: {
|
||||||
|
from: { ref: ['Foo'] },
|
||||||
|
where: [
|
||||||
|
{ ref: ['x'] },
|
||||||
|
'=',
|
||||||
|
{ val: 1 },
|
||||||
|
'and',
|
||||||
|
'(',
|
||||||
|
{ ref: ['y'] },
|
||||||
|
'=',
|
||||||
|
{ val: 2 },
|
||||||
|
'or',
|
||||||
|
{ ref: ['z'] },
|
||||||
|
'=',
|
||||||
|
{ val: 3 },
|
||||||
|
')',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('where ( ... cql | {x:y} )', () => {
|
||||||
const args = [`foo`, "'bar'", 3]
|
const args = [`foo`, "'bar'", 3]
|
||||||
const ID = 11
|
const ID = 11
|
||||||
|
|
||||||
@@ -297,7 +301,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
')',
|
')',
|
||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
'(', //> this one is not required
|
// '(', //> this one is not required
|
||||||
{ ref: ['ID'] },
|
{ ref: ['ID'] },
|
||||||
'=',
|
'=',
|
||||||
{ val: ID },
|
{ val: ID },
|
||||||
@@ -306,7 +310,7 @@ describe('cds.ql → cqn', () => {
|
|||||||
'in',
|
'in',
|
||||||
{ val: args },
|
{ val: args },
|
||||||
'and',
|
'and',
|
||||||
// '(', //> this one is missing, and that's changing the logic -> that's a BUG
|
'(', //> this one is missing, and that's changing the logic -> that's a BUG
|
||||||
{ ref: ['x'] },
|
{ ref: ['x'] },
|
||||||
'like',
|
'like',
|
||||||
{ val: '%x%' },
|
{ val: '%x%' },
|
||||||
@@ -340,8 +344,6 @@ describe('cds.ql → cqn', () => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqn)
|
|
||||||
expect(SELECT.from(Foo).where(`ID=${ID} and x in (${args})`)).to.eql(cqn)
|
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
SELECT.from(Foo).where(`x=`, 1, `or y.z is null and (a>`, 2, `or b=`, 3, `)`)
|
SELECT.from(Foo).where(`x=`, 1, `or y.z is null and (a>`, 2, `or b=`, 3, `)`)
|
||||||
|
|||||||
Reference in New Issue
Block a user