Example #1
0
func TestString(t *testing.T) {
	p := op.NewParser("", 0)
	a := p.String("-a")
	assertEqual(t, *a, "", "String did not default to empty string")
	b := p.String("-b", op.Const("foo"))
	assertEqual(t, *b, "", "String with Const did not default to empty string")
	args, err := p.ParseArgs([]string{"-a", "blah", "-b"})
	checkArgs(t, args, err)
	assertEqual(t, *a, "blah", "String did not get passed argument")
	assertEqual(t, *b, "foo", "String did not get Const value")
}
Example #2
0
func TestInt(t *testing.T) {
	p := op.NewParser("", 0)
	a := p.Int("-a")
	assertEqual(t, *a, 0, "Int did not default to 0")
	b := p.Int("-b", op.Count)
	assertEqual(t, *b, 0, "Int with Count did not default to 0")
	c := p.Int("-c", op.Const(10))
	assertEqual(t, *c, 0, "Int with Const did not default to 0")
	args, err := p.ParseArgs([]string{"-a", "20", "-bbb", "-c"})
	checkArgs(t, args, err)
	assertEqual(t, *a, 20, "Int did not get passed argument")
	assertEqual(t, *b, 3, "Int did not count correctly")
	assertEqual(t, *c, 10, "Int did not get Const value")
}