Skip to content

Commit

Permalink
🎨 Use longer-form blank for dummy type name (#244)
Browse files Browse the repository at this point in the history
* 🎨 Use [____] as the dummy type
📝 Retain [__] for compat

* 🔧 Fix AboutVariables
  • Loading branch information
vexx32 committed Sep 13, 2019
1 parent 8300057 commit 9690b0a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 28 deletions.
7 changes: 5 additions & 2 deletions PSKoans/DummyTypes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

switch ($null) {
('FillerType' -as [type]) {
class FillerType {}
class FillerType { }
}
('__' -as [type]) {
class __ : FillerType {}
class __ : FillerType { }
}
('____' -as [type]) {
class ____ : FillerType { }
}
}
4 changes: 2 additions & 2 deletions PSKoans/Koans/Cmdlets 1/AboutPSProviders.Koans.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Describe 'Function Provider' {
$Functions[3].ScriptBlock | Should -BeOfType ScriptBlock
__ | Should -Be $Functions[1].ScriptBlock.ToString().Length

$Functions[4] | Get-Content | Should -BeOfType [__]
$Functions[4] | Get-Content | Should -BeOfType [____]
}

It 'allows you to rename the functions however you wish' {
Expand All @@ -214,7 +214,7 @@ Describe 'Function Provider' {
syntax must be used to indicate to the PowerShell parser that all contained characters
are part of the variable name.
#>
${function:Test-Function} | Should -BeOfType [__]
${function:Test-Function} | Should -BeOfType [____]
}

It 'can be defined using variable syntax' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ Describe 'ErrorRecord' {

It 'is an ErrorRecord' {
# At times, even tautologies can make sense of what is, and is not.
$ErrorRecord -is [__] | Should -BeTrue
$ErrorRecord -is [____] | Should -BeTrue
}

It 'always contains a reference to an Exception' {
$ErrorRecord.Exception | Should -Not -BeNullOrEmpty
$ErrorRecord.Exception -is [__] | Should -BeTrue
$ErrorRecord.Exception -is [____] | Should -BeTrue
'____' | Should -Be $ErrorRecord.Exception.Message
}

Expand Down Expand Up @@ -234,8 +234,8 @@ Describe 'Types of Errors' {
}
catch {
# A red ball is thrown... and what is caught?
$_ -is [__] | Should -BeTrue
$_.Exception -is [__] | Should -BeTrue
$_ -is [____] | Should -BeTrue
$_.Exception -is [____] | Should -BeTrue
'____' | Should -Be $_.Exception.Message
}
}
Expand Down Expand Up @@ -293,8 +293,8 @@ Describe 'Types of Errors' {
}
catch {
# What can we catch here?
$_ -is [__] | Should -BeTrue
$_.Exception -is [__] | Should -BeTrue
$_ -is [____] | Should -BeTrue
$_.Exception -is [____] | Should -BeTrue
'____' | Should -Be $_.Exception.Message
'____' | Should -Be $_.TargetObject.Secret
}
Expand All @@ -313,8 +313,8 @@ Describe 'Types of Errors' {
Write-Error @Params
}
catch {
$_ -is [__] | Should -BeTrue
[__] | Should -Be $_.Exception.GetType()
$_ -is [____] | Should -BeTrue
[____] | Should -Be $_.Exception.GetType()
'____' | Should -Be $_.Exception.Message
@('____', '____', '____') | Should -Be $_.TargetObject[3..1]
}
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutConditionals.Koans.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Describe 'Switch' {
}

$Variable | Should -Be -1
$Variable | Should -BeOfType [__]
$Variable | Should -BeOfType [____]
}

It 'can go through multiple branches' {
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutTypeOperators.Koans.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Describe 'Type Operators' {

It 'examines the type of the left hand object' {
45 -isnot [double] | Should -BeTrue
'string' -is [__] | Should -BeTrue
'string' -is [____] | Should -BeTrue
}

It 'is useful for determining available methods' {
Expand Down
32 changes: 18 additions & 14 deletions PSKoans/Koans/Foundations/AboutVariables.Koans.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ Describe 'Variable Assignment' {
It 'infers types on its own' {
$Number = 10

$Number | Should -BeOfType [__]
$Number | Should -BeOfType [____]
}

It 'can directly compare types' {
# For each task, a different tool.
$Number = 5
$Number -is [int] | Should -BeTrue
$Number | Should -BeOfType [__]
$Number | Should -BeOfType [____]

$Text = 'Every worthwhile step is uphill.'
$ExpectedType = __
Expand All @@ -56,8 +56,8 @@ Describe 'Variable Assignment' {
# Its contents may choose their own kind, or it be chosen for them.
$String = [string]$true

$Number | Should -BeOfType [__]
$String | Should -BeOfType [__]
$Number | Should -BeOfType [____]
$String | Should -BeOfType [____]
}

It 'distinguishes between types of numbers' {
Expand All @@ -70,23 +70,27 @@ Describe 'Variable Assignment' {
$NotInteger = 12.0

$Integer | Should -BeOfType [int]
$NotInteger | Should -BeOfType [__]
$NotInteger | Should -BeOfType [____]
}

It 'allows you to declare constant variables' {
{
$RemoveConstant = {
Set-Variable -Name 'Constant' -Value 25 -Option Constant
# The next operation will never succeed; constant variables cannot be altered.
# Try uncommenting the below line to see what happens.
# Constant variables cannot be altered.

# $Constant = 'NewValue'
} | Should -Throw
{
# Contrast Read-Only variables, which can be later removed
# So what happens if we try to modify $Constant in some way?
$____ = 'NewValue'
}
$RemoveConstant | Should -Throw -ExpectedMessage '____'

$RemoveReadOnly = {
# Contrast Read-Only variables, which can be later removed (if you do it right.)
Set-Variable -Name 'Constant' -Value 25 -Option ReadOnly
Remove-Variable -Name 'Constant' -Force
# While these variables can be Removed, they cannot be directly altered.
Remove-Variable -Name '____' -Force -ErrorAction Stop
$Constant = 2
$Constant++
} | Should -Not -Throw
}
$RemoveReadOnly | Should -Not -Throw
}
}

0 comments on commit 9690b0a

Please sign in to comment.