Skip to content

Instantly share code, notes, and snippets.

@bravo-kernel
Created June 25, 2022 16:47
Show Gist options
  • Save bravo-kernel/e5fc2e4178754b3ffabcc43fa690d77f to your computer and use it in GitHub Desktop.
Save bravo-kernel/e5fc2e4178754b3ffabcc43fa690d77f to your computer and use it in GitHub Desktop.
Three .mdx indentation cases to be fixed

EXAMPLE 1

function BeAwesome($ActualValue, [switch] $Negate)
{

[bool] $succeeded = $ActualValue -eq 'Awesome'
    if ($Negate) { $succeeded = -not $succeeded }

    if (-not $succeeded)
    {
        if ($Negate)
        {
            $failureMessage = "{$ActualValue} is Awesome"
        }
        else
        {
            $failureMessage = "{$ActualValue} is not Awesome"
        }
    }

    return New-Object psobject -Property @{
        Succeeded      = $succeeded
        FailureMessage = $failureMessage
    }
}

Add-ShouldOperator -Name  BeAwesome `
                    -Test  $function:BeAwesome `
                    -Alias 'BA'

PS C:\> "bad" | should -BeAwesome
{bad} is not Awesome

EXAMPLE 2

Describe "Validate important file" {
    BeforeAll {
        $samplePath = "$([IO.Path]::GetTempPath())/$([Guid]::NewGuid()).txt"
        Write-Host $samplePath
        1..100 | Set-Content -Path $samplePath
    }

It "File Contains 100 lines" {
        @(Get-Content $samplePath).Count | Should -Be 100
    }

    It "First ten lines should be 1 -\> 10" {
        @(Get-Content $samplePath -TotalCount 10) | Should -Be @(1..10)
    }

    AfterAll {
        Remove-Item -Path $samplePath
    }
}

EXAMPLE 3

Describe "Testing export formats" {
    BeforeAll {
        $filePath = "$([IO.Path]::GetTempPath())/$([Guid]::NewGuid())"
    }
    It "Test Export-CSV" {
        Get-ChildItem | Export-CSV -Path $filePath -NoTypeInformation
        $dir = Import-CSV -Path $filePath
        # ...

    }
    It "Test Export-Clixml" {
        Get-ChildItem | Export-Clixml -Path $filePath
        $dir = Import-Clixml -Path $filePath
        # ...

    }

AfterEach {
        if (Test-Path $file) {
            Remove-Item $file -Force
        }
    }
}
@bravo-kernel
Copy link
Author

bravo-kernel commented Jun 25, 2022

Fix pseudo code: add 4-char white-space to the first matching line without indentation (except for the first and last line)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment