Add more test cases
This commit is contained in:
		
							parent
							
								
									a06e83f96a
								
							
						
					
					
						commit
						9456b4097b
					
				|  | @ -265,3 +265,49 @@ func TestParseSingleDashValue(t *testing.T) { | ||||||
| 		t.Errorf("Expected fruit to be '-', got: %s", opt.Value()) | 		t.Errorf("Expected fruit to be '-', got: %s", opt.Value()) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func TestParseLongOptionBadValue(t *testing.T) { | ||||||
|  | 	opt := opts.Int("fruit", "f", 0, "") | ||||||
|  | 	set := opts.Set{opt} | ||||||
|  | 	args := []string{"--fruit=five"} | ||||||
|  | 	parser := opts.NewParser(args, set, false) | ||||||
|  | 	_, err := parser.Parse() | ||||||
|  | 	if err == nil { | ||||||
|  | 		t.Error("Expected error") | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestParseShortOptionWithSpaceBadValue(t *testing.T) { | ||||||
|  | 	opt := opts.Int("fruit", "f", 0, "") | ||||||
|  | 	set := opts.Set{opt} | ||||||
|  | 	args := []string{"-f", "five"} | ||||||
|  | 	parser := opts.NewParser(args, set, false) | ||||||
|  | 	_, err := parser.Parse() | ||||||
|  | 	if err == nil { | ||||||
|  | 		t.Error("Expected error") | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestParseShortOptionWithoutEqualBadValue(t *testing.T) { | ||||||
|  | 	optG := opts.Bool("green", "g", false, "") | ||||||
|  | 	optF := opts.Int("fruit", "f", 0, "") | ||||||
|  | 	set := opts.Set{optG, optF} | ||||||
|  | 	args := []string{"-ffive"} | ||||||
|  | 	parser := opts.NewParser(args, set, false) | ||||||
|  | 	_, err := parser.Parse() | ||||||
|  | 	if err == nil { | ||||||
|  | 		t.Error("Expected error") | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestParseShortOptionWithEqualBadValue(t *testing.T) { | ||||||
|  | 	optG := opts.Bool("green", "g", false, "") | ||||||
|  | 	optF := opts.Int("fruit", "f", 0, "") | ||||||
|  | 	set := opts.Set{optG, optF} | ||||||
|  | 	args := []string{"-f=five"} | ||||||
|  | 	parser := opts.NewParser(args, set, false) | ||||||
|  | 	_, err := parser.Parse() | ||||||
|  | 	if err == nil { | ||||||
|  | 		t.Error("Expected error") | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue