wip2
This commit is contained in:
44
internal/runtime/runtime_test.go
Normal file
44
internal/runtime/runtime_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestExecuteTypeScript(t *testing.T) {
|
||||
var stdout, stderr bytes.Buffer
|
||||
|
||||
rt := New()
|
||||
err := rt.RunFile("../../test_data/test.ts", &stdout, &stderr)
|
||||
|
||||
assert.NoError(t, err, "Expected no error")
|
||||
assert.Empty(t, stderr.String(), "Expected no error output")
|
||||
|
||||
output := stdout.String()
|
||||
|
||||
assert.Contains(t, output, "Hello, Alice!", "Should greet Alice")
|
||||
assert.Contains(t, output, "You are 30 years old", "Should show age")
|
||||
assert.Contains(t, output, "Email: alice@example.com", "Should show email")
|
||||
assert.Contains(t, output, "Sum of 5 and 10 is: 15", "Should calculate sum correctly")
|
||||
|
||||
lines := strings.Split(strings.TrimSpace(output), "\n")
|
||||
assert.GreaterOrEqual(t, len(lines), 3, "Should have at least 3 output lines")
|
||||
}
|
||||
|
||||
func TestFetchBuiltinIntegration(t *testing.T) {
|
||||
rt := New()
|
||||
|
||||
tsContent := `
|
||||
const result = add(5, 10);
|
||||
console.log("Result:", result);
|
||||
`
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
err := rt.RunCode(tsContent, &stdout, &stderr)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, stdout.String(), "Result: 15")
|
||||
}
|
||||
Reference in New Issue
Block a user