Files
pokerfreak/tests/schalter_entwurf_spec.ps1
T
mmintelandClaude Opus 5.5 22164a83eb Schalter-Entwurf als Werkzeug: Zeilenenden (LF/CRLF) und Schluss-Umbruch wie die Live-Datei, ohne BOM, nie ueberschreiben
Der erste Entwurf fuer alles-0212h schrieb durchgehend CRLF (321 von 321 Zeilen), die Live-Datei hat LF. Spec 9 Faelle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 21:24:31 +01:00

30 lines
2.3 KiB
PowerShell

# Spezifikation von messung/farm/schalter_entwurf.ps1. Lauf: pwsh -NoProfile -File tests/schalter_entwurf_spec.ps1 (auch Windows PowerShell 5.1)
. (Join-Path $PSScriptRoot '..\messung\farm\schalter_entwurf.ps1')
$fehler = 0; $n = 0
function Pruefe($name, $ist, $soll) { $script:n++; if ("$ist" -ceq "$soll") { "OK $name" } else { $script:fehler++; "FEHLER ${name}: ist '$ist', soll '$soll'" } }
$s = [ordered]@{ AB_SPOT = 'ALLES0212H'; AB_SPOT_SALZ = 'alles0212h' }; $a = [ordered]@{ AB_SPOT_B = ';MOTOR_X=1' }
$lf = "# Kommentar AB_SPOT=x`nAB_SPOT=ALLES0212G`nAB_SPOT_B=MOTOR_A=1`nAB_SPOT_SALZ=alles0212g`nNOTBREMSE=1`n"
$e = Schalter-Entwurf $lf $s $a
Pruefe 'LF bleibt LF (kein CR)' ($e.Contains("`r")) 'False'
Pruefe 'genau die Zeilen ersetzt/angehaengt' $e "# Kommentar AB_SPOT=x`nAB_SPOT=ALLES0212H`nAB_SPOT_B=MOTOR_A=1;MOTOR_X=1`nAB_SPOT_SALZ=alles0212h`nNOTBREMSE=1`n"
$crlf = $lf.Replace("`n", "`r`n")
$e2 = Schalter-Entwurf $crlf $s $a
Pruefe 'CRLF bleibt CRLF' $e2 ($e.Replace("`n", "`r`n"))
Pruefe 'ohne Schluss-Umbruch bleibt ohne' (Schalter-Entwurf "AB_SPOT=x`nB=1" ([ordered]@{ AB_SPOT = 'y' }) ([ordered]@{})) "AB_SPOT=y`nB=1"
Pruefe 'Leerzeilen bleiben' (Schalter-Entwurf "A=1`n`nB=2`n" ([ordered]@{ B = '3' }) ([ordered]@{})) "A=1`n`nB=3`n"
$fehlt = try { Schalter-Entwurf $lf ([ordered]@{ GIBTS_NICHT = '1' }) ([ordered]@{}); 'kein Fehler' } catch { "$_" }
Pruefe 'fehlender Schluessel ist ein Fehler' $fehlt 'nicht in der Vorlage: GIBTS_NICHT'
# Datei: ohne BOM, LF wie Vorlage, nie ueberschreiben
$d = Join-Path ([IO.Path]::GetTempPath()) ("se-" + [guid]::NewGuid()); New-Item -ItemType Directory $d | Out-Null; $lv = Join-Path $d "live.txt"; $ef = Join-Path $d "e.txt"
[IO.File]::WriteAllText($lv, $lf, (New-Object Text.UTF8Encoding $false))
$skript = Join-Path $PSScriptRoot '..\messung\farm\schalter_entwurf.ps1'
& $skript -Live $lv -Aus $ef -Setze 'AB_SPOT=ALLES0212H', 'AB_SPOT_SALZ=alles0212h' -Anhaengen 'AB_SPOT_B=;MOTOR_X=1' | Out-Null
$b = [IO.File]::ReadAllBytes($ef)
Pruefe 'Datei ohne BOM' ($b[0] -eq 0xEF) 'False'
Pruefe 'Datei gleich dem Text-Entwurf' ([Text.Encoding]::UTF8.GetString($b)) $e
$ueber = try { & $skript -Live $lv -Aus $ef -Setze 'AB_SPOT=Z'; 'ueberschrieben' } catch { 'abgelehnt' }
Pruefe 'vorhandene Datei wird nicht ueberschrieben' $ueber 'abgelehnt'
Remove-Item $d -Recurse
"$n Faelle, $fehler Fehler"
if ($fehler) { exit 1 }