@@ -59,15 +59,67 @@ func TestCommandParsing(t *testing.T) {
5959		cmd , args  :=  c .matchCommand (test .line )
6060		if  test .cmd  !=  ""  {
6161			if  assert .NotNil (t , cmd , "No command found for `%s`" , test .line ) {
62- 				assert .Equal (t , test .cmd , cmd .name , "Incorrect command for `%s`" , test .line )
63- 				assert .Equal (t , test .args , args , "Incorrect arguments for `%s`" , test .line )
62+ 				assert .Equalf (t , test .cmd , cmd .name , "Incorrect command for `%s`" , test .line )
63+ 				assert .Equalf (t , test .args , args , "Incorrect arguments for `%s`" , test .line )
64+ 				line  :=  test .line  +  " -- comment" 
65+ 				cmd , args  =  c .matchCommand (line )
66+ 				if  assert .NotNil (t , cmd , "No command found for `%s`" , line ) {
67+ 					assert .Equalf (t , test .cmd , cmd .name , "Incorrect command for `%s`" , line )
68+ 					assert .Equalf (t , len (test .args ), len (args ), "Incorrect argument count for `%s`." , line )
69+ 					for  _ , a  :=  range  args  {
70+ 						assert .NotContains (t , a , "--" , "comment marker should be omitted" )
71+ 						assert .NotContains (t , a , "comment" , "comment should e omitted" )
72+ 					}
73+ 				}
6474			}
6575		} else  {
6676			assert .Nil (t , cmd , "Unexpected match for %s" , test .line )
6777		}
6878	}
6979}
7080
81+ func  TestRemoveComments (t  * testing.T ) {
82+ 	type  testData  struct  {
83+ 		args    []string 
84+ 		result  []string 
85+ 	}
86+ 	tests  :=  []testData {
87+ 		{[]string {"-- comment" }, []string {"" }},
88+ 		{[]string {"filename -- comment" }, []string {"filename " }},
89+ 		{[]string {`"file""name"` , `-- comment` }, []string {`"file""name"` , "" }},
90+ 		{[]string {`"file""name"--comment` }, []string {`"file""name"--comment` }},
91+ 	}
92+ 	for  _ , test  :=  range  tests  {
93+ 		actual  :=  removeComments (test .args )
94+ 		assert .Equal (t , test .result , actual , "Comments not removed properly" )
95+ 	}
96+ }
97+ 
98+ func  TestCommentStart (t  * testing.T ) {
99+ 	type  testData  struct  {
100+ 		arg       string 
101+ 		quoteIn   bool 
102+ 		quoteOut  bool 
103+ 		pos       int 
104+ 	}
105+ 	tests  :=  []testData {
106+ 		{"nospace-- comment" , false , false , - 1 },
107+ 		{"-- comment" , false , false , 0 },
108+ 		{"-- comment" , true , true , - 1 },
109+ 		{`" ""quoted""` , false , true , - 1 },
110+ 		{`"-- ""quoted""` , false , true , - 1 },
111+ 		{`"-- ""quoted"" " -- comment` , false , false , 17 },
112+ 		{`"-- ""quoted"" " -- comment` , true , false , 1 },
113+ 	}
114+ 	for  _ , test  :=  range  tests  {
115+ 		t .Run (test .arg , func (t  * testing.T ) {
116+ 			i , q  :=  commentStart ([]rune (test .arg ), test .quoteIn )
117+ 			assert .Equal (t , test .quoteOut , q , "Wrong quote" )
118+ 			assert .Equal (t , test .pos , i , "Wrong position" )
119+ 		})
120+ 	}
121+ }
122+ 
71123func  TestCustomBatchSeparator (t  * testing.T ) {
72124	c  :=  newCommands ()
73125	err  :=  c .SetBatchTerminator ("me!" )
0 commit comments