Skip to content

Commit

Permalink
fix: expression counts
Browse files Browse the repository at this point in the history
  • Loading branch information
lostfields committed Jan 26, 2023
1 parent d69be1a commit 0e52490
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/linq/operators/whereoperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class WhereOperator<TEntity> extends Operator<TEntity> {
}

default:
return 0;
return 1;
}
}

Expand Down
31 changes: 31 additions & 0 deletions src/test/whereoperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,37 @@ describe("When using WhereOperator", () => {
assert.equal((<ILiteralExpression>(<ILogicalExpression>intersection[0]).right).value, 2015);
});

it("should be able to count expression properties", () => {
let where = new WhereOperator<ICar>('Javascript', car => (car.registrationYear >= 2015 && car.location == 'NO') || 2015 <= car.registrationYear || (car.location == 'SE' && car.registrationYear >= 2015)),
counts = where.getExpressionCount();

assert.equal(counts, 5);
})

it("should be able to count expression properties for odata", () => {
let where = new WhereOperator<ICar>('OData', `date ge 2023-01-01 and date le 2023-02-01 and contains(tolower(invoiceNo), tolower('invhoi2'))`),
counts = where.getExpressionCount();

assert.equal(counts, 3);
})


it("should be able to count and find intersections", () => {
let where = new WhereOperator<ICar>('OData', `date ge 2023-01-01 and date le 2023-02-01 and contains(tolower(invoiceNo), tolower('invhoi2'))`),
intersection = where.getExpressionIntersection(),
counts = where.getExpressionCount();

assert.equal(counts, intersection.length);
})

it("should be able to count expression properties where there is difference", () => {
let where = new WhereOperator<ICar>('Javascript', car => (car.registrationYear >= 2015 && car.location == 'NO') || 2015 <= car.registrationYear || (car.location == 'SE' && car.registrationYear >= 2015)),
intersection = where.getExpressionIntersection(),
counts = where.getExpressionCount();

assert.notEqual(counts, intersection);
})

it("should get union expression properties", () => {
let where = new WhereOperator<ICar>('Javascript', car => (car.registrationYear == 2015 && car.location == 'NO') || car.registrationYear == 2015 || (car.location == 'SE' && car.registrationYear == 2015)),
intersection = where.getExpressionUnion();
Expand Down

0 comments on commit 0e52490

Please sign in to comment.