github.com/iDigitalFlame/xmt@v0.5.4/cmd/util_test.go (about) 1 // Copyright (C) 2020 - 2023 iDigitalFlame 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 // 16 17 package cmd 18 19 import "testing" 20 21 func TestSplit(t *testing.T) { 22 v := [...]struct { 23 Cmd string 24 Result []string 25 }{ 26 {"cmd.exe /c", []string{"cmd.exe", "/c"}}, 27 {`notepad.exe "derp"`, []string{"notepad.exe", "derp"}}, 28 {`C:\Windows\system32\calc.exe "open1" "open 2" open 3`, []string{`C:\Windows\system32\calc.exe`, "open1", "open 2", "open", "3"}}, 29 {`test1 /test2 -test3 'test 3' "test 4"`, []string{"test1", "/test2", "-test3", "test3", "test 4"}}, 30 {`test1 /test2 -test3 'test 3' "test 4" "test '5'"`, []string{"test1", "/test2", "-test3", "test3", "test 4", "test '5'"}}, 31 } 32 for i := range v { 33 r := Split(v[i].Cmd) 34 if len(r) != len(v[i].Result) { 35 t.Fatalf(`TestSplit(): Result "%s" does not match expected "%s" for "%s"!`, r, v[i].Result, v[i].Cmd) 36 } 37 } 38 }