forked from SublimeText/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsyntax_test_Pester.ps1
More file actions
61 lines (55 loc) · 2.35 KB
/
syntax_test_Pester.ps1
File metadata and controls
61 lines (55 loc) · 2.35 KB
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
# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax"
BeforeAll {
# your function
function Get-Planet ([string]$Name='*')
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.powershell meta.function.powershell
# ^^^^^^^^ keyword.declaration.function.powershell
# ^^^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.parameters.begin.powershell
# ^ punctuation.section.brackets.begin.powershell
# ^^^^^^ storage.type.powershell
# ^ punctuation.section.brackets.end.powershell
# ^^^^^ variable.parameter.powershell
# ^ punctuation.definition.variable.begin.powershell
# ^ keyword.operator.assignment.powershell
# ^^^ meta.string.powershell string.quoted.single.powershell
# ^ punctuation.definition.string.begin.powershell
# ^ punctuation.definition.string.end.powershell
# ^ punctuation.section.parameters.end.powershell
{
$planets = @(
@{ Name = 'Mercury' }
@{ Name = 'Venus' }
@{ Name = 'Earth' }
@{ Name = 'Mars' }
@{ Name = 'Jupiter' }
@{ Name = 'Saturn' }
@{ Name = 'Uranus' }
@{ Name = 'Neptune' }
) | foreach { [PSCustomObject]$_ }
$planets | where { $_.Name -like $Name }
}
}
# Pester tests
Describe 'Get-Planet' {
It "Given no parameters, it lists all 8 planets" {
$allPlanets = Get-Planet
$allPlanets.Count | Should -Be 8
}
Context "Filtering by Name" {
It "Given valid -Name '<Filter>', it returns '<Expected>'" -TestCases @(
@{ Filter = 'Earth'; Expected = 'Earth' }
@{ Filter = 'ne*' ; Expected = 'Neptune' }
@{ Filter = 'ur*' ; Expected = 'Uranus' }
@{ Filter = 'm*' ; Expected = 'Mercury', 'Mars' }
) {
param ($Filter, $Expected)
$planets = Get-Planet -Name $Filter
$planets.Name | Should -Be $Expected
}
It "Given invalid parameter -Name 'Alpha Centauri', it returns `$null" {
$planets = Get-Planet -Name 'Alpha Centauri'
$planets | Should -Be $null
}
}
}