# No test framework dependency: exercise the build-time resource validator itself.
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$generator = Join-Path $PSScriptRoot 'Generate-Localization.ps1'
$testDirectory = Join-Path $PSScriptRoot ('../obj/localization-tests/' + [guid]::NewGuid().ToString('N'))
$utf8 = [Text.UTF8Encoding]::new($false)
$cases = @(
@{ Name='missing-key'; Zh='{"TestOne":"一","TestTwo":"二"}'; En='{"TestOne":"One"}'; Error='key count mismatch' },
@{ Name='wrong-key'; Zh='{"TestOne":"一"}'; En='{"TestTwo":"Two"}'; Error='Missing English resource' },
@{ Name='placeholder'; Zh='{"TestOne":"值 {0}"}'; En='{"TestOne":"Value {1}"}'; Error='placeholder mismatch' },
@{ Name='duplicate'; Zh='{"TestOne":"一","TestOne":"二"}'; En='{"TestOne":"One"}'; Error='Duplicate resource key' },
@{ Name='non-string'; Zh='{"TestOne":123}'; En='{"TestOne":"One"}'; Error='must be a string' },
@{ Name='invalid-format'; Zh='{"TestOne":"值 {"}'; En='{"TestOne":"Value {0}"}'; Error='Invalid format string' },
@{ Name='invalid-key'; Zh='{"invalid-key":"一"}'; En='{"invalid-key":"One"}'; Error='Invalid/reserved resource key' }
)
foreach ($case in $cases) {
$directory = Join-Path $testDirectory $case.Name
$null = [IO.Directory]::CreateDirectory($directory)
[IO.File]::WriteAllText((Join-Path $directory 'test.zh-CN.json'), $case.Zh, $utf8)
[IO.File]::WriteAllText((Join-Path $directory 'test.en-US.json'), $case.En, $utf8)
$rejected = $false
try { & $generator -ResourceDirectory $directory -ValidateOnly }
catch { if ($_.Exception.Message.Contains($case.Error)) { $rejected = $true } else { throw } }
if (-not $rejected) { throw "Resource validator accepted invalid case: $($case.Name)" }
}
$validDirectory = Join-Path $testDirectory 'valid'
$null = [IO.Directory]::CreateDirectory($validDirectory)
[IO.File]::WriteAllText((Join-Path $validDirectory 'test.zh-CN.json'), '{"TestOne":"值 {0} / {{转义}} / \"引号\"\n第二行\\路径"}', $utf8)
[IO.File]::WriteAllText((Join-Path $validDirectory 'test.en-US.json'), '{"TestOne":"Value {0} / {{escaped}} / \"quote\"\nLine two\\path"}', $utf8)
$output = Join-Path $validDirectory 'Strings.g.cs'
& $generator -ResourceDirectory $validDirectory -Language zh-CN -OutputPath $output
$first = [IO.File]::ReadAllText($output)
& $generator -ResourceDirectory $validDirectory -Language zh-CN -OutputPath $output
if ([IO.File]::ReadAllText($output) -cne $first -or -not $first.Contains('\"引号\"\n第二行\\路径')) { throw 'Resource generation is not deterministic or does not escape C# literals.' }
& $generator -ValidateOnly
Write-Host 'XFE AMS localization generator: 8 checks passed.' -ForegroundColor Green
# No test framework dependency: exercise the build-time resource validator itself.
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$generator = Join-Path $PSScriptRoot 'Generate-Localization.ps1'
$testDirectory = Join-Path $PSScriptRoot ('../obj/localization-tests/' + [guid]::NewGuid().ToString('N'))
$utf8 = [Text.UTF8Encoding]::new($false)
$cases = @(
@{ Name='missing-key'; Zh='{"TestOne":"一","TestTwo":"二"}'; En='{"TestOne":"One"}'; Error='key count mismatch' },
@{ Name='wrong-key'; Zh='{"TestOne":"一"}'; En='{"TestTwo":"Two"}'; Error='Missing English resource' },
@{ Name='placeholder'; Zh='{"TestOne":"值 {0}"}'; En='{"TestOne":"Value {1}"}'; Error='placeholder mismatch' },
@{ Name='duplicate'; Zh='{"TestOne":"一","TestOne":"二"}'; En='{"TestOne":"One"}'; Error='Duplicate resource key' },
@{ Name='non-string'; Zh='{"TestOne":123}'; En='{"TestOne":"One"}'; Error='must be a string' },
@{ Name='invalid-format'; Zh='{"TestOne":"值 {"}'; En='{"TestOne":"Value {0}"}'; Error='Invalid format string' },
@{ Name='invalid-key'; Zh='{"invalid-key":"一"}'; En='{"invalid-key":"One"}'; Error='Invalid/reserved resource key' }
)
foreach ($case in $cases) {
$directory = Join-Path $testDirectory $case.Name
$null = [IO.Directory]::CreateDirectory($directory)
[IO.File]::WriteAllText((Join-Path $directory 'test.zh-CN.json'), $case.Zh, $utf8)
[IO.File]::WriteAllText((Join-Path $directory 'test.en-US.json'), $case.En, $utf8)
$rejected = $false
try { & $generator -ResourceDirectory $directory -ValidateOnly }
catch { if ($_.Exception.Message.Contains($case.Error)) { $rejected = $true } else { throw } }
if (-not $rejected) { throw "Resource validator accepted invalid case: $($case.Name)" }
}
$validDirectory = Join-Path $testDirectory 'valid'
$null = [IO.Directory]::CreateDirectory($validDirectory)
[IO.File]::WriteAllText((Join-Path $validDirectory 'test.zh-CN.json'), '{"TestOne":"值 {0} / {{转义}} / \"引号\"\n第二行\\路径"}', $utf8)
[IO.File]::WriteAllText((Join-Path $validDirectory 'test.en-US.json'), '{"TestOne":"Value {0} / {{escaped}} / \"quote\"\nLine two\\path"}', $utf8)
$output = Join-Path $validDirectory 'Strings.g.cs'
& $generator -ResourceDirectory $validDirectory -Language zh-CN -OutputPath $output
$first = [IO.File]::ReadAllText($output)
& $generator -ResourceDirectory $validDirectory -Language zh-CN -OutputPath $output
if ([IO.File]::ReadAllText($output) -cne $first -or -not $first.Contains('\"引号\"\n第二行\\路径')) { throw 'Resource generation is not deterministic or does not escape C# literals.' }
& $generator -ValidateOnly
Write-Host 'XFE AMS localization generator: 8 checks passed.' -ForegroundColor Green