Skip to content

Commit c5c1b8f

Browse files
author
James Brundage
committed
Updating Templates Tests
1 parent 2b2049a commit c5c1b8f

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
describe 'PipeScript Templates' {
2+
context 'Template Files' {
3+
it 'Allows you to embed PipeScript in many file types' {
4+
@'
5+
namespace TestProgram/*{Get-Random}*/ {
6+
public static class Program {
7+
public static string Hello() {
8+
string helloMessage = /*{param($n)
9+
if ($n) {
10+
"`"hello $n`""
11+
} else {
12+
'"hello"', '"hello world"', '"hey there"', '"howdy"' | Get-Random
13+
}
14+
}*/ string.Empty;
15+
return helloMessage;
16+
}
17+
}
18+
}
19+
'@ |
20+
Set-Content ".\HelloWorld.ps1.cs"
21+
$AddedFile = Invoke-PipeScript .\HelloWorld.ps1.cs
22+
$addedType = Add-Type -TypeDefinition (Get-Content $addedFile.FullName -Raw) -PassThru
23+
$addedType::Hello() | Should -belike 'H*'
24+
25+
$addedFile2 = Invoke-PipeScript .\HelloWorld.ps1.cs 1
26+
$addedType2 = Add-Type -TypeDefinition (Get-Content $addedFile.FullName -Raw) -PassThru
27+
$addedType2::Hello() | Should -be 'Hello 1'
28+
29+
Remove-Item .\HelloWorld.ps1.cs
30+
Remove-Item $AddedFile.FullName
31+
}
32+
}
33+
34+
context 'Markdown' {
35+
it 'Can embed a value inline' {
36+
Invoke-PipeScript {
37+
$mdt = a.md template '`|{1}|`'
38+
$mdt.Evaluate()
39+
} | Should -be "1"
40+
}
41+
42+
it 'Can embed a multiline value' {
43+
Invoke-PipeScript {
44+
$mdt = a.md template @'
45+
~~~PipeScript{
46+
"hello world"
47+
}~~~
48+
'@
49+
$mdt.Evaluate()
50+
} | Should -be 'Hello world'
51+
}
52+
53+
it 'Can embed in an HTML comment' {
54+
Invoke-PipeScript {
55+
$mdt = a.md template '<!--{1}-->'
56+
$mdt.Evaluate()
57+
} | Should -be "1"
58+
}
59+
60+
it 'Can embed in a CSS comment' {
61+
Invoke-PipeScript {
62+
$mdt = a.md template '/*{1}*/'
63+
$mdt.Evaluate()
64+
} | Should -be "1"
65+
}
66+
}
67+
68+
context 'JSON' {
69+
it 'Can embed JSON' {
70+
Invoke-PipeScript {
71+
$jsonTemplate = my.json template '/*{1}*/'
72+
$jsonTemplate.Evaluate()
73+
} | Should -be "1"
74+
}
75+
76+
it 'Will turn non-string output into JSON' {
77+
Invoke-PipeScript {
78+
$jsonTemplate = my.json template '/*{Get-Process -id $pid | select name,id}*/'
79+
$jsonTemplate.Evaluate()
80+
} | ConvertFrom-Json |
81+
Select-Object -ExpandProperty Name |
82+
Should -Be (Get-process -id $pid).Name
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)