Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AST
# Ast
Comment thread
MariusStorhaug marked this conversation as resolved.

A PowerShell module for using the Abstract Syntax Tree (AST) on any PowerShell code.

Expand All @@ -12,8 +12,8 @@ This uses the following external resources:
To install the module from the PowerShell Gallery, you can use the following command:

```powershell
Install-PSResource -Name AST
Import-Module -Name AST
Install-PSResource -Name Ast
Import-Module -Name Ast
```

## Usage
Expand All @@ -25,7 +25,7 @@ Here is a list of example that are typical use cases for the module.
This example shows how to get the function name from a script.

```powershell
Get-ASTFunctionName -Path 'Test-Me.ps1'
Get-AstFunctionName -Path 'Test-Me.ps1'
Test-Me
```

Expand Down
72 changes: 36 additions & 36 deletions tests/AST.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' }

Describe 'Core' {
Context "Function: 'Get-ASTScript'" {
It 'Get-ASTScript gets the script AST' {
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 = 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' {
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 = 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' {
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 = 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' {
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 = Get-AstFunctionType -Path $path
$functionType.Type | Should -Be 'Function'
}
}
Context "Function: 'Get-ASTFunctionName'" {
It 'Get-ASTFunctionName gets the function name' {
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 = Get-AstFunctionName -Path $path
$functionName | Should -Be 'Test-Function'
}
}
Context "Function: 'Get-ASTFunctionAlias'" {
It 'Get-ASTFunctionAlias gets the function alias' {
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 = Get-AstFunctionAlias -Path $path
$functionAlias.Alias | Should -Contain 'Test'
$functionAlias.Alias | Should -Contain 'TestFunc'
$functionAlias.Alias | Should -Contain 'Test-Func'
Expand All @@ -54,34 +54,34 @@ Describe 'Functions' {
}

Describe 'Lines' {
Context 'Function: Get-ASTLineComment' {
It 'Get-ASTLineComment gets the line comment' {
Context 'Function: Get-AstLineComment' {
It 'Get-AstLineComment gets the line comment' {
$line = '# This is a comment'
$line = Get-ASTLineComment -Line $line
$line = Get-AstLineComment -Line $line
$line | Should -Be '# This is a comment'
}
It 'Get-ASTLineComment gets the line comment without leading whitespace' {
It 'Get-AstLineComment gets the line comment without leading whitespace' {
$line = ' # This is a comment'
$line = Get-ASTLineComment -Line $line
$line = Get-AstLineComment -Line $line
$line | Should -Be '# This is a comment'
}
It 'Get-ASTLineComment gets the line comment but not the command' {
It 'Get-AstLineComment gets the line comment but not the command' {
$line = ' Get-Command # This is a comment '
$line = Get-ASTLineComment -Line $line
$line = Get-AstLineComment -Line $line
$line | Should -Be '# This is a comment '
}
It 'Get-ASTLineComment returns nothing when no comment is present' {
It 'Get-AstLineComment returns nothing when no comment is present' {
$line = 'Get-Command'
$line | Get-ASTLineComment | Should -BeNullOrEmpty
$line | Get-AstLineComment | Should -BeNullOrEmpty
}
}
}

Describe 'Scripts' {
Context "Function: 'Get-ASTScriptCommands'" {
It 'Get-ASTScriptCommands gets the script commands' {
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 = Get-AstScriptCommand -Path $path
$commands | Should -Not -BeNullOrEmpty
$commands | Should -BeOfType [pscustomobject]
$commands.Name | Should -Not -Contain 'ForEach-Object'
Expand All @@ -91,9 +91,9 @@ Describe 'Scripts' {
$commands.Name | Should -Not -Contain '.'
$commands.Name | Should -Not -Contain '&'
}
It 'Get-ASTScriptCommands gets the script commands (recursive)' {
It 'Get-AstScriptCommands gets the script commands (recursive)' {
$path = Join-Path $PSScriptRoot 'src\Test-Function.ps1'
$commands = Get-ASTScriptCommand -Path $path -Recurse
$commands = Get-AstScriptCommand -Path $path -Recurse
$commands | Should -Not -BeNullOrEmpty
$commands | Should -BeOfType [pscustomobject]
$commands.Name | Should -Contain 'ForEach-Object'
Expand All @@ -103,9 +103,9 @@ Describe 'Scripts' {
$commands.Name | Should -Not -Contain '.'
$commands.Name | Should -Not -Contain '&'
}
It 'Get-ASTScriptCommands gets the script commands with call operators' {
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 = Get-AstScriptCommand -Path $path -IncludeCallOperators
$commands | Should -Not -BeNullOrEmpty
$commands | Should -BeOfType [pscustomobject]
$commands.Name | Should -Not -Contain 'ForEach-Object'
Expand All @@ -115,9 +115,9 @@ Describe 'Scripts' {
$commands.Name | Should -Not -Contain '.'
$commands.Name | Should -Not -Contain '&'
}
It 'Get-ASTScriptCommands gets the script commands with call operators (recursive)' {
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 = Get-AstScriptCommand -Path $path -Recurse -IncludeCallOperators
$commands | Should -Not -BeNullOrEmpty
$commands | Should -BeOfType [pscustomobject]
$commands.Name | Should -Contain 'ForEach-Object'
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Test-Function.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[Alias('Test-Func')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingCmdletAliases',
Justification = 'Want to see that ASTCommand actually can get aliases.'
Justification = 'Want to see that AstCommand actually can get aliases.'
)]
[CmdletBinding()]
param (
Expand Down
Loading