-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b1b07a
commit 0f154b6
Showing
2 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package toolbox3d | ||
|
||
import ( | ||
"flag" | ||
"testing" | ||
) | ||
|
||
type TestAddFlagsSubObj struct { | ||
} | ||
|
||
type TestAddFlagsObj struct { | ||
IntField int | ||
OtherIntField int `default:"123"` | ||
FloatField float64 `default:"3.14"` | ||
} | ||
|
||
func TestAddFlags(t *testing.T) { | ||
var obj TestAddFlagsObj | ||
fs := flag.NewFlagSet("foo", flag.PanicOnError) | ||
AddFlags(&obj, fs) | ||
fs.Parse([]string{}) | ||
if obj.OtherIntField != 123 { | ||
t.Errorf("incorrect OtherIntField: %v", obj.OtherIntField) | ||
} | ||
if obj.IntField != 0 { | ||
t.Errorf("incorrect IntField: %v", obj.IntField) | ||
} | ||
if obj.FloatField != 3.14 { | ||
t.Errorf("incorrect FloatField: %v", obj.FloatField) | ||
} | ||
|
||
var obj1 TestAddFlagsObj | ||
fs = flag.NewFlagSet("foo", flag.PanicOnError) | ||
AddFlags(&obj1, fs) | ||
fs.Parse([]string{"-int-field", "4", "-other-int-field", "5", "-float-field", "3.14"}) | ||
if obj1.OtherIntField != 5 { | ||
t.Errorf("incorrect OtherIntField: %v", obj.OtherIntField) | ||
} | ||
if obj1.IntField != 4 { | ||
t.Errorf("incorrect IntField: %v", obj.IntField) | ||
} | ||
if obj1.FloatField != 3.14 { | ||
t.Errorf("incorrect FloatField: %v", obj.FloatField) | ||
} | ||
} |