Skip to content

Commit

Permalink
feat: support for enum literals
Browse files Browse the repository at this point in the history
  • Loading branch information
OlafConijn committed May 1, 2022
1 parent ed6f03c commit 051aae3
Show file tree
Hide file tree
Showing 14 changed files with 539 additions and 0 deletions.
17 changes: 17 additions & 0 deletions convert/src/__test__/integration-tests/enums.integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { convertDeployExecute } from "../utility";
jest.setTimeout(99999999);

describe("when converting enums", () => {
it("will execute compareEnum as if it were node", async () => {
const resultFromSfn = await convertDeployExecute("enums", "compareEnum");
const { compareEnum } = require("../resources/enums");
const resultFromNode = await compareEnum();
expect(resultFromSfn).toEqual(resultFromNode);
});
it("will execute compareStringEnum as if it were node", async () => {
const resultFromSfn = await convertDeployExecute("enums", "compareStringEnum");
const { compareStringEnum } = require("../resources/enums");
const resultFromNode = await compareStringEnum();
expect(resultFromSfn).toEqual(resultFromNode);
});
});
41 changes: 41 additions & 0 deletions convert/src/__test__/output/asl/enums-compareEnum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"StartAt": "Initialize",
"States": {
"Initialize": {
"Type": "Pass",
"ResultPath": "$",
"Parameters": {
"vars.$": "$$.Execution.Input",
"_undefined": null
},
"Next": "Assign x"
},
"Assign x": {
"Type": "Pass",
"ResultPath": "$.vars.x",
"Result": 0,
"Next": "If (x === ExampleEnum.A)"
},
"If (x === ExampleEnum.A)": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.vars.x",
"NumericEquals": 0,
"Next": "Return \"success\""
}
],
"Default": "Return \"fail\""
},
"Return \"success\"": {
"End": true,
"Type": "Pass",
"Result": "success"
},
"Return \"fail\"": {
"End": true,
"Type": "Pass",
"Result": "fail"
}
}
}
41 changes: 41 additions & 0 deletions convert/src/__test__/output/asl/enums-compareStringEnum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"StartAt": "Initialize",
"States": {
"Initialize": {
"Type": "Pass",
"ResultPath": "$",
"Parameters": {
"vars.$": "$$.Execution.Input",
"_undefined": null
},
"Next": "Assign x"
},
"Assign x": {
"Type": "Pass",
"ResultPath": "$.vars.x",
"Result": "a",
"Next": "If (x === ExampleEnumStri ..."
},
"If (x === ExampleEnumStri ...": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.vars.x",
"StringEquals": "a",
"Next": "Return \"success\""
}
],
"Default": "Return \"fail\""
},
"Return \"success\"": {
"End": true,
"Type": "Pass",
"Result": "success"
},
"Return \"fail\"": {
"End": true,
"Type": "Pass",
"Result": "fail"
}
}
}
64 changes: 64 additions & 0 deletions convert/src/__test__/output/iasl/enums-compareEnum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"statements": [
{
"name": {
"identifier": "x",
"_syntaxKind": "identifier",
"type": "unknown"
},
"expression": {
"stateName": "Assign x",
"parameters": {
"value": 0,
"type": "numeric",
"_syntaxKind": "literal"
},
"_syntaxKind": "asl-pass-state"
},
"stateName": "Assign x",
"_syntaxKind": "variable-assignment"
},
{
"stateName": "If (x === ExampleEnum.A)",
"condition": {
"lhs": {
"identifier": "x",
"_syntaxKind": "identifier",
"type": "unknown"
},
"operator": "eq",
"rhs": {
"value": 0,
"type": "numeric",
"_syntaxKind": "literal"
},
"_syntaxKind": "binary-expression"
},
"then": {
"statements": [
{
"expression": {
"value": "success",
"type": "string",
"_syntaxKind": "literal"
},
"_syntaxKind": "return",
"stateName": "Return \"success\""
}
],
"_syntaxKind": "function"
},
"_syntaxKind": "if"
},
{
"expression": {
"value": "fail",
"type": "string",
"_syntaxKind": "literal"
},
"_syntaxKind": "return",
"stateName": "Return \"fail\""
}
],
"_syntaxKind": "statemachine"
}
64 changes: 64 additions & 0 deletions convert/src/__test__/output/iasl/enums-compareStringEnum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"statements": [
{
"name": {
"identifier": "x",
"_syntaxKind": "identifier",
"type": "unknown"
},
"expression": {
"stateName": "Assign x",
"parameters": {
"value": "a",
"type": "string",
"_syntaxKind": "literal"
},
"_syntaxKind": "asl-pass-state"
},
"stateName": "Assign x",
"_syntaxKind": "variable-assignment"
},
{
"stateName": "If (x === ExampleEnumStri ...",
"condition": {
"lhs": {
"identifier": "x",
"_syntaxKind": "identifier",
"type": "unknown"
},
"operator": "eq",
"rhs": {
"value": "a",
"type": "string",
"_syntaxKind": "literal"
},
"_syntaxKind": "binary-expression"
},
"then": {
"statements": [
{
"expression": {
"value": "success",
"type": "string",
"_syntaxKind": "literal"
},
"_syntaxKind": "return",
"stateName": "Return \"success\""
}
],
"_syntaxKind": "function"
},
"_syntaxKind": "if"
},
{
"expression": {
"value": "fail",
"type": "string",
"_syntaxKind": "literal"
},
"_syntaxKind": "return",
"stateName": "Return \"fail\""
}
],
"_syntaxKind": "statemachine"
}
34 changes: 34 additions & 0 deletions convert/src/__test__/output/ts-lib/enums-compareEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as asl from "@ts2asl/asl-lib"

enum ExampleEnum {
"A",
"B"
}

export const compareEnum = asl.deploy.asStateMachine(async () =>{
const x = asl.pass({
name: "Assign x",
parameters: () => 0
});
asl.typescriptIf({
name: "If (x === ExampleEnum.A)",
condition: () => x === 0,
then: async () => {
return "success";
}
})
return "fail";
});

enum ExampleEnumString {
"A" = "a",
"B" = "b"
}

export const compareStringEnum = asl.deploy.asStateMachine(async () => {
const x = ExampleEnumString.A;
if (x === ExampleEnumString.A) {
return "success"
}
return "fail"
});
34 changes: 34 additions & 0 deletions convert/src/__test__/output/ts-lib/enums-compareStringEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as asl from "@ts2asl/asl-lib"

enum ExampleEnum {
"A",
"B"
}

export const compareEnum = asl.deploy.asStateMachine(async () => {
const x = ExampleEnum.A;
if (x === ExampleEnum.A) {
return "success"
}
return "fail"
});

enum ExampleEnumString {
"A" = "a",
"B" = "b"
}

export const compareStringEnum = asl.deploy.asStateMachine(async () =>{
const x = asl.pass({
name: "Assign x",
parameters: () => "a"
});
asl.typescriptIf({
name: "If (x === ExampleEnumStri ...",
condition: () => x === "a",
then: async () => {
return "success";
}
})
return "fail";
});
27 changes: 27 additions & 0 deletions convert/src/__test__/resources/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as asl from "@ts2asl/asl-lib"

enum ExampleEnum {
"A",
"B"
}

export const compareEnum = asl.deploy.asStateMachine(async () => {
const x = ExampleEnum.A;
if (x === ExampleEnum.A) {
return "success"
}
return "fail"
});

enum ExampleEnumString {
"A" = "a",
"B" = "b"
}

export const compareStringEnum = asl.deploy.asStateMachine(async () => {
const x = ExampleEnumString.A;
if (x === ExampleEnumString.A) {
return "success"
}
return "fail"
});
Loading

0 comments on commit 051aae3

Please sign in to comment.