Skip to content

Commit f7ab1e1

Browse files
Add test for the REPL.
1 parent 7ff826b commit f7ab1e1

10 files changed

Lines changed: 107 additions & 6 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
IMPORT(path)
2+
3+
STR: p = path.TEMPFILE("prefix-readfile-utf16-replacement.bin")
4+
5+
ASSERT(WRITEFILE("00D8", p, coding = "hex"))
6+
ASSERT(EQ(READFILE(p, coding = "UTF-16 LE"), "\uFFFD"))

tests/cases/passing/repl-basic.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$helperPath = Join-Path (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) 'helpers\prefix-input.ps1'
2+
. $helperPath
3+
4+
$result = Invoke-PrefixWithArguments -Arguments @() -InputText "PRINT('repl-basic')`n.exit`n"
5+
6+
Assert-PrefixSuccess $result
7+
Assert-NoErrorOutput $result
8+
9+
$stdout = Format-VisibleText $result.Stdout
10+
if (-not ($stdout -match 'repl-basic')) {
11+
throw "Unexpected stdout: $stdout"
12+
}

tests/cases/passing/repl-eof.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$helperPath = Join-Path (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) 'helpers\prefix-input.ps1'
2+
. $helperPath
3+
4+
# Send a single command and EOF (no explicit .exit)
5+
$result = Invoke-PrefixWithArguments -Arguments @() -InputText "PRINT('bye')`n"
6+
7+
Assert-PrefixSuccess $result
8+
Assert-NoErrorOutput $result
9+
10+
$stdout = Format-VisibleText $result.Stdout
11+
if (-not ($stdout -match 'bye')) {
12+
throw "Unexpected stdout: $stdout"
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$helperPath = Join-Path (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) 'helpers\prefix-input.ps1'
2+
. $helperPath
3+
4+
$input = @'
5+
FUNC STR: hello(){
6+
RETURN("hi")
7+
}
8+
PRINT(hello())
9+
.exit
10+
'@
11+
12+
$result = Invoke-PrefixWithArguments -Arguments @() -InputText $input
13+
14+
Assert-PrefixSuccess $result
15+
Assert-NoErrorOutput $result
16+
17+
$stdout = Format-VisibleText $result.Stdout
18+
if (-not ($stdout -match 'hi')) {
19+
throw "Unexpected stdout: $stdout"
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
$helperPath = Join-Path (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) 'helpers\prefix-input.ps1'
2+
. $helperPath
3+
4+
$input = @'
5+
BOOL: persisted = TRUE
6+
7+
PRINT(persisted)
8+
.exit
9+
'@
10+
11+
$result = Invoke-PrefixWithArguments -Arguments @() -InputText $input
12+
13+
Assert-PrefixSuccess $result
14+
Assert-NoErrorOutput $result
15+
16+
$stdout = Format-VisibleText $result.Stdout
17+
if (-not ($stdout -match 'TRUE')) {
18+
throw "Unexpected stdout: $stdout"
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
IMPORT(path)
2+
3+
STR: p = path.TEMPFILE("prefix-writefile-bin.bin")
4+
5+
ASSERT(WRITEFILE("0100000101111010", p, coding = "bin"))
6+
ASSERT(EQ(READFILE(p, coding = "bin"), "0100000101111010"))
7+
ASSERT(EQ(READFILE(p), "Az"))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
IMPORT(path)
2+
3+
STR: d = path.TEMPFILE("prefix-writefile-fail-dir")
4+
5+
IF(EQ(OS(),"win")){
6+
ASSERT(EQ(CL(JOIN("md ", WINPATH(d))), 0d0))
7+
} ELSE {
8+
ASSERT(EQ(CL(JOIN("mkdir -p ", d)), 0d0))
9+
}
10+
11+
ASSERT(NOT(WRITEFILE("x", d)))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
IMPORT(path)
2+
3+
STR: p = path.TEMPFILE("prefix-writefile-utf16-be.txt")
4+
5+
ASSERT(WRITEFILE("Prefix", p, coding = "UTF-16 BE"))
6+
ASSERT(EQ(READFILE(p, coding = "UTF-16 BE"), "Prefix"))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
IMPORT(path)
2+
3+
STR: p = path.TEMPFILE("prefix-writefile-utf16-le.txt")
4+
5+
ASSERT(WRITEFILE("Prefix", p, coding = "UTF-16 LE"))
6+
ASSERT(EQ(READFILE(p, coding = "UTF-16 LE"), "Prefix"))

tests/helpers/prefix-input.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ function New-PrefixTempDir {
5151

5252
function ConvertTo-PrefixArgumentString {
5353
param(
54-
[Parameter(Mandatory = $true)]
55-
[string[]]$Arguments
54+
[Parameter(Mandatory = $false)]
55+
[string[]]$Arguments = @()
5656
)
57+
if (-not $Arguments) { return '' }
5758

5859
$escaped = foreach ($argument in $Arguments) {
5960
if ($null -eq $argument) {
@@ -69,8 +70,8 @@ function ConvertTo-PrefixArgumentString {
6970

7071
function Start-PrefixProcessWithArguments {
7172
param(
72-
[Parameter(Mandatory = $true)]
73-
[string[]]$Arguments,
73+
[Parameter(Mandatory = $false)]
74+
[string[]]$Arguments = @(),
7475

7576
[string]$WorkingDirectory,
7677

@@ -118,8 +119,8 @@ function Start-PrefixProcess {
118119

119120
function Invoke-PrefixWithArguments {
120121
param(
121-
[Parameter(Mandatory = $true)]
122-
[string[]]$Arguments,
122+
[Parameter(Mandatory = $false)]
123+
[string[]]$Arguments = @(),
123124

124125
[AllowEmptyString()]
125126
[string]$InputText = '',

0 commit comments

Comments
 (0)