This commit is contained in:
2026-01-28 21:59:04 -05:00
parent dcd516d970
commit ffcb6f658b
10 changed files with 60 additions and 134 deletions

View File

@@ -3,6 +3,7 @@ package runtime
import (
"bytes"
"context"
"os"
"strings"
"testing"
@@ -26,7 +27,44 @@ func TestExecuteTypeScript(t *testing.T) {
rt, err := New(context.Background(), WithStderr(&stderr), WithStdout(&stdout))
assert.NoError(t, err, "Expected no error")
err = rt.RunFile("../../test_data/test.ts")
tsCode := `interface Person {
name: string;
age: number;
email: string;
}
function greet(person: Person): string {
return "Hello, " + person.name + "! You are " + person.age + " years old.";
}
const user: Person = {
name: "Alice",
age: 30,
email: "alice@example.com",
};
console.log(greet(user));
console.log("Email: " + user.email);
function calculateSum(a: number, b: number): number {
return a + b;
}
console.log("Sum of 5 and 10 is: " + calculateSum(5, 10));
`
tmpFile, err := os.CreateTemp("", "*.ts")
assert.NoError(t, err, "Failed to create temp file")
t.Cleanup(func() {
_ = os.Remove(tmpFile.Name())
})
_, err = tmpFile.WriteString(tsCode)
assert.NoError(t, err, "Failed to write to temp file")
err = tmpFile.Close()
assert.NoError(t, err, "Failed to close temp file")
err = rt.RunFile(tmpFile.Name())
assert.NoError(t, err, "Expected no error")
assert.Empty(t, stderr.String(), "Expected no error output")