Tests/FormatTools.Tests.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
Describe "Tests Format-Banner" {
    BeforeAll {
        $strs = "this is","a test"
        $banner = Format-Banner -strings $strs -asObject
        $ExpectedOutput = @(
" ",
" ##### # # # #### # #### ",
" # # # # # # # ",
" # ###### # #### # #### ",
" # # # # # # # ",
" # # # # # # # # # ",
" # # # # #### # #### ",
" ",
" ## ##### ###### #### ##### ",
" # # # # # # ",
" # # # ##### #### # ",
" ###### # # # # ",
" # # # # # # # ",
" # # # ###### #### # ",
""
        )
    }
    It "Format-Banner should collect strings correctly" {
        $banner.OriginalStrings[0] | should be $strs[0]
        $banner.OriginalStrings[1] | should be $strs[1]
    }
    It "The ToString method should render the correct output" {
        $StringOutput = $banner.ToString().Split("`n")
        $StringOutput.Count | Should be $expectedOutput.Count
        for($i = 0; $i -lt $StringOutput.Count; $i++) {
            $StringOutput[$i] | Should be $expectedOutput[$i]
        }
    }
    It "The default should return the properly formatted banner" {
        $strs = "this is","a test"
        $stringoutput = (Format-Banner -strings $strs).Split("`n")
        $StringOutput.Count | Should be $expectedOutput.Count
        for($i = 0; $i -lt $StringOutput.Count; $i++) {
            $StringOutput[$i] | Should be $expectedOutput[$i]
        }
        
    }
}

Describe "Format-String" {
    BeforeAll {
        $Text = "This is a test of the emergency broadcasting system"
"This is a test of the emergency broadcasting system"
        $longText = "abcd" * 40
        $expectedStrings = "This is a test of the","emergency broadcasting system"
        $expectedWithIndent = " This is a test of the","emergency broadcasting system"
        $expectedWithPad = " This is a test of the"," emergency broadcasting"," system"
        $expectedWithPadAndIndent = " This is a test of the"," emergency broadcasting"," system"
    }
    It "Breaks text correctly" {
        $observedOutput = Format-String -width 30 $Text
        $observedOutput.Count | should be 2
        $observedOutput[0] | should be $expectedStrings[0]
        $observedOutput[1] | should be $expectedStrings[1]
    }
    It "Indents text correctly" {
        $observedOutput = Format-String -width 30 $Text -indent
        $observedOutput.Count | should be 2
        $observedOutput[0] | should be $expectedWithIndent[0]
        $observedOutput[1] | should be $expectedWithIndent[1]
    }
    It "Pads text correctly" {
        $observedOutput = Format-String -width 30 $Text -padw 4
        $observedOutput.Count | should be 3
        $observedOutput[0] | should be $expectedWithPad[0]
        $observedOutput[1] | should be $expectedWithPad[1]
        $observedOutput[2] | should be $expectedWithPad[2]
    }
    It "Pads and indents text correctly" {
        $observedOutput = Format-String -width 30 $Text -padw 4 -indent
        $observedOutput.Count | should be 3
        $observedOutput[0] | should be $expectedWithPadAndIndent[0]
        $observedOutput[1] | should be $expectedWithPadAndIndent[1]
        $observedOutput[2] | should be $expectedWithPadAndIndent[2]
    }

}

Describe "Get-Lorem" {
    It "Returns the proper count of words" {
        (Get-Lorem -count 44).split(" ").Count | Should be 44
    }
    It "The last character is a period" {
        (get-lorem -count 20)[-1] | Should be "."
    }
    It "The first character should be capitalized" {
        (get-lorem -count 10)[0] | Should MatchExactly "[A-Z]"
    }
}

Describe "New-TableFormat" {
    BeforeAll {
        $output = get-date | New-TableFormat day,dayofweek,@{Label="thing";Expr={"static"}}
    }
    It "Should emit valid XML" {
        { [xml]$output } | Should not throw
    }
    It "Should have the proper headers" {
        $x = [xml]$output
        $x.View.TableControl.TableHeaders.TableColumnHeader.Label[0] | should be "day"
        $x.View.TableControl.TableHeaders.TableColumnHeader.Label[1] | should be "dayofweek"
        $x.View.TableControl.TableHeaders.TableColumnHeader.Label[2] | should be "thing"
    }
    It "Should have the proper rows" {
        $x = [xml]$output
        $x.View.TableControl.TableRowEntries.TableRowEntry.TableColumnItems.TableColumnItem[0].PropertyName | should be "day"
        $x.View.TableControl.TableRowEntries.TableRowEntry.TableColumnItems.TableColumnItem[1].PropertyName | should be "dayofweek"
        $x.View.TableControl.TableRowEntries.TableRowEntry.TableColumnItems.TableColumnItem[2].ScriptBlock | should be '"static"'
    }

}