11package figtree
22
33import (
4+ "os"
45 "testing"
56
67 "github.com/stretchr/testify/assert"
@@ -11,26 +12,30 @@ func TestWithAlias(t *testing.T) {
1112 const cmdShort , cmdAliasShort , valueShort = "short" , "s" , "default"
1213
1314 t .Run ("basic_usage" , func (t * testing.T ) {
15+ os .Args = []string {os .Args [0 ], "-l" , t .Name ()}
1416 figs := With (Options {Germinate : true , Tracking : false })
15- figs .NewString (cmdLong , valueLong , usage )
16- figs .WithAlias (cmdLong , cmdAliasLong )
17+ figs = figs .NewString (cmdLong , valueLong , usage )
18+ figs = figs .WithAlias (cmdLong , cmdAliasLong )
1719 assert .NoError (t , figs .Parse ())
1820
19- assert .Equal (t , valueLong , * figs .String (cmdLong ))
20- assert .Equal (t , valueLong , * figs .String (cmdAliasLong ))
21+ assert .NotEqual (t , valueLong , * figs .String (cmdLong ))
22+ assert .Equal (t , t .Name (), * figs .String (cmdLong ))
23+ assert .NotEqual (t , valueLong , * figs .String (cmdAliasLong ))
24+ assert .Equal (t , t .Name (), * figs .String (cmdAliasLong ))
2125 figs = nil
2226 })
2327
2428 t .Run ("multiple_aliases" , func (t * testing.T ) {
29+ os .Args = []string {os .Args [0 ]}
2530 const k , v , u = "name" , "yeshua" , "the real name of god"
2631 ka1 := "father"
2732 ka2 := "son"
2833 ka3 := "rauch-hokadesch"
2934 figs := With (Options {Germinate : true , Tracking : false })
30- figs .NewString (k , v , u )
31- figs .WithAlias (k , ka1 )
32- figs .WithAlias (k , ka2 )
33- figs .WithAlias (k , ka3 )
35+ figs = figs .NewString (k , v , u )
36+ figs = figs .WithAlias (k , ka1 )
37+ figs = figs .WithAlias (k , ka2 )
38+ figs = figs .WithAlias (k , ka3 )
3439 assert .NoError (t , figs .Parse ())
3540
3641 assert .Equal (t , v , * figs .String (k ))
@@ -41,17 +46,17 @@ func TestWithAlias(t *testing.T) {
4146 })
4247
4348 t .Run ("complex_usage" , func (t * testing.T ) {
44-
49+ os . Args = [] string { os . Args [ 0 ]}
4550 figs := With (Options {Germinate : true , Tracking : false })
4651 // long
47- figs .NewString (cmdLong , valueLong , usage )
48- figs .WithAlias (cmdLong , cmdAliasLong )
49- figs .WithValidator (cmdLong , AssureStringNotEmpty )
52+ figs = figs .NewString (cmdLong , valueLong , usage )
53+ figs = figs .WithAlias (cmdLong , cmdAliasLong )
54+ figs = figs .WithValidator (cmdLong , AssureStringNotEmpty )
5055
5156 // short
52- figs .NewString (cmdShort , valueShort , usage )
53- figs .WithAlias (cmdShort , cmdAliasShort )
54- figs .WithValidator (cmdShort , AssureStringNotEmpty )
57+ figs = figs .NewString (cmdShort , valueShort , usage )
58+ figs = figs .WithAlias (cmdShort , cmdAliasShort )
59+ figs = figs .WithValidator (cmdShort , AssureStringNotEmpty )
5560
5661 assert .NoError (t , figs .Parse ())
5762
@@ -63,24 +68,25 @@ func TestWithAlias(t *testing.T) {
6368 assert .Equal (t , valueShort , * figs .String (cmdAliasShort ))
6469
6570 figs = nil
66-
6771 })
6872
6973 t .Run ("alias_with_int" , func (t * testing.T ) {
74+ os .Args = []string {os .Args [0 ]}
7075 figs := With (Options {Germinate : true })
71- figs .NewInt ("count" , 42 , "usage" )
72- figs .WithAlias ("count" , "c" )
76+ figs = figs .NewInt ("count" , 42 , "usage" )
77+ figs = figs .WithAlias ("count" , "c" )
7378 assert .NoError (t , figs .Parse ())
7479 assert .Equal (t , 42 , * figs .Int ("count" ))
7580 assert .Equal (t , 42 , * figs .Int ("c" ))
7681 })
7782
7883 t .Run ("alias_conflict" , func (t * testing.T ) {
84+ os .Args = []string {os .Args [0 ]}
7985 figs := With (Options {Germinate : true })
80- figs .NewString ("one" , "value1" , "usage" )
81- figs .NewString ("two" , "value2" , "usage" )
82- figs .WithAlias ("one" , "x" )
83- figs .WithAlias ("two" , "x" ) // Should this overwrite or be ignored?
86+ figs = figs .NewString ("one" , "value1" , "usage" )
87+ figs = figs .NewString ("two" , "value2" , "usage" )
88+ figs = figs .WithAlias ("one" , "x" )
89+ figs = figs .WithAlias ("two" , "x" ) // Should this overwrite or be ignored?
8490 assert .NoError (t , figs .Parse ())
8591 assert .Equal (t , "value1" , * figs .String ("x" )) // Clarify expected behavior
8692 })
0 commit comments