Skip to content

Commit 1ee04f8

Browse files
(MAINT) Update i18n tests for panic_t! and assert_t!
This change updates the i18n Pester tests to account for: - Usage of the `t!` macro when the translation key is defined on the next line. - Usage of the convenience `panic_t!` macro, which simplifies sending translated strings to the `panic!` macro. - Usage of the convenience `assert_t!` macro, which simplifies sending translated strings to the panic when an `assert!` macro fails. These use cases were required for the `dsc-lib-jsonschema` crate, which uses both `panic_t!` and `assert_t!` to raise translated panic messages when a transform is invalidly applied. While this change doesn't modify the behavior for any other crates, it does lay the groundwork for translating panic messages and assertions throughout the crates.
1 parent fd71648 commit 1ee04f8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

dsc/tests/dsc_i18n.tests.ps1

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,25 @@ Describe 'Internationalization tests' {
2626
}
2727
}
2828

29+
$patterns = @{
30+
t = '(?s)\bt\!\(\s*"(?<key>.*?)".*?\)'
31+
panic_t = '(?s)\bpanic_t\!\(\s*"(?<key>.*?)".*?\)'
32+
assert_t = '(?s)\bassert_t\!\(\s*.*?,\s*"(?<key>.*?)".*?\)'
33+
}
34+
2935
$missing = @()
3036
Get-ChildItem -Recurse -Path $project -Include *.rs -File | ForEach-Object {
31-
# Write-Verbose -Verbose "File: $_"
32-
$line = 0
33-
Get-Content -Path $_ | ForEach-Object {
34-
$line++
35-
($_ | Select-String -Pattern '[^\w]t\!\("(?<key>.*?)".*?\)' -AllMatches).Matches | ForEach-Object {
37+
$content = Get-Content -Path $_ -Raw
38+
foreach ($pattern in $patterns.keys) {
39+
($content | Select-String -Pattern $patterns[$pattern] -AllMatches).Matches | ForEach-Object {
3640
# write-verbose -verbose "Line: $_"
3741
if ($null -ne $_) {
3842
$key = $_.Groups['key'].Value
3943
if ($i18n.ContainsKey($key)) {
4044
$i18n[$key] = 1
41-
# write-verbose -verbose "Found on line $line : $key"
4245
}
4346
else {
4447
$missing += $key
45-
# write-verbose -verbose "Missing: $key"
4648
}
4749
}
4850
}

0 commit comments

Comments
 (0)