<commit_before>
$currentTest = $null

Add-Type @"
namespace Pest
{
    public sealed class AssertionException : System.Exception
    {
        private string[] _psStackTrace;
        
        public AssertionException(string message, string[] psStackTrace) : base(message)
        {
            _psStackTrace = psStackTrace;
        }

        public string[] PSStackTrace 
        { 
            get { return _psStackTrace; }
        }  
    }
}
"@

function Set-CurrentTest($currentTest)
{
    $SCRIPT:currentTest = $currentTest
}

function Assert-Contains($haystack, $needle, $message)
{
    if( $haystack -notcontains $needle )
    {
        Fail "Unable to find '$needle': $message"
    }
}

function Assert-ContainsLike($haystack, $needle, $message)
{
    foreach( $line in $haystack )
    {
        if( $line -like "*$needle*" )
        {
            return
        }
    }
    Fail "Unable to find '$needle': $message" 
}

function Assert-ContainsNotLike($haystack, $needle, [Parameter(Mandatory=$true)]$message)
{
    foreach( $line in $haystack )
    {
        if( $line -like "*$needle*" )
        {
            Fail "Found '$needle': $message"
        }
    }
}


function Assert-DirectoryDoesNotExist($directory, $message)
{
    if( Test-Path $directory -PathType Container )
    {
        Fail "Directory '$directory' exists: $message"
    }
}

function Assert-DirectoryExists($directory, $message)
{
    if( -not (Test-Path $directory -PathType Container) )
    {
        Fail "Directory $directory does not exist: $message"
    }
}

function Assert-DoesNotContain($Haystack, $Needle, $Message)
{
    if( $Haystack -contains $Needle )
    {
        Fail "Found '$Needle': $Message"
    }
}

function Assert-Empty($item, $message)
{
    if( $item -and ($item.Length -gt 0 -or $item.Count -gt 0) )
    {
        Fail "Expected '$item' to be empty: $message"
    }
}

function Assert-Equal($expected, $actual, $message)
{
    Write-TestVerbose "Is '$expected' -eq '$actual'?"
    if( -not ($expected -eq $actual) )
    {
        if( $expected -is [string] -and $actual -is [string] -and ($expected.Contains("`n") -or $actual.Contains("`n")))
        {
            for( $idx = 0; $idx -lt $expected.Length; ++$idx )
            {
                if( $idx -gt $actual.Length )
                {
                    Fail "Strings different, beginning at index $idx:`n$($expected.Substring(0,$idx))`n($actual)`n$message"
                }
                
                if( $expected[$idx] -ne $actual[$idx] )
                {
                    Fail "Strings different beginning at index $idx: $idx`n$($expected.Substring(0,$idx))`n$($actual.Substring(0,$idx))`n$message"
                }
            }
            
        }
        Fail "Expected '$expected', but was '$actual': $message"
    }
}

function Assert-CEqual
{
    param(
        [Parameter(Mandatory=$true)]
        [string]
        $Expected,
        [Parameter(Mandatory=$true)]
        [string]
        $Actual,
        [Parameter(Mandatory=$true)]
        [string]
        $Message
    )
    if( $Expected -cne $Actual )
    {
        for( $idx = 0; $idx -lt $expected.Length; ++$idx )
        {
            if( $idx -gt $actual.Length )
            {
                Fail "Strings different, beginning at index $idx:`n$($expected.Substring(0,$idx))`n($actual)`n$message"
            }
            
            if( $expected[$idx] -cne $actual[$idx] )
            {
                $actualSnippet = if( ($idx + 1) -gt $actual.Length ) { $Actual } else { $Actual.Substring(0, $idx) }
                Fail "Strings different beginning at index $idx: $idx`n$($expected.Substring(0,$idx + 1))`n$actualSnippet`n$message"
            }
        }

        Fail "Expected '$Expected', but was '$Actual': $Message"
    }<commit_msg>Updating to work with PowerShell v3.0.<commit_after>
$currentTest = $null

Add-Type @"
namespace Pest
{
    public sealed class AssertionException : System.Exception
    {
        private string[] _psStackTrace;
        
        public AssertionException(string message, string[] psStackTrace) : base(message)
        {
            _psStackTrace = psStackTrace;
        }

        public string[] PSStackTrace 
        { 
            get { return _psStackTrace; }
        }  
    }
}
"@

function Set-CurrentTest($currentTest)
{
    $SCRIPT:currentTest = $currentTest
}

function Assert-Contains($haystack, $needle, $message)
{
    if( $haystack -notcontains $needle )
    {
        Fail "Unable to find '$needle': $message"
    }
}

function Assert-ContainsLike($haystack, $needle, $message)
{
    foreach( $line in $haystack )
    {
        if( $line -like "*$needle*" )
        {
            return
        }
    }
    Fail "Unable to find '$needle': $message" 
}

function Assert-ContainsNotLike($haystack, $needle, [Parameter(Mandatory=$true)]$message)
{
    foreach( $line in $haystack )
    {
        if( $line -like "*$needle*" )
        {
            Fail "Found '$needle': $message"
        }
    }
}


function Assert-DirectoryDoesNotExist($directory, $message)
{
    if( Test-Path $directory -PathType Container )
    {
        Fail "Directory '$directory' exists: $message"
    }
}

function Assert-DirectoryExists($directory, $message)
{
    if( -not (Test-Path $directory -PathType Container) )
    {
        Fail "Directory $directory does not exist: $message"
    }
}

function Assert-DoesNotContain($Haystack, $Needle, $Message)
{
    if( $Haystack -contains $Needle )
    {
        Fail "Found '$Needle': $Message"
    }
}

function Assert-Empty($item, $message)
{
    if( $item -and ($item.Length -gt 0 -or $item.Count -gt 0) )
    {
        Fail "Expected '$item' to be empty: $message"
    }
}

function Assert-Equal($expected, $actual, $message)
{
    Write-TestVerbose "Is '$expected' -eq '$actual'?"
    if( -not ($expected -eq $actual) )
    {
        if( $expected -is [string] -and $actual -is [string] -and ($expected.Contains("`n") -or $actual.Contains("`n")))
        {
            for( $idx = 0; $idx -lt $expected.Length; ++$idx )
            {
                if( $idx -gt $actual.Length )
                {
                    Fail ("Strings different, beginning at index {0}:`n{1}`n({2})`n{3}" -f $idx,$expected.Substring(0,$idx),$actual,$message)
                }
                
                if( $expected[$idx] -ne $actual[$idx] )
                {
                    Fail ("Strings different beginning at index {0}: {0}`n{1}`n{2}`n{3}" -f $idx,$expected.Substring(0,$idx),$actual.Substring(0,$idx),$message)
                }
            }
            
        }
        Fail "Expected '$expected', but was '$actual': $message"
    }
}

function Assert-CEqual
{
    param(
        [Parameter(Mandatory=$true)]
        [string]
        $Expected,
        [Parameter(Mandatory=$true)]
        [string]
        $Actual,
        [Parameter(Mandatory=$true)]
        [string]
        $Message
    )
    if( $Expected -cne $Actual )
    {
        for( $idx = 0; $idx -lt $expected.Length; ++$idx )
        {
            if( $idx -gt $actual.Length )
            {
                Fail ("Strings different, beginning at index {0}:`n{1}`n({2})`n{3}" -f $idx,$expected.Substring(0,$idx),$actual,$message)
            }
            
            if( $expected[$idx] -cne $actual[$idx] )
            {
                $actualSnippet = if( ($idx + 1) -gt $actual.Length ) { $Actual } else { $Actual.Substring(0, $idx) }
                Fail ("Strings different beginning at index {0}: {0}`n{1}`n{2}`n{3}" -f $idx,$expected.Substring(0,$idx + 1),$actualSnippet,$message)
            }
        }

        Fail "Expected '$Expected', but was '$Actual': $Message"
    }
{'fraction_non_alphanumeric': 0.14940290758047767, 'fraction_numerical': 0.005711318795430945, 'mean_word_length': 2.04304897314376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5460531', 'n_tokens_mistral': 2446, 'n_tokens_neox': 2381, 'n_words': 551}