Skip to content

Commit 3208530

Browse files
committed
0.1.1
Tests: - source code rendering tests
1 parent 8981cb0 commit 3208530

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
Describe 'Prepare-CoverageLineColors' {
2+
BeforeAll {
3+
. (Resolve-Path "$PSScriptRoot\..\..\..\src\templates\elements\source-code.ps1").Path
4+
. (Resolve-Path "$PSScriptRoot\..\..\..\src\utilities\string.ps1").Path
5+
. (Resolve-Path "$PSScriptRoot\..\..\..\src\utilities\object.ps1").Path
6+
}
7+
8+
Context 'Error' {
9+
It 'Should return $null' {
10+
$sourceFile = [PSCustomObject]@{
11+
'something_other_than_line' = 'lorem ipsum';
12+
}
13+
14+
$result = Prepare-CoverageLineColors -sourceFile $sourceFile
15+
$result | Should -Be $null
16+
}
17+
}
18+
19+
Context 'Happy flow' {
20+
It 'Should prepare color arrays for specified set of lines' {
21+
$sourceFile = [PSCustomObject]@{
22+
'line' = [PSCustomObject[]]@(
23+
# yellow
24+
[PSCustomObject]@{
25+
'@nr' = '1';
26+
'@mi' = '6';
27+
'@ci' = '3';
28+
'@mb' = '0';
29+
'@cb' = '0';
30+
},
31+
# green
32+
[PSCustomObject]@{
33+
'@nr' = '2';
34+
'@mi' = '0';
35+
'@ci' = '3';
36+
'@mb' = '0';
37+
'@cb' = '0';
38+
},
39+
# red
40+
[PSCustomObject]@{
41+
'@nr' = '3';
42+
'@mi' = '6';
43+
'@ci' = '0';
44+
'@mb' = '0';
45+
'@cb' = '0';
46+
}
47+
)
48+
}
49+
$yellowLines = New-Object System.Collections.Generic.List[String]
50+
$yellowLines.Add('1')
51+
$greenLines = New-Object System.Collections.Generic.List[String]
52+
$greenLines.Add('2')
53+
$redLines = New-Object System.Collections.Generic.List[String]
54+
$redLines.Add('3')
55+
$expected = New-Object System.Collections.Generic.List[Object]
56+
$expected.Add($yellowLines)
57+
$expected.Add($redLines)
58+
$expected.Add($greenLines)
59+
60+
$result = Prepare-CoverageLineColors -sourceFile $sourceFile
61+
$result | Should -Be $expected
62+
}
63+
}
64+
}
65+
66+
Describe 'Render-CoverageLineColors' {
67+
BeforeAll {
68+
. (Resolve-Path "$PSScriptRoot\..\..\..\src\templates\elements\source-code.ps1").Path
69+
. (Resolve-Path "$PSScriptRoot\..\..\..\src\utilities\string.ps1").Path
70+
. (Resolve-Path "$PSScriptRoot\..\..\..\src\utilities\object.ps1").Path
71+
}
72+
73+
Context 'Error' {
74+
It 'Should remove line coloring JS' {
75+
$template = @'
76+
something
77+
highlightLines([<!--yellow.lines-->], '<!--line.number.yellow-->', '<!--source.code.yellow-->');
78+
highlightLines([<!--red.lines-->], '<!--line.number.red-->', '<!--source.code.red-->');
79+
highlightLines([<!--green.lines-->], '<!--line.number.green-->', '<!--source.code.green-->');
80+
something else
81+
'@
82+
$template = $template.Replace("`r`n", "`n")
83+
$expected = @'
84+
something
85+
something else
86+
'@
87+
$expected = $expected.Replace("`r`n", "`n")
88+
89+
$sourceFile = [PSCustomObject]@{
90+
'something_other_than_line' = 'lorem ipsum';
91+
}
92+
93+
$result = Render-CoverageLineColors -template $template -sourcefile $sourceFile
94+
$result | Should -Be $expected
95+
}
96+
}
97+
98+
Context 'Happy flow' {
99+
It 'Should include yellow, red and green lines' {
100+
$template = @'
101+
something
102+
highlightLines([<!--yellow.lines-->], '<!--line.number.yellow-->', '<!--source.code.yellow-->');
103+
highlightLines([<!--red.lines-->], '<!--line.number.red-->', '<!--source.code.red-->');
104+
highlightLines([<!--green.lines-->], '<!--line.number.green-->', '<!--source.code.green-->');
105+
something else
106+
'@
107+
$template = $template.Replace("`r`n", "`n")
108+
$expected = @'
109+
something
110+
highlightLines([1], '<!--line.number.yellow-->', '<!--source.code.yellow-->');
111+
highlightLines([3], '<!--line.number.red-->', '<!--source.code.red-->');
112+
highlightLines([2], '<!--line.number.green-->', '<!--source.code.green-->');
113+
something else
114+
'@
115+
$expected = $expected.Replace("`r`n", "`n")
116+
117+
$sourceFile = [PSCustomObject]@{
118+
'line' = [PSCustomObject[]]@(
119+
# yellow
120+
[PSCustomObject]@{
121+
'@nr' = '1';
122+
'@mi' = '6';
123+
'@ci' = '3';
124+
'@mb' = '0';
125+
'@cb' = '0';
126+
},
127+
# green
128+
[PSCustomObject]@{
129+
'@nr' = '2';
130+
'@mi' = '0';
131+
'@ci' = '3';
132+
'@mb' = '0';
133+
'@cb' = '0';
134+
},
135+
# red
136+
[PSCustomObject]@{
137+
'@nr' = '3';
138+
'@mi' = '6';
139+
'@ci' = '0';
140+
'@mb' = '0';
141+
'@cb' = '0';
142+
}
143+
)
144+
}
145+
146+
$result = Render-CoverageLineColors -template $template -sourcefile $sourceFile
147+
$result | Should -Be $expected
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)