mirror of https://github.com/AMT-Cheif/drift.git
[bugfix/aggregate_test] - Bugfix feature - Add More Aggregate Test for bool
This commit is contained in:
parent
ea78e1b16f
commit
9dbcdc9599
|
@ -7,6 +7,7 @@ void main() {
|
|||
const foo = CustomExpression<int>('foo', precedence: Precedence.primary);
|
||||
const b1 = CustomExpression<BigInt>('b1', precedence: Precedence.primary);
|
||||
const s1 = CustomExpression<String>('s1', precedence: Precedence.primary);
|
||||
const p1 = CustomExpression<bool>('p1', precedence: Precedence.primary);
|
||||
|
||||
group('count', () {
|
||||
test('all', () {
|
||||
|
@ -26,18 +27,24 @@ void main() {
|
|||
countAll(filter: s1.equals('STRING_VALUE')),
|
||||
generates('COUNT(*) FILTER (WHERE s1 = ?)', ['STRING_VALUE']),
|
||||
);
|
||||
expect(
|
||||
countAll(filter: p1.equals(true)),
|
||||
generates('COUNT(*) FILTER (WHERE p1 = ?)', [1]),
|
||||
);
|
||||
});
|
||||
|
||||
test('single', () {
|
||||
expect(foo.count(), generates('COUNT(foo)'));
|
||||
expect(b1.count(), generates('COUNT(b1)'));
|
||||
expect(s1.count(), generates('COUNT(s1)'));
|
||||
expect(p1.count(), generates('COUNT(p1)'));
|
||||
});
|
||||
|
||||
test('single - distinct', () {
|
||||
expect(foo.count(distinct: true), generates('COUNT(DISTINCT foo)'));
|
||||
expect(b1.count(distinct: true), generates('COUNT(DISTINCT b1)'));
|
||||
expect(s1.count(distinct: true), generates('COUNT(DISTINCT s1)'));
|
||||
expect(p1.count(distinct: true), generates('COUNT(DISTINCT p1)'));
|
||||
});
|
||||
|
||||
test('single - filter', () {
|
||||
|
@ -53,6 +60,10 @@ void main() {
|
|||
s1.count(filter: s1.equals('STRING_VALUE')),
|
||||
generates('COUNT(s1) FILTER (WHERE s1 = ?)', ['STRING_VALUE']),
|
||||
);
|
||||
expect(
|
||||
p1.count(filter: p1.equals(true)),
|
||||
generates('COUNT(p1) FILTER (WHERE p1 = ?)', [1]),
|
||||
);
|
||||
});
|
||||
|
||||
test('single - distinct and filter', () {
|
||||
|
@ -70,6 +81,10 @@ void main() {
|
|||
s1.count(distinct: true, filter: s1.equals('STRING_VALUE')),
|
||||
generates('COUNT(DISTINCT s1) FILTER (WHERE s1 = ?)', ['STRING_VALUE']),
|
||||
);
|
||||
expect(
|
||||
p1.count(distinct: true, filter: p1.equals(true)),
|
||||
generates('COUNT(DISTINCT p1) FILTER (WHERE p1 = ?)', [1]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -87,12 +102,14 @@ void main() {
|
|||
expect(foo.max(), generates('MAX(foo)'));
|
||||
expect(b1.max(), generates('MAX(b1)'));
|
||||
expect(s1.max(), generates('MAX(s1)'));
|
||||
expect(p1.max(), generates('MAX(p1)'));
|
||||
});
|
||||
|
||||
test('min', () {
|
||||
expect(foo.min(), generates('MIN(foo)'));
|
||||
expect(b1.min(), generates('MIN(b1)'));
|
||||
expect(s1.min(), generates('MIN(s1)'));
|
||||
expect(p1.min(), generates('MIN(p1)'));
|
||||
});
|
||||
|
||||
test('sum', () {
|
||||
|
@ -110,10 +127,12 @@ void main() {
|
|||
expect(foo.groupConcat(), generates('GROUP_CONCAT(foo)'));
|
||||
expect(b1.groupConcat(), generates('GROUP_CONCAT(b1)'));
|
||||
expect(s1.groupConcat(), generates('GROUP_CONCAT(s1)'));
|
||||
expect(p1.groupConcat(), generates('GROUP_CONCAT(p1)'));
|
||||
|
||||
expect(foo.groupConcat(separator: ','), generates('GROUP_CONCAT(foo)'));
|
||||
expect(b1.groupConcat(separator: ','), generates('GROUP_CONCAT(b1)'));
|
||||
expect(s1.groupConcat(separator: ','), generates('GROUP_CONCAT(s1)'));
|
||||
expect(p1.groupConcat(separator: ','), generates('GROUP_CONCAT(p1)'));
|
||||
});
|
||||
|
||||
test('with a custom separator', () {
|
||||
|
@ -123,6 +142,8 @@ void main() {
|
|||
generates('GROUP_CONCAT(b1, ?)', [' and ']));
|
||||
expect(s1.groupConcat(separator: ' and '),
|
||||
generates('GROUP_CONCAT(s1, ?)', [' and ']));
|
||||
expect(p1.groupConcat(separator: ' and '),
|
||||
generates('GROUP_CONCAT(p1, ?)', [' and ']));
|
||||
});
|
||||
|
||||
test('with a filter', () {
|
||||
|
@ -136,6 +157,8 @@ void main() {
|
|||
s1.groupConcat(filter: s1.isSmallerThan(Variable('STRING_VALUE'))),
|
||||
generates(
|
||||
'GROUP_CONCAT(s1) FILTER (WHERE s1 < ?)', ['STRING_VALUE']));
|
||||
expect(p1.groupConcat(filter: p1.equals(true)),
|
||||
generates('GROUP_CONCAT(p1) FILTER (WHERE p1 = ?)', [1]));
|
||||
});
|
||||
|
||||
test('with distinct', () {
|
||||
|
@ -145,6 +168,8 @@ void main() {
|
|||
generates('GROUP_CONCAT(DISTINCT b1)', isEmpty));
|
||||
expect(s1.groupConcat(distinct: true),
|
||||
generates('GROUP_CONCAT(DISTINCT s1)', isEmpty));
|
||||
expect(p1.groupConcat(distinct: true),
|
||||
generates('GROUP_CONCAT(DISTINCT p1)', isEmpty));
|
||||
|
||||
expect(
|
||||
foo.groupConcat(
|
||||
|
@ -176,6 +201,16 @@ void main() {
|
|||
['STRING_VALUE'],
|
||||
),
|
||||
);
|
||||
expect(
|
||||
p1.groupConcat(
|
||||
distinct: true,
|
||||
filter: p1.equals(true),
|
||||
),
|
||||
generates(
|
||||
'GROUP_CONCAT(DISTINCT p1) FILTER (WHERE p1 = ?)',
|
||||
[1],
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('does not allow distinct with a custom separator', () {
|
||||
|
@ -185,6 +220,8 @@ void main() {
|
|||
throwsArgumentError);
|
||||
expect(() => s1.groupConcat(distinct: true, separator: ' and '),
|
||||
throwsArgumentError);
|
||||
expect(() => p1.groupConcat(distinct: true, separator: ' and '),
|
||||
throwsArgumentError);
|
||||
|
||||
expect(
|
||||
() => foo.groupConcat(
|
||||
|
@ -210,6 +247,14 @@ void main() {
|
|||
),
|
||||
throwsArgumentError,
|
||||
);
|
||||
expect(
|
||||
() => p1.groupConcat(
|
||||
distinct: true,
|
||||
separator: ' and ',
|
||||
filter: p1.equals(true),
|
||||
),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue