# test-vim.ps1 - regression tests for the assembly vim (vim/src/vim.s). # # pwsh vim/test/test-vim.ps1 all cases # pwsh vim/test/test-vim.ps1 -Only join run the cases whose name matches # # Each case rebuilds vim/build/vim.d64 (so it starts from the fixtures in # vim/test), types its keys into VICE with `c64 test`, checks the screen # for the expected text and, where a case saves, reads the file back from the # disk image with c1541 and compares the bytes. Keys: \n is RETURN, \x03 is # RUN/STOP (Esc), \x14 is DEL. Expected file text is ASCII with \n line # ends; it is converted to PETSCII the way the fixtures are. param([string]$Only = "") $ErrorActionPreference = "Stop" $repo = Resolve-Path (Join-Path $PSScriptRoot "..\..") $c64 = Join-Path $repo "c64.cmd" $c1541 = "C:\Program Files\GTK3VICE-3.10-win64\bin\c1541.exe" $disk = Join-Path $repo "vim\build\vim.d64" $tmp = Join-Path ([IO.Path]::GetTempPath()) "vim-test-read.seq" function ConvertTo-Petscii([string]$text) { $o = New-Object System.Collections.Generic.List[byte] foreach ($ch in [Text.Encoding]::ASCII.GetBytes($text)) { if ($ch -eq 10) { $o.Add(13) } elseif ($ch -ge 0x61 -and $ch -le 0x7A) { $o.Add([byte]($ch - 0x20)) } elseif ($ch -ge 0x41 -and $ch -le 0x5A) { $o.Add([byte]($ch + 0x80)) } else { $o.Add($ch) } } return ,$o.ToArray() } $k51 = "k" * 51 $cases = @( @{ n = "open"; k = 'sample\n'; e = @("alpha", "delta", "sample", "1/4") } @{ n = "edit-save"; k = 'sample\njddpggA xyz\x03onew line\x03:w\n'; e = @("written", "2/5") f = "sample"; t = "alpha xyz`nnew line`ncharlie`nbravo`ndelta`n" } @{ n = "join"; k = 'sample\njjI\x14\x14!\x03'; e = @("brav!charlie", "2/3") } @{ n = "x-O-i"; k = 'sample\nxxlOtop\x03jjiI\x03'; e = @("top", "pha", "brIavo", "3/5") } @{ n = "k-x"; k = 'sample\nGkkx'; e = @("ravo", "2/4") } @{ n = "dd-last"; k = 'sample\nGdd'; e = @("charlie", "3/3") } @{ n = "dd-G-p"; k = 'sample\nddGp'; e = @("4/4") after = { param($s) $i = $s.IndexOf("delta"); $j = $s.IndexOf("alpha"); ($i -ge 0) -and ($j -gt $i) } } @{ n = "dd-only"; k = '\nihi\x03dd'; e = @("1/1", "+") } @{ n = "o-last"; k = 'sample\nGoecho\x03:w\n'; e = @("written", "5/5") f = "sample"; t = "alpha`nbravo`ncharlie`ndelta`necho`n" } @{ n = "empty-end"; k = 'sample\nGo\x03:w\n'; e = @("written", "5/5") f = "sample"; t = "alpha`nbravo`ncharlie`ndelta`n`n" } @{ n = "q-dirty"; k = 'sample\nx:q\n'; e = @("unsaved - :q! quits") } @{ n = "unknown"; k = 'sample\n:zz\n'; e = @("unknown command") } @{ n = "q-bang"; k = 'sample\nx:q!\n'; e = @("READY.") } @{ n = "new-wq"; k = 'fresh\nyihello\x03:wq\n'; e = @("READY.") f = "fresh"; t = "hello`n" } @{ n = "w-name"; k = 'sample\n:w other\nl'; e = @("other", "1/4") f = "other"; t = "alpha`nbravo`ncharlie`ndelta`n" } @{ n = "dir"; k = '\n:dir\n'; e = @("blocks free", "sample", "-- any key --") } @{ n = "long-G"; k = 'long\nG'; j = 2500; e = @("line 77", "line 100", "101/101") } @{ n = "long-split";k = 'long\n'; j = 2500; e = @("long lines split at 240", "1/101") } @{ n = "long-wrap"; k = "long\nG$k51"; j = 4000; e = @("50/101", "line 50", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") } @{ n = "hscroll"; k = "long\nG$k51`$"; j = 4000; e = @("50/101") after = { param($s) $s -match "(?m)^x{39}_\s*$" -and $s -notmatch "line 50" } } @{ n = "wrap"; k = '\niword01 word02 word03 word04 word05 word06 word07 word08 word09 word10 word11 word12 word13 word14 word15\x030'; e = @("1/1") after = { param($s) $s -match "(?m)^word01 word02 word03 word04 word05 word0\s*$" -and $s -match "(?m)^word12 word13 word14 word15_\s*$" } } @{ n = "type-wrap"; k = '\nithe quick brown fox jumps over the lazy dog and then the quick brown fox jumps aga'; e = @("insert") after = { param($s) $s -match "(?m)^the quick brown fox jumps over the lazy\s*$" -and $s -match "(?m)^aga_\s*$" } } @{ n = "type-40"; k = '\nithe quick brown fox jumps over the lazzzzzzy'; e = @("insert") after = { param($s) $s -match "(?m)^lazzzzzzy_\s*$" } } @{ n = "wrap-type"; k = 'sample\nA one two three four five six seven eight\x03:w\n0'; e = @("alpha one two three four five six seven", "bravo") f = "sample"; t = "alpha one two three four five six seven eight`nbravo`ncharlie`ndelta`n" } ) $pass = 0; $fail = 0 foreach ($c in $cases) { if ($Only -and $c.n -notmatch $Only) { continue } & $c64 build vim *> $null if ($LASTEXITCODE -ne 0) { throw "build failed" } $j = if ($c.j) { $c.j } else { 1500 } $targs = @("test", "vim", "-NoBuild", "-AfterJiffies", "$j", "-Keys", $c.k) foreach ($x in $c.e) { $targs += @("-Expect", $x) } & $c64 @targs *> $null $ok = $LASTEXITCODE -eq 0 $why = "" if (-not $ok) { $why = "screen" } $screen = Get-Content -Raw (Join-Path $repo "vim/build/test/vim/screen.txt") if ($ok -and $c.after) { if (-not (& $c.after $screen)) { $ok = $false; $why = "order" } } if ($ok -and $c.f) { if (Test-Path $tmp) { Remove-Item $tmp } & $c1541 $disk -read "$($c.f),s" $tmp *> $null $want = ConvertTo-Petscii $c.t $got = if (Test-Path $tmp) { [IO.File]::ReadAllBytes($tmp) } else { @() } if (-not (($got.Length -eq $want.Length) -and (-not (Compare-Object $got $want -SyncWindow 0)))) { $ok = $false $why = "file " + $c.f + ": " + (($got | ForEach-Object { "{0:x2}" -f $_ }) -join " ") } } if ($ok) { $pass++; Write-Host ("PASS {0}" -f $c.n) -ForegroundColor Green } else { $fail++ Write-Host ("FAIL {0} ({1})" -f $c.n, $why) -ForegroundColor Red Write-Host $screen } } Write-Host ("{0} passed, {1} failed" -f $pass, $fail) if ($fail -gt 0) { exit 1 }