mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
New pester test for Import-LocalizedData
This commit is contained in:
committed by
Andrew Schwartzmeyer
parent
4fe69773d4
commit
43d284f6b3
@@ -0,0 +1,36 @@
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$assetsDir = Join-Path -Path $here -ChildPath assets
|
||||
|
||||
Describe "Import-LocalizedData" {
|
||||
|
||||
BeforeAll {
|
||||
$script = "localized.ps1"
|
||||
$sunday = "Sunday"
|
||||
$sundayInGerman = $sunday + " (in German)"
|
||||
}
|
||||
|
||||
It "Should be able to import string using default culture" {
|
||||
# Set-Culture is broken, but let's verify that default culture is en-US
|
||||
$culture = Get-Culture
|
||||
$culture.Name | Should Be "en-US"
|
||||
|
||||
$d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir
|
||||
$d.d0 | Should be $sunday
|
||||
}
|
||||
|
||||
It "Should be able to import string using en-US culture" {
|
||||
$d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture en-US
|
||||
$d.d0 | Should be $sunday
|
||||
}
|
||||
|
||||
It "Should be able to import string using de-DE culture" {
|
||||
$d = Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE
|
||||
$d.d0 | Should be $sundayInGerman
|
||||
}
|
||||
|
||||
It "Should be able to import string and store in binding variable" {
|
||||
Import-LocalizedData -FileName $script -BaseDirectory $assetsDir -UICulture de-DE -BindingVariable d
|
||||
$d.d0 | Should be $sundayInGerman
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# culture="de-DE"
|
||||
ConvertFrom-StringData @'
|
||||
messageDate = Today is
|
||||
d0 = Sunday (in German)
|
||||
d1 = Monday (in German)
|
||||
d2 = Tuesday (in German)
|
||||
d3 = Wednesday (in German)
|
||||
d4 = Thursday (in German)
|
||||
d5 = Friday (in German)
|
||||
d6 = Saturday (in German)
|
||||
'@
|
||||
@@ -0,0 +1,11 @@
|
||||
# culture="en-US"
|
||||
ConvertFrom-StringData @'
|
||||
messageDate = Today is
|
||||
d0 = Sunday
|
||||
d1 = Monday
|
||||
d2 = Tuesday
|
||||
d3 = Wednesday
|
||||
d4 = Thursday
|
||||
d5 = Friday
|
||||
d6 = Saturday
|
||||
'@
|
||||
@@ -0,0 +1,29 @@
|
||||
# Sample code from https://technet.microsoft.com/en-us/library/hh847854.aspx
|
||||
|
||||
$Day = DATA {
|
||||
# culture="en-US"
|
||||
ConvertFrom-StringData @'
|
||||
messageDate = Today is
|
||||
d0 = Sunday
|
||||
d1 = Monday
|
||||
d2 = Tuesday
|
||||
d3 = Wednesday
|
||||
d4 = Thursday
|
||||
d5 = Friday
|
||||
d6 = Saturday
|
||||
'@
|
||||
}
|
||||
|
||||
|
||||
Import-LocalizedData -BindingVariable Day
|
||||
|
||||
# Build an array of weekdays.
|
||||
$a = $Day.d0, $Day.d1, $Day.d2, $Day.d3, $Day.d4, $Day.d5, $Day.d6
|
||||
|
||||
|
||||
# Get the day of the week as a number (Monday = 1).
|
||||
# Index into $a to get the name of the day.
|
||||
# Use string formatting to build a sentence.
|
||||
|
||||
"{0} {1}" -f $Day.messageDate, $a[(get-date -uformat %u)] | Out-Host
|
||||
|
||||
Reference in New Issue
Block a user