From acdf1c1d44d44186cada413011386ded5a28e6b4 Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Mon, 14 Nov 2016 11:19:35 -0800 Subject: [PATCH] Fix LengthInBufferCells test for downlevel When running on systems that do not support a virtual terminal, the tests was incorrectly assuming escape sequences were removed. The fix is to expect different results depending on whether or not the host supports virtual terminal mode. --- test/powershell/Host/ConsoleHost.Tests.ps1 | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index 3a3b3cfb77..1ab7fed1da 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -330,17 +330,31 @@ foo } } } +} +Describe "Console host api tests" -Tag CI { Context "String escape sequences" { - It "Should properly calculate buffer cell width" { - $esc = [char]0x1b - $host.UI.RawUI.LengthInBufferCells("abc") | Should Be 3 - $host.UI.RawUI.LengthInBufferCells("$esc[31mabc") | Should Be 3 - $host.UI.RawUI.LengthInBufferCells("$esc[31mabc$esc[0m") | Should Be 3 + $esc = [char]0x1b + $testCases = + @{InputObject = "abc"; Length = 3; Name = "No escapes"}, + @{InputObject = "${esc} [31mabc"; Length = 9; Name = "Malformed escape - extra space"}, + @{InputObject = "${esc}abc"; Length = 4; Name = "Malformed escape - no csi"}, + @{InputObject = "[31mabc"; Length = 7; Name = "Malformed escape - no escape"} - $host.UI.RawUI.LengthInBufferCells("${esc} [31mabc") | Should Be 9 - $host.UI.RawUI.LengthInBufferCells("${esc}abc") | Should Be 4 - $host.UI.RawUI.LengthInBufferCells("[31mabc") | Should Be 7 + $testCases += if ($host.UI.SupportsVirtualTerminal) + { + @{InputObject = "$esc[31mabc"; Length = 3; Name = "Escape at start"} + @{InputObject = "$esc[31mabc$esc[0m"; Length = 3; Name = "Escape at start and end"} + } + else + { + @{InputObject = "$esc[31mabc"; Length = 8; Name = "Escape at start - no virtual term support"} + @{InputObject = "$esc[31mabc$esc[0m"; Length = 12; Name = "Escape at start and end - no virtual term support"} + } + + It "Should properly calculate buffer cell width of ''" -TestCases $testCases { + param($InputObject, $Length) + $host.UI.RawUI.LengthInBufferCells($InputObject) | Should Be $Length } } }