wip/VerboseOutput.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# I am using this file to play with the verbose output,
# this might become a source of examples for assert, don't want to delete it
# so I commit it.


Get-Module Assert | remove-module ;
Import-module ./Assert.psd1

# messages:
# (in the result use $(Format-Nicely $variable) for the $Expected and $Actual messages so we can see what was actually there and detect errors better))
# expectation -> v "`$Expected is `$null, so we are expecting `$null."
# v -Difference "`$Actual is not equivalent to `$null, because it has a value of type $(Format-Nicely $Actual.GetType())."
# v -Equivalence "`$Actual is equivalent to `$null, because it is `$null."
& (Get-Module Assert) {
    function c ($a, $e) {
        Compare-Equivalent -Actual $a -Expected $e -Verbose
        "`n"
    }

    
    function mm ($string) { m "- $string" }
    function m ($string) { Write-Host -fore Cyan $string}
m ("-*"*40)
#mm "nulls"
#c -a 1 -e $null
#c -a $null -e $null


#mm "values"

#mm "bools"
#m "fixing bool for expected"
#c -a $false -e 'False'
#c -a $true -e 'False'

#m "fixing bool for actual"
#c -a 'False' -e $false
#c -a 'False' -e $true

#m compare scriptblocks by content
# c -a {} -e {}
# c -a { "hello" } -e { "hello" }

# c -a { } -e {}
# c -a { "hello"} -e { "hello" }

# m "normal boolean comparison"
# c -a $true -e $true
# c -a $false -e $false
# c -a $true -e $false
# c -a $false -e $true
# c -a "" -e $true
# c -a 1 -e $true
# c -a 0 -e $true
# c -a {} -e ""
# c -a "" -e {}

m compare objects 


$expected = [PSCustomObject]@{ 
    Name = 'Jakub' 
    Age = 28
    KnowsPowerShell = $true
    Languages = 'Czech', 'English' 
}

$actual = [PSCustomObject]@{ 
    Name = 'Jkb'
    KnowsPowerShell = 0
    Languages = 'Czech', 'English', 'German'
}

c -a $actual -e $expected
# m hashtables
# c -a @{} -e @{}
# c -a @() -e @{}

# c -a @{Name="Jakub"} -e @{}
# c -a @{} -e @{Name="Jakub"}
# c -a @{Name="Jakub"} -e @{Name="Jakub"}

# m collections
# c -a 1 -e @()
# c -a @() -e @()
# c -a @(1) -e @()
# c -a @(1,1) -e @(1,2)
}