您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

107 行
6.3KB

  1. # test-vim.ps1 - regression tests for the assembly vim (vim/src/vim.s).
  2. #
  3. # pwsh vim/test/test-vim.ps1 all cases
  4. # pwsh vim/test/test-vim.ps1 -Only join run the cases whose name matches
  5. #
  6. # Each case rebuilds vim/build/vim.d64 (so it starts from the fixtures in
  7. # vim/test), types its keys into VICE with `c64 test`, checks the screen
  8. # for the expected text and, where a case saves, reads the file back from the
  9. # disk image with c1541 and compares the bytes. Keys: \n is RETURN, \x03 is
  10. # RUN/STOP (Esc), \x14 is DEL. Expected file text is ASCII with \n line
  11. # ends; it is converted to PETSCII the way the fixtures are.
  12. param([string]$Only = "")
  13. $ErrorActionPreference = "Stop"
  14. $repo = Resolve-Path (Join-Path $PSScriptRoot "..\..")
  15. $c64 = Join-Path $repo "c64.cmd"
  16. $c1541 = "C:\Program Files\GTK3VICE-3.10-win64\bin\c1541.exe"
  17. $disk = Join-Path $repo "vim\build\vim.d64"
  18. $tmp = Join-Path ([IO.Path]::GetTempPath()) "vim-test-read.seq"
  19. function ConvertTo-Petscii([string]$text) {
  20. $o = New-Object System.Collections.Generic.List[byte]
  21. foreach ($ch in [Text.Encoding]::ASCII.GetBytes($text)) {
  22. if ($ch -eq 10) { $o.Add(13) }
  23. elseif ($ch -ge 0x61 -and $ch -le 0x7A) { $o.Add([byte]($ch - 0x20)) }
  24. elseif ($ch -ge 0x41 -and $ch -le 0x5A) { $o.Add([byte]($ch + 0x80)) }
  25. else { $o.Add($ch) }
  26. }
  27. return ,$o.ToArray()
  28. }
  29. $k51 = "k" * 51
  30. $cases = @(
  31. @{ n = "open"; k = 'sample\n'; e = @("alpha", "delta", "sample", "1/4") }
  32. @{ n = "edit-save"; k = 'sample\njddpggA xyz\x03onew line\x03:w\n'; e = @("written", "2/5")
  33. f = "sample"; t = "alpha xyz`nnew line`ncharlie`nbravo`ndelta`n" }
  34. @{ n = "join"; k = 'sample\njjI\x14\x14!\x03'; e = @("brav!charlie", "2/3") }
  35. @{ n = "x-O-i"; k = 'sample\nxxlOtop\x03jjiI\x03'; e = @("top", "pha", "brIavo", "3/5") }
  36. @{ n = "k-x"; k = 'sample\nGkkx'; e = @("ravo", "2/4") }
  37. @{ n = "dd-last"; k = 'sample\nGdd'; e = @("charlie", "3/3") }
  38. @{ n = "dd-G-p"; k = 'sample\nddGp'; e = @("4/4")
  39. after = { param($s) $i = $s.IndexOf("delta"); $j = $s.IndexOf("alpha"); ($i -ge 0) -and ($j -gt $i) } }
  40. @{ n = "dd-only"; k = '\nihi\x03dd'; e = @("1/1", "+") }
  41. @{ n = "o-last"; k = 'sample\nGoecho\x03:w\n'; e = @("written", "5/5")
  42. f = "sample"; t = "alpha`nbravo`ncharlie`ndelta`necho`n" }
  43. @{ n = "empty-end"; k = 'sample\nGo\x03:w\n'; e = @("written", "5/5")
  44. f = "sample"; t = "alpha`nbravo`ncharlie`ndelta`n`n" }
  45. @{ n = "q-dirty"; k = 'sample\nx:q\n'; e = @("unsaved - :q! quits") }
  46. @{ n = "unknown"; k = 'sample\n:zz\n'; e = @("unknown command") }
  47. @{ n = "q-bang"; k = 'sample\nx:q!\n'; e = @("READY.") }
  48. @{ n = "new-wq"; k = 'fresh\nyihello\x03:wq\n'; e = @("READY.")
  49. f = "fresh"; t = "hello`n" }
  50. @{ n = "w-name"; k = 'sample\n:w other\nl'; e = @("other", "1/4")
  51. f = "other"; t = "alpha`nbravo`ncharlie`ndelta`n" }
  52. @{ n = "dir"; k = '\n:dir\n'; e = @("blocks free", "sample", "-- any key --") }
  53. @{ n = "long-G"; k = 'long\nG'; j = 2500; e = @("line 77", "line 100", "101/101") }
  54. @{ n = "long-split";k = 'long\n'; j = 2500; e = @("long lines split at 240", "1/101") }
  55. @{ n = "long-wrap"; k = "long\nG$k51"; j = 4000; e = @("50/101", "line 50", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") }
  56. @{ n = "hscroll"; k = "long\nG$k51`$"; j = 4000; e = @("50/101")
  57. after = { param($s) $s -match "(?m)^x{39}_\s*$" -and $s -notmatch "line 50" } }
  58. @{ n = "wrap"; k = '\niword01 word02 word03 word04 word05 word06 word07 word08 word09 word10 word11 word12 word13 word14 word15\x030'; e = @("1/1")
  59. after = { param($s) $s -match "(?m)^word01 word02 word03 word04 word05 word0\s*$" -and $s -match "(?m)^word12 word13 word14 word15_\s*$" } }
  60. @{ n = "type-wrap"; k = '\nithe quick brown fox jumps over the lazy dog and then the quick brown fox jumps aga'; e = @("insert")
  61. after = { param($s) $s -match "(?m)^the quick brown fox jumps over the lazy\s*$" -and $s -match "(?m)^aga_\s*$" } }
  62. @{ n = "type-40"; k = '\nithe quick brown fox jumps over the lazzzzzzy'; e = @("insert")
  63. after = { param($s) $s -match "(?m)^lazzzzzzy_\s*$" } }
  64. @{ 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")
  65. f = "sample"; t = "alpha one two three four five six seven eight`nbravo`ncharlie`ndelta`n" }
  66. )
  67. $pass = 0; $fail = 0
  68. foreach ($c in $cases) {
  69. if ($Only -and $c.n -notmatch $Only) { continue }
  70. & $c64 build vim *> $null
  71. if ($LASTEXITCODE -ne 0) { throw "build failed" }
  72. $j = if ($c.j) { $c.j } else { 1500 }
  73. $targs = @("test", "vim", "-NoBuild", "-AfterJiffies", "$j", "-Keys", $c.k)
  74. foreach ($x in $c.e) { $targs += @("-Expect", $x) }
  75. & $c64 @targs *> $null
  76. $ok = $LASTEXITCODE -eq 0
  77. $why = ""
  78. if (-not $ok) { $why = "screen" }
  79. $screen = Get-Content -Raw (Join-Path $repo "vim/build/test/vim/screen.txt")
  80. if ($ok -and $c.after) {
  81. if (-not (& $c.after $screen)) { $ok = $false; $why = "order" }
  82. }
  83. if ($ok -and $c.f) {
  84. if (Test-Path $tmp) { Remove-Item $tmp }
  85. & $c1541 $disk -read "$($c.f),s" $tmp *> $null
  86. $want = ConvertTo-Petscii $c.t
  87. $got = if (Test-Path $tmp) { [IO.File]::ReadAllBytes($tmp) } else { @() }
  88. if (-not (($got.Length -eq $want.Length) -and (-not (Compare-Object $got $want -SyncWindow 0)))) {
  89. $ok = $false
  90. $why = "file " + $c.f + ": " + (($got | ForEach-Object { "{0:x2}" -f $_ }) -join " ")
  91. }
  92. }
  93. if ($ok) { $pass++; Write-Host ("PASS {0}" -f $c.n) -ForegroundColor Green }
  94. else {
  95. $fail++
  96. Write-Host ("FAIL {0} ({1})" -f $c.n, $why) -ForegroundColor Red
  97. Write-Host $screen
  98. }
  99. }
  100. Write-Host ("{0} passed, {1} failed" -f $pass, $fail)
  101. if ($fail -gt 0) { exit 1 }

Powered by TurnKey Linux.