-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAST.Tests.ps1
More file actions
131 lines (127 loc) · 6.04 KB
/
Copy pathAST.Tests.ps1
File metadata and controls
131 lines (127 loc) · 6.04 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.8.0'; GUID = 'a699dea5-2c73-4616-a270-1f7abb777e71' }
Describe 'Core' {
Context "Function: 'Get-AstScript'" {
It 'Get-AstScript gets the script Ast' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$script = Get-AstScript -Path $path
$script | Should -Not -BeNullOrEmpty
$script.Ast | Should -BeOfType [System.Management.Automation.Language.ScriptBlockAst]
}
}
Context "Function: 'Get-AstFunction'" {
It 'Get-AstFunction gets the function Ast' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$function = Get-AstFunction -Path $path
$function | Should -Not -BeNullOrEmpty
$function.Ast | Should -BeOfType [System.Management.Automation.Language.FunctionDefinitionAst]
}
}
Context "Function: 'Get-AstCommand'" {
It 'Get-AstCommand gets the command Ast' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$command = Get-AstCommand -Path $path
$command | Should -Not -BeNullOrEmpty
$command.Ast | Should -BeOfType [System.Management.Automation.Language.CommandAst]
}
}
}
Describe 'Functions' {
Context "Function: 'Get-AstFunctionType'" {
It 'Get-AstFunctionType gets the function type' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$functionType = Get-AstFunctionType -Path $path
$functionType.Type | Should -Be 'Function'
}
}
Context "Function: 'Get-AstFunctionName'" {
It 'Get-AstFunctionName gets the function name' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$functionName = Get-AstFunctionName -Path $path
$functionName | Should -Be 'Test-Function'
}
}
Context "Function: 'Get-AstFunctionAlias'" {
It 'Get-AstFunctionAlias gets the function alias' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$functionAlias = Get-AstFunctionAlias -Path $path
$functionAlias.Alias | Should -Contain 'Test'
$functionAlias.Alias | Should -Contain 'TestFunc'
$functionAlias.Alias | Should -Contain 'Test-Func'
}
}
}
Describe 'Lines' {
Context 'Function: Get-AstLineComment' {
It 'Get-AstLineComment gets the line comment' {
$line = '# This is a comment'
$line = Get-AstLineComment -Line $line
$line | Should -Be '# This is a comment'
}
It 'Get-AstLineComment gets the line comment without leading whitespace' {
$line = ' # This is a comment'
$line = Get-AstLineComment -Line $line
$line | Should -Be '# This is a comment'
}
It 'Get-AstLineComment gets the line comment but not the command' {
$line = ' Get-Command # This is a comment '
$line = Get-AstLineComment -Line $line
$line | Should -Be '# This is a comment '
}
It 'Get-AstLineComment returns nothing when no comment is present' {
$line = 'Get-Command'
$line | Get-AstLineComment | Should -BeNullOrEmpty
}
}
}
Describe 'Scripts' {
Context "Function: 'Get-AstScriptCommands'" {
It 'Get-AstScriptCommands gets the script commands' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$commands = Get-AstScriptCommand -Path $path
$commands | Should -Not -BeNullOrEmpty
$commands | Should -BeOfType [pscustomobject]
$commands.Name | Should -Not -Contain 'ForEach-Object'
$commands.Name | Should -Not -Contain 'Get-Process'
$commands.Name | Should -Not -Contain 'ipmo'
$commands.Name | Should -Contain 'Register-ArgumentCompleter'
$commands.Name | Should -Not -Contain '.'
$commands.Name | Should -Not -Contain '&'
}
It 'Get-AstScriptCommands gets the script commands (recursive)' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$commands = Get-AstScriptCommand -Path $path -Recurse
$commands | Should -Not -BeNullOrEmpty
$commands | Should -BeOfType [pscustomobject]
$commands.Name | Should -Contain 'ForEach-Object'
$commands.Name | Should -Contain 'Get-Process'
$commands.Name | Should -Contain 'ipmo'
$commands.Name | Should -Contain 'Register-ArgumentCompleter'
$commands.Name | Should -Not -Contain '.'
$commands.Name | Should -Not -Contain '&'
}
It 'Get-AstScriptCommands gets the script commands with call operators' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$commands = Get-AstScriptCommand -Path $path -IncludeCallOperators
$commands | Should -Not -BeNullOrEmpty
$commands | Should -BeOfType [pscustomobject]
$commands.Name | Should -Not -Contain 'ForEach-Object'
$commands.Name | Should -Not -Contain 'Get-Process'
$commands.Name | Should -Not -Contain 'ipmo'
$commands.Name | Should -Contain 'Register-ArgumentCompleter'
$commands.Name | Should -Not -Contain '.'
$commands.Name | Should -Not -Contain '&'
}
It 'Get-AstScriptCommands gets the script commands with call operators (recursive)' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$commands = Get-AstScriptCommand -Path $path -Recurse -IncludeCallOperators
$commands | Should -Not -BeNullOrEmpty
$commands | Should -BeOfType [pscustomobject]
$commands.Name | Should -Contain 'ForEach-Object'
$commands.Name | Should -Contain 'Get-Process'
$commands.Name | Should -Contain 'ipmo'
$commands.Name | Should -Contain 'Register-ArgumentCompleter'
$commands.Name | Should -Contain '.'
$commands.Name | Should -Contain '&'
}
}
}