Skip to content

Commit

Permalink
chore(iot-events): support all binary operators (aws#19889)
Browse files Browse the repository at this point in the history
This PR adds rest binary operators of IoT Events.
This PR does not add new integ tests because of [this conversation](aws#19329 (comment)).

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
yamatatsu authored and josephedward committed Aug 30, 2022
1 parent 2e42c72 commit bf5ea10
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/@aws-cdk/aws-iotevents/lib/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,62 @@ export abstract class Expression {
return this.fromString(`$input.${input.inputName}.${path}`);
}

/**
* Create a expression for the Addition operator.
*/
public static add(left: Expression, right: Expression): Expression {
return new BinaryOperationExpression(left, '+', right, 12);
}

/**
* Create a expression for the Subtraction operator.
*/
public static subtract(left: Expression, right: Expression): Expression {
return new BinaryOperationExpression(left, '-', right, 12);
}

/**
* Create a expression for the Division operator.
*/
public static divide(left: Expression, right: Expression): Expression {
return new BinaryOperationExpression(left, '/', right, 13);
}

/**
* Create a expression for the Multiplication operator.
*/
public static multiply(left: Expression, right: Expression): Expression {
return new BinaryOperationExpression(left, '*', right, 13);
}

/**
* Create a expression for the String Concatenation operator.
*/
public static concat(left: Expression, right: Expression): Expression {
return this.add(left, right);
}

/**
* Create a expression for the Bitwise OR operator.
*/
public static bitwiseOr(left: Expression, right: Expression): Expression {
return new BinaryOperationExpression(left, '|', right, 6);
}

/**
* Create a expression for the Bitwise AND operator.
*/
public static bitwiseAnd(left: Expression, right: Expression): Expression {
return new BinaryOperationExpression(left, '&', right, 8);
}

/**
* Create a expression for the Bitwise XOR operator.
*/
public static bitwiseXor(left: Expression, right: Expression): Expression {
return new BinaryOperationExpression(left, '^', right, 7);
}

/**
* Create a expression for the Equal operator.
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-iotevents/test/detector-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,14 @@ describe('Expression', () => {
test.each([
['currentInput', (testInput: iotevents.IInput) => E.currentInput(testInput), 'currentInput("test-input")'],
['inputAttribute', (testInput: iotevents.IInput) => E.inputAttribute(testInput, 'json.path'), '$input.test-input.json.path'],
['add', () => E.add(E.fromString('5'), E.fromString('2')), '5 + 2'],
['subtract', () => E.subtract(E.fromString('5'), E.fromString('2')), '5 - 2'],
['divide', () => E.divide(E.fromString('5'), E.fromString('2')), '5 / 2'],
['multiply', () => E.multiply(E.fromString('5'), E.fromString('2')), '5 * 2'],
['concat', () => E.concat(E.fromString('"aaa"'), E.fromString('"bbb"')), '"aaa" + "bbb"'],
['bitwiseOr', () => E.bitwiseOr(E.fromString('5'), E.fromString('2')), '5 | 2'],
['bitwiseAnd', () => E.bitwiseAnd(E.fromString('5'), E.fromString('2')), '5 & 2'],
['bitwiseXor', () => E.bitwiseXor(E.fromString('5'), E.fromString('2')), '5 ^ 2'],
['eq', () => E.eq(E.fromString('"aaa"'), E.fromString('"bbb"')), '"aaa" == "bbb"'],
['neq', () => E.neq(E.fromString('"aaa"'), E.fromString('"bbb"')), '"aaa" != "bbb"'],
['lt', () => E.lt(E.fromString('5'), E.fromString('2')), '5 < 2'],
Expand Down

0 comments on commit bf5ea10

Please sign in to comment.