Skip to content

Commit

Permalink
Extended the style rules for files in the Dependencies folder (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
it-praktyk authored and nohwnd committed May 4, 2018
1 parent 870e16a commit 55c0b15
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion Dependencies/Axiom/Axiom.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

. $PSScriptRoot\Verify-Type.ps1

. $PSScriptRoot\Verify-AssertionFailed.ps1
. $PSScriptRoot\Verify-AssertionFailed.ps1
4 changes: 2 additions & 2 deletions Dependencies/Axiom/Verify-AssertionFailed.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function Verify-AssertionFailed {
$err = $_
$err
}

if (-not $assertionExceptionThrown) {
$result = if ($null -eq $err) { "no assertion failure error was thrown!" }
$result = if ($null -eq $err) { "no assertion failure error was thrown!" }
else { "other error was thrown! $($err | Format-List -Force * | Out-String)" }
throw [Exception]"Expected the script block { $ScriptBlock } to fail in Pester assertion, but $result"
}
Expand Down
6 changes: 3 additions & 3 deletions Dependencies/Axiom/Verify-Equal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
if ($Expected -ne $Actual) {
$message = "Expected and actual values differ!`n"+
"Expected: '$Expected'`n"+
"Actual : '$Actual'"
"Actual : '$Actual'"
if ($Expected -is [string] -and $Actual -is [string]) {
$message += "`nExpected length: $($Expected.Length)`nActual length: $($Actual.Length)"
}
throw [Exception]$message
}

$Actual
}
}
2 changes: 1 addition & 1 deletion Dependencies/Axiom/Verify-False.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ function Verify-False {
}

$Actual
}
}
4 changes: 2 additions & 2 deletions Dependencies/Axiom/Verify-NotNull.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ function Verify-NotNull {
if ($null -eq $Actual) {
throw [Exception]"Expected not `$null but got `$null."
}

$Actual
}
}
4 changes: 2 additions & 2 deletions Dependencies/Axiom/Verify-NotSame.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
if ([object]::ReferenceEquals($Expected, $Actual)) {
throw [Exception]"Expected the objects to be different instance but they were the same instance."
}

$Actual
}
}
4 changes: 2 additions & 2 deletions Dependencies/Axiom/Verify-Null.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ function Verify-Null {
if ($null -ne $Actual) {
throw [Exception]"Expected `$null but got '$Actual'."
}

$Actual
}
}
4 changes: 2 additions & 2 deletions Dependencies/Axiom/Verify-Same.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ function Verify-Same {
if (-not [object]::ReferenceEquals($Expected, $Actual)) {
throw [Exception]"Expected the objects to be the same instance but they were not."
}

$Actual
}
}
6 changes: 3 additions & 3 deletions Dependencies/Axiom/Verify-Throw.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Verify-Throw
function Verify-Throw
{
param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
Expand All @@ -14,8 +14,8 @@ function Verify-Throw
$exceptionThrown = $true
$_
}

if (-not $exceptionThrown) {
throw [Exception]"An exception was expected, but no exception was thrown!"
}
}
}
2 changes: 1 addition & 1 deletion Dependencies/Axiom/Verify-True.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ function Verify-True {
}

$Actual
}
}
6 changes: 3 additions & 3 deletions Dependencies/Axiom/Verify-Type.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

if ($Actual -isnot $Expected) {
$message = "Expected value to be of type $($Expected.FullName)"
$Actual = "but got " + $(if ($null -eq $Actual) { "'<null>'" }
$Actual = "but got " + $(if ($null -eq $Actual) { "'<null>'" }
else { "'$($Actual.GetType().FullName)'" })
throw [Exception]"$message, $Actual"
}

$Actual
}
}
35 changes: 17 additions & 18 deletions Dependencies/Format/Format.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$here = $MyInvocation.MyCommand.Path | Split-Path
Get-Module Axiom,Format | Remove-Module
Import-Module $here\..\Axiom\Axiom.psm1 -ErrorAction 'stop' -DisableNameChecking
Import-Module $here\..\Axiom\Axiom.psm1 -ErrorAction 'stop' -DisableNameChecking
Import-Module $here\Format.psm1 -ErrorAction 'stop' -DisableNameChecking

function New-PSObject ([hashtable]$Property) {
Expand All @@ -9,30 +9,30 @@ function New-PSObject ([hashtable]$Property) {

function New-Dictionary ([hashtable]$Hashtable) {
$d = new-object "Collections.Generic.Dictionary[string,object]"

$Hashtable.GetEnumerator() | foreach { $d.Add($_.Key, $_.Value) }

$d
}

# Add-Type -TypeDefinition 'namespace Assertions.TestType { public class Person { public string Name {get;set;} public int Age {get;set;}}}'
Describe "Format-Collection" {
Describe "Format-Collection" {
It "Formats collection of values '<value>' to '<expected>' using comma separator" -TestCases @(
@{ Value = (1, 2, 3); Expected = "@(1, 2, 3)" }
) {
) {
param ($Value, $Expected)
Format-Collection -Value $Value | Verify-Equal $Expected
}
}

Describe "Format-Number" {
Describe "Format-Number" {
It "Formats number to use . separator (tests anything only on non-english systems --todo)" -TestCases @(
@{ Value = 1.1; },
@{ Value = [double] 1.1; },
@{ Value = [float] 1.1; },
@{ Value = [single] 1.1; },
@{ Value = [decimal] 1.1; }
) {
) {
param ($Value)
Format-Number -Value $Value | Verify-Equal "1.1"
}
Expand All @@ -43,20 +43,20 @@ Describe "Format-Number" {
# It "Formats object '<value>' to '<expected>'" -TestCases @(
# @{ Value = (New-PSObject @{Name = 'Jakub'; Age = 28}); Expected = "PSObject{Age=28; Name=Jakub}"},
# @{ Value = (New-Object -Type Assertions.TestType.Person -Property @{Name = 'Jakub'; Age = 28}); Expected = "Assertions.TestType.Person{Age=28; Name=Jakub}"}
# ) {
# ) {
# param ($Value, $Expected)
# Format-Object -Value $Value | Verify-Equal $Expected
# }

# It "Formats object '<value>' with selected properties '<selectedProperties>' to '<expected>'" -TestCases @(
# @{ Value = (New-PSObject @{Name = 'Jakub'; Age = 28}); SelectedProperties = "Age"; Expected = "PSObject{Age=28}"},
# @{ Value = (Get-Process -Name Idle); SelectedProperties = 'Name', 'Id'; Expected = "Diagnostics.Process{Id=0; Name=Idle}" },
# @{
# @{
# Value = (New-Object -Type Assertions.TestType.Person -Property @{Name = 'Jakub'; Age = 28})
# SelectedProperties = 'Name'
# Expected = "Assertions.TestType.Person{Name=Jakub}"
# }
# ) {
# ) {
# param ($Value, $SelectedProperties, $Expected)
# Format-Object -Value $Value -Property $SelectedProperties | Verify-Equal $Expected
# }
Expand All @@ -72,13 +72,13 @@ Describe "Format-Boolean" {
}
}

Describe "Format-Null" {
Describe "Format-Null" {
It "Formats null to '`$null'" {
Format-Null | Verify-Equal '$null'
}
}

Describe "Format-String" {
Describe "Format-String" {
It "Formats empty string to '<empty>'" {
Format-String -Value "" | Verify-Equal '<empty>'
}
Expand All @@ -88,20 +88,20 @@ Describe "Format-String" {
}
}

Describe "Format-DateTime" {
Describe "Format-DateTime" {
It "Formats date to orderable format with ticks" {
Format-Date -Value ([dateTime]239842659899234234) | Verify-Equal '0761-01-12T16:06:29.9234234'
}
}

Describe "Format-ScriptBlock" {
Describe "Format-ScriptBlock" {
It "Formats scriptblock as string with curly braces" {
Format-ScriptBlock -Value {abc} | Verify-Equal '{abc}'
}
}

# skipping object formatting for now
# Describe "Format-Hashtable" {
# Describe "Format-Hashtable" {
# It "Formats empty hashtable as @{}" {
# Format-Hashtable @{} | Verify-Equal '@{}'
# }
Expand All @@ -117,7 +117,7 @@ Describe "Format-ScriptBlock" {
# }

# skipping object formatting for now
# Describe "Format-Dictionary" {
# Describe "Format-Dictionary" {
# It "Formats empty dictionary as @{}" {
# Format-Dictionary (New-Dictionary @{}) | Verify-Equal 'Dictionary{}'
# }
Expand Down Expand Up @@ -149,7 +149,7 @@ Describe "Format-Nicely" {
#@{ Value = (New-Object -Type Assertions.TestType.Person -Property @{Name = 'Jakub'; Age = 28}); Expected = "Assertions.TestType.Person{Age=28; Name=Jakub}"}
#@{ Value = @{Name = 'Jakub'; Age = 28}; Expected = '@{Age=28; Name=Jakub}' }
#@{ Value = New-Dictionary @{Age = 28; Name = 'Jakub'}; Expected = 'Dictionary{Age=28; Name=Jakub}' }
) {
) {
param($Value, $Expected)
Format-Nicely -Value $Value | Verify-Equal $Expected
}
Expand Down Expand Up @@ -177,7 +177,7 @@ Describe "Format-Type" {
Format-Type -Value $Value | Verify-Equal $Expected
}
}


Describe "Get-ShortType" {
It "Given '<value>' it returns the correct shortened type name '<expected>'" -TestCases @(
Expand All @@ -192,4 +192,3 @@ Describe "Get-ShortType" {
Get-ShortType -Value $Value | Verify-Equal $Expected
}
}

Loading

0 comments on commit 55c0b15

Please sign in to comment.