Tests/Touch/Touch.Count.Tests.ps1

BeforeAll {
    . "$PSScriptRoot\..\Shared\Setup.ps1"
    Initialize-TestEnvironment
}

AfterAll {
    Clear-TestEnvironment
}

Describe 'Touch - Count parameter' {
    BeforeEach {
        $script:testFolder = Join-Path $TestDrive "Touch_Count_$(Get-Random)"
        New-Item -Path $script:testFolder -ItemType Directory -Force | Out-Null
    }

    It 'Creates numbered files with -Count 3' {
        Touch 'log.txt' -Count 3 -Path $script:testFolder
        '(1)log.txt', '(2)log.txt', '(3)log.txt' | ForEach-Object {
            Test-Path (Join-Path $script:testFolder $_) | Should -BeTrue
        }
    }

    It 'Creates single file (no numbering) with -Count 1' {
        Touch 'single.txt' -Count 1 -Path $script:testFolder
        Test-Path (Join-Path $script:testFolder 'single.txt') | Should -BeTrue
        Test-Path (Join-Path $script:testFolder '(1)single.txt') | Should -BeFalse
    }

    It 'Creates single file (no numbering) with -Count 0' {
        Touch 'zero.txt' -Count 0 -Path $script:testFolder
        Test-Path (Join-Path $script:testFolder 'zero.txt') | Should -BeTrue
        Test-Path (Join-Path $script:testFolder '(1)zero.txt') | Should -BeFalse
    }

    It 'Creates numbered copies for each file with -Count and multiple files' {
        Touch -Name 'a.txt', 'b.txt' -Count 2 -Path $script:testFolder
        '(1)a.txt', '(2)a.txt', '(1)b.txt', '(2)b.txt' | ForEach-Object {
            Test-Path (Join-Path $script:testFolder $_) | Should -BeTrue
        }
    }

    It 'Creates numbered files via positional parameters with -Count' {
        Touch 'x.txt' 'y.txt' -Count 2 -Path $script:testFolder
        '(1)x.txt', '(2)x.txt', '(1)y.txt', '(2)y.txt' | ForEach-Object {
            Test-Path (Join-Path $script:testFolder $_) | Should -BeTrue
        }
    }
}