MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe 'Clipboard cmdlet tests' -Tag CI {5 BeforeAll {6 $xclip = Get-Command xclip -CommandType Application -ErrorAction Ignore7 }8 9 Context 'Text' {10 BeforeAll {11 $defaultParamValues = $PSDefaultParameterValues.Clone()12 $PSDefaultParameterValues["it:skip"] = ($IsWindows -and $env:PROCESSOR_ARCHITECTURE.Contains("arm")) -or ($IsLinux -and $xclip -eq $null)13 }14 15 AfterAll {16 $global:PSDefaultParameterValues = $defaultParamValues17 }18 19 It 'Get-Clipboard returns what is in Set-Clipboard' {20 $guid = New-Guid21 Set-Clipboard -Value $guid22 Get-Clipboard | Should -BeExactly $guid23 }24 25 It 'Get-Clipboard returns an array' {26 1,2 | Set-Clipboard27 $out = Get-Clipboard28 $out.Count | Should -Be 229 $out[0] | Should -Be 130 $out[1] | Should -Be 231 }32 33 It 'Get-Clipboard -Raw returns one item' {34 1,2 | Set-Clipboard35 (Get-Clipboard -Raw).Count | Should -Be 136 Get-Clipboard -Raw | Should -BeExactly "1$([Environment]::NewLine)2"37 }38 39 It 'Get-Clipboard -Delimiter should return items based on the delimiter' {40 Set-Clipboard -Value "Line1`r`nLine2`nLine3"41 $result = Get-Clipboard -Delimiter "`r`n", "`n"42 $result.Count | Should -Be 343 $result | ForEach-Object -Process {$_.Length | Should -Be "LineX".Length}44 }45 46 It 'Set-Clipboard -Append will add text' {47 'hello' | Set-Clipboard48 'world' | Set-Clipboard -Append49 Get-Clipboard -Raw | Should -BeExactly "hello$([Environment]::NewLine)world"50 }51 52 It 'Set-Clipboard accepts <value> string' -TestCases @(53 @{ value = 'empty'; text = "" }54 @{ value = 'null' ; text = $null }55 ){56 param ($text)57 58 $text | Set-Clipboard59 Get-Clipboard -Raw | Should -BeNullOrEmpty60 }61 62 It 'Set-Clipboard should not return object' {63 $result = 'hello' | Set-Clipboard64 $result | Should -BeNullOrEmpty65 }66 67 It 'Set-Clipboard -PassThru returns single object with -Append = <Append>' -TestCases @(68 @{ Append = $false }69 @{ Append = $true }70 ){71 param ($append)72 73 $params = @{ PassThru = $true; Append = $append }74 75 Set-Clipboard -Value 'world'76 $result = 'hello' | Set-Clipboard @params77 $result | Should -BeExactly 'hello'78 }79 80 It 'Set-Clipboard -PassThru returns multiple objects with -Append = <Append>' -TestCases @(81 @{ Append = $false }82 @{ Append = $true }83 ){84 param ($append)85 86 $params = @{ PassThru = $true; Append = $append }87 88 Set-Clipboard -Value 'world'89 $result = 'hello', 'world' | Set-Clipboard @params90 $result | Should -BeExactly @('hello', 'world')91 }92 }93}94 