forked from toolshed/abra
		
	
		
			
				
	
	
		
			32 lines
		
	
	
		
			912 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			912 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package app
 | |
| 
 | |
| import (
 | |
| 	"strings"
 | |
| 	"testing"
 | |
| )
 | |
| 
 | |
| func TestParseCmdArgs(t *testing.T) {
 | |
| 	tests := []struct {
 | |
| 		input          []string
 | |
| 		shouldParse    bool
 | |
| 		expectedOutput string
 | |
| 	}{
 | |
| 		// `--` is not parsed when passed in from the command-line e.g. -- foo bar baz
 | |
| 		// so we need to eumlate that as missing when testing if bash args are passed in
 | |
| 		// see https://git.coopcloud.tech/toolshed/organising/issues/336 for more
 | |
| 		{[]string{"foo.com", "app", "test"}, false, ""},
 | |
| 		{[]string{"foo.com", "app", "test", "foo"}, true, "foo "},
 | |
| 		{[]string{"foo.com", "app", "test", "foo", "bar", "baz"}, true, "foo bar baz "},
 | |
| 	}
 | |
| 
 | |
| 	for _, test := range tests {
 | |
| 		ok, parsed := parseCmdArgs(test.input, false)
 | |
| 		if ok != test.shouldParse {
 | |
| 			t.Fatalf("[%s] should not parse", strings.Join(test.input, " "))
 | |
| 		}
 | |
| 		if parsed != test.expectedOutput {
 | |
| 			t.Fatalf("%s does not match %s", parsed, test.expectedOutput)
 | |
| 		}
 | |
| 	}
 | |
| }
 |