@@ -84,13 +84,46 @@ Describe "Join-Path cmdlet tests" -Tags "CI" {
8484 $result = Join-Path - Path $Path - ChildPath $ChildPath
8585 $result | Should - BeExactly $ExpectedResult
8686 }
87- It " should change extension when -Extension parameter is specified" {
88- $result = Join-Path - Path " folder" - ChildPath " file.txt" - Extension " .log"
89- $result | Should - BeExactly " folder${SepChar} file.log"
90- }
91- It " should add extension to file without extension" {
92- $result = Join-Path - Path " folder" - ChildPath " file" - Extension " .txt"
93- $result | Should - BeExactly " folder${SepChar} file.txt"
87+ It " should handle extension parameter: <TestName>" - TestCases @ (
88+ @ {
89+ TestName = " change extension"
90+ Path = " folder"
91+ ChildPath = " file.txt"
92+ Extension = " .log"
93+ ExpectedResult = " folder${SepChar} file.log"
94+ }
95+ @ {
96+ TestName = " add extension to file without extension"
97+ Path = " folder"
98+ ChildPath = " file"
99+ Extension = " .txt"
100+ ExpectedResult = " folder${SepChar} file.txt"
101+ }
102+ @ {
103+ TestName = " extension without leading dot"
104+ Path = " folder"
105+ ChildPath = " file.txt"
106+ Extension = " log"
107+ ExpectedResult = " folder${SepChar} file.log"
108+ }
109+ @ {
110+ TestName = " double extension with dot"
111+ Path = " folder"
112+ ChildPath = " file.txt"
113+ Extension = " .tar.gz"
114+ ExpectedResult = " folder${SepChar} file.tar.gz"
115+ }
116+ @ {
117+ TestName = " double extension without dot"
118+ Path = " folder"
119+ ChildPath = " file.txt"
120+ Extension = " tar.gz"
121+ ExpectedResult = " folder${SepChar} file.tar.gz"
122+ }
123+ ) {
124+ param ($TestName , $Path , $ChildPath , $Extension , $ExpectedResult )
125+ $result = Join-Path - Path $Path - ChildPath $ChildPath - Extension $Extension
126+ $result | Should - BeExactly $ExpectedResult
94127 }
95128 It " should remove extension when empty string is specified" {
96129 $result = Join-Path - Path " folder" - ChildPath " file.txt" - Extension " "
@@ -106,12 +139,6 @@ Describe "Join-Path cmdlet tests" -Tags "CI" {
106139 $result [0 ] | Should - BeExactly " folder1${SepChar} file.log"
107140 $result [1 ] | Should - BeExactly " folder2${SepChar} file.log"
108141 }
109- It " should handle extension with or without leading dot" {
110- $result1 = Join-Path - Path " folder" - ChildPath " file.txt" - Extension " .log"
111- $result2 = Join-Path - Path " folder" - ChildPath " file.txt" - Extension " log"
112- $result1 | Should - BeExactly " folder${SepChar} file.log"
113- $result2 | Should - BeExactly " folder${SepChar} file.log"
114- }
115142 It " should replace only the last extension for files with multiple dots" {
116143 $result = Join-Path - Path " folder" - ChildPath " file.backup.txt" - Extension " .log"
117144 $result | Should - BeExactly " folder${SepChar} file.backup.log"
0 commit comments