Skip to content

Commit

Permalink
other (#587): added an additional test case for num/num multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzholzbauer committed Jun 26, 2024
1 parent eb94965 commit ac387e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To use development versions of Kipper download the
- Support for complex string formatting (or also called templating) in the form of Python-like F-Strings.
([#287](https://github.com/Kipper-Lang/Kipper/issues/287)).
- Support for string multiplication using the `*` operator.
([#478](https://github.com/Kipper-Lang/Kipper/issues/478)).
([#478](https://github.com/Kipper-Lang/Kipper/issues/478)).
- New valid conversions:
- `void` to `str`.
- `null` to `str`.
Expand Down
1 change: 1 addition & 0 deletions kipper/target-js/src/code-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ export class JavaScriptTargetCodeGenerator extends KipperTargetCodeGenerator {
const exp1: TranslatedExpression = await semanticData.leftOp.translateCtxAndChildren();
const exp2: TranslatedExpression = await semanticData.rightOp.translateCtxAndChildren();

// In this case it should be a string multiplication
if (semanticData.leftOp.getTypeSemanticData().evaluatedType.getCompilableType() === "str") {
return [stringRepeatFunction, "(", ...exp1, ", ", ...exp2, ")"];
}
Expand Down
14 changes: 14 additions & 0 deletions test/module/core/errors/type-errors/arithmetic-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,20 @@ describe("ArithmeticOperationTypeError", () => {
});

describe("NoError", () => {
describe("num*num", () => {
it("num*num", async () => {
let result: KipperCompileResult | undefined = undefined;
try {
result = await new KipperCompiler().compile("3 * 3;", defaultConfig);
} catch (e) {
assert.fail("Expected no 'ArithmeticOperationTypeError'");
}
assert.isDefined(result, "Expected defined compilation result");
assert.isDefined(result!!.programCtx, "Expected programCtx to be defined");
assert.isFalse(result!!.programCtx!!.hasFailed, "Expected no errors");
});
});

describe("*", () => {
it("str*num", async () => {
let result: KipperCompileResult | undefined = undefined;
Expand Down

0 comments on commit ac387e1

Please sign in to comment.