Skip to content

Commit

Permalink
Improve behaviour of casting and comparing [Blank] (vexx32#157)
Browse files Browse the repository at this point in the history
Improve behaviour of [Blank] & Small Refactoring
  • Loading branch information
vexx32 authored Apr 24, 2019
1 parent f89c11b commit d75c84f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
20 changes: 18 additions & 2 deletions PSKoans/Classes/Blank.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@ class Blank {
[string] ToString() {
return $null
}

[bool] op_Equals([object] $other) {

[bool] Equals([object] $other) {
return $false
}

static [bool] op_Equality([Blank] $self, [object] $other) {
return $false
}

static [bool] op_Inequality([Blank] $self, [object] $other) {
return $true
}

static [bool] op_Explicit([Blank] $Instance) {
return $false
}

static [bool] op_Implicit([Blank] $Instance) {
return $false
}
}
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutAssertions.Koans.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Describe 'Equality' {

It 'is a simple comparison' {
# Some truths are absolute.
__ | Should -Be $true
'__' | Should -Be 'True!'
}

It 'expects you to fill in values' {
Expand Down
7 changes: 3 additions & 4 deletions Tests/KoanValidation.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ Describe "Koan Assessment" {
$Scripts = Get-ChildItem -Path $KoanFolder -Recurse -Filter '*.Koans.ps1'

# TestCases are splatted to the script so we need hashtables
$TestCases = $Scripts | ForEach-Object { @{File = $_} }
$TestCases = $Scripts | ForEach-Object { @{File = $_ } }
It "<File> koans should be valid powershell" -TestCases $TestCases {
param($File)

$File.FullName | Should -Exist

$FileContents = Get-Content -Path $File.FullName -ErrorAction Stop
$Errors = $null
[System.Management.Automation.PSParser]::Tokenize($FileContents, [ref]$Errors) > $null
$Errors = $Tokens = $null
[System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref]$Tokens, [ref]$Errors) > $null
$Errors.Count | Should -Be 0
}
}

0 comments on commit d75c84f

Please sign in to comment.