Skip to content

Commit

Permalink
booleanParams need thenElse too (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
Berlioz committed Nov 23, 2022
1 parent 53d566c commit 0aa6d6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions spec/params/params.spec.ts
Expand Up @@ -277,13 +277,13 @@ describe("Params as CEL", () => {
const booleanExpr = params.defineBoolean("BOOL");
const cmpExpr = params.defineInt("A").cmp("!=", params.defineInt("B"));

expect(booleanExpr.then("asdf", "jkl;").toCEL()).to.equal(
expect(booleanExpr.thenElse("asdf", "jkl;").toCEL()).to.equal(
'{{ params.BOOL ? "asdf" : "jkl;" }}'
);
expect(booleanExpr.then(-11, 22).toCEL()).to.equal("{{ params.BOOL ? -11 : 22 }}");
expect(booleanExpr.then(false, true).toCEL()).to.equal("{{ params.BOOL ? false : true }}");
expect(booleanExpr.thenElse(-11, 22).toCEL()).to.equal("{{ params.BOOL ? -11 : 22 }}");
expect(booleanExpr.thenElse(false, true).toCEL()).to.equal("{{ params.BOOL ? false : true }}");
expect(
booleanExpr.then(params.defineString("FOO"), params.defineString("BAR")).toCEL()
booleanExpr.thenElse(params.defineString("FOO"), params.defineString("BAR")).toCEL()
).to.equal("{{ params.BOOL ? params.FOO : params.BAR }}");
expect(cmpExpr.thenElse("asdf", "jkl;").toCEL()).to.equal(
'{{ params.A != params.B ? "asdf" : "jkl;" }}'
Expand Down
8 changes: 8 additions & 0 deletions src/params/types.ts
Expand Up @@ -452,7 +452,15 @@ export class BooleanParam extends Param<boolean> {
return !!process.env[this.name] && process.env[this.name] === "true";
}

/** @deprecated */
then<T extends string | number | boolean>(ifTrue: T | Expression<T>, ifFalse: T | Expression<T>) {
return this.thenElse(ifTrue, ifFalse);
}

thenElse<T extends string | number | boolean>(
ifTrue: T | Expression<T>,
ifFalse: T | Expression<T>
) {
return new TernaryExpression(this, ifTrue, ifFalse);
}
}

0 comments on commit 0aa6d6b

Please sign in to comment.