@ -21,17 +21,17 @@ import (
"testing"
)
// Test Browser Flag.String()
func TestBrowser FlagString ( t * testing . T ) {
var bf Browser Flag
// Test Bool Flag.String()
func TestBool FlagString ( t * testing . T ) {
var bf Bool Flag
testCases := [ ] struct {
flag Browser Flag
flag Bool Flag
expectedResult string
} {
{ bf , "off" } ,
{ Browser Flag ( true ) , "on" } ,
{ Browser Flag ( false ) , "off" } ,
{ Bool Flag ( true ) , "on" } ,
{ Bool Flag ( false ) , "off" } ,
}
for _ , testCase := range testCases {
@ -42,17 +42,17 @@ func TestBrowserFlagString(t *testing.T) {
}
}
// Test Browser Flag.MarshalJSON()
func TestBrowser FlagMarshalJSON ( t * testing . T ) {
var bf Browser Flag
// Test Bool Flag.MarshalJSON()
func TestBool FlagMarshalJSON ( t * testing . T ) {
var bf Bool Flag
testCases := [ ] struct {
flag Browser Flag
flag Bool Flag
expectedResult string
} {
{ bf , ` "off" ` } ,
{ Browser Flag ( true ) , ` "on" ` } ,
{ Browser Flag ( false ) , ` "off" ` } ,
{ Bool Flag ( true ) , ` "on" ` } ,
{ Bool Flag ( false ) , ` "off" ` } ,
}
for _ , testCase := range testCases {
@ -63,27 +63,27 @@ func TestBrowserFlagMarshalJSON(t *testing.T) {
}
}
// Test Browser Flag.UnmarshalJSON()
func TestBrowser FlagUnmarshalJSON ( t * testing . T ) {
// Test Bool Flag.UnmarshalJSON()
func TestBool FlagUnmarshalJSON ( t * testing . T ) {
testCases := [ ] struct {
data [ ] byte
expectedResult Browser Flag
expectedResult Bool Flag
expectedErr error
} {
{ [ ] byte ( ` { } ` ) , Browser Flag ( false ) , errors . New ( "json: cannot unmarshal object into Go value of type string" ) } ,
{ [ ] byte ( ` ["on"] ` ) , Browser Flag ( false ) , errors . New ( "json: cannot unmarshal array into Go value of type string" ) } ,
{ [ ] byte ( ` "junk" ` ) , Browser Flag ( false ) , errors . New ( "invalid value ‘junk’ for Browser Flag" ) } ,
{ [ ] byte ( ` "true" ` ) , Browser Flag ( false ) , errors . New ( "invalid value ‘true’ for Browser Flag" ) } ,
{ [ ] byte ( ` "false" ` ) , Browser Flag ( false ) , errors . New ( "invalid value ‘false’ for Browser Flag" ) } ,
{ [ ] byte ( ` "ON" ` ) , Browser Flag ( false ) , errors . New ( "invalid value ‘ON’ for Browser Flag" ) } ,
{ [ ] byte ( ` "OFF" ` ) , Browser Flag ( false ) , errors . New ( "invalid value ‘OFF’ for Browser Flag" ) } ,
{ [ ] byte ( ` "" ` ) , Browser Flag ( true ) , nil } ,
{ [ ] byte ( ` "on" ` ) , Browser Flag ( true ) , nil } ,
{ [ ] byte ( ` "off" ` ) , Browser Flag ( false ) , nil } ,
{ [ ] byte ( ` { } ` ) , Bool Flag ( false ) , errors . New ( "json: cannot unmarshal object into Go value of type string" ) } ,
{ [ ] byte ( ` ["on"] ` ) , Bool Flag ( false ) , errors . New ( "json: cannot unmarshal array into Go value of type string" ) } ,
{ [ ] byte ( ` "junk" ` ) , Bool Flag ( false ) , errors . New ( "invalid value ‘junk’ for Bool Flag" ) } ,
{ [ ] byte ( ` "true" ` ) , Bool Flag ( false ) , errors . New ( "invalid value ‘true’ for Bool Flag" ) } ,
{ [ ] byte ( ` "false" ` ) , Bool Flag ( false ) , errors . New ( "invalid value ‘false’ for Bool Flag" ) } ,
{ [ ] byte ( ` "ON" ` ) , Bool Flag ( false ) , errors . New ( "invalid value ‘ON’ for Bool Flag" ) } ,
{ [ ] byte ( ` "OFF" ` ) , Bool Flag ( false ) , errors . New ( "invalid value ‘OFF’ for Bool Flag" ) } ,
{ [ ] byte ( ` "" ` ) , Bool Flag ( true ) , nil } ,
{ [ ] byte ( ` "on" ` ) , Bool Flag ( true ) , nil } ,
{ [ ] byte ( ` "off" ` ) , Bool Flag ( false ) , nil } ,
}
for _ , testCase := range testCases {
var flag Browser Flag
var flag Bool Flag
err := ( & flag ) . UnmarshalJSON ( testCase . data )
if testCase . expectedErr == nil {
if err != nil {
@ -101,25 +101,25 @@ func TestBrowserFlagUnmarshalJSON(t *testing.T) {
}
}
// Test ParseBrowser Flag()
func TestParseBrowser Flag ( t * testing . T ) {
// Test ParseBool Flag()
func TestParseBool Flag ( t * testing . T ) {
testCases := [ ] struct {
flagStr string
expectedResult Browser Flag
expectedResult Bool Flag
expectedErr error
} {
{ "" , Browser Flag ( false ) , errors . New ( "invalid value ‘’ for Browser Flag" ) } ,
{ "junk" , Browser Flag ( false ) , errors . New ( "invalid value ‘junk’ for Browser Flag" ) } ,
{ "true" , Browser Flag ( false ) , errors . New ( "invalid value ‘true’ for Browser Flag" ) } ,
{ "false" , Browser Flag ( false ) , errors . New ( "invalid value ‘false’ for Browser Flag" ) } ,
{ "ON" , Browser Flag ( false ) , errors . New ( "invalid value ‘ON’ for Browser Flag" ) } ,
{ "OFF" , Browser Flag ( false ) , errors . New ( "invalid value ‘OFF’ for Browser Flag" ) } ,
{ "on" , Browser Flag ( true ) , nil } ,
{ "off" , Browser Flag ( false ) , nil } ,
{ "" , Bool Flag ( false ) , errors . New ( "invalid value ‘’ for Bool Flag" ) } ,
{ "junk" , Bool Flag ( false ) , errors . New ( "invalid value ‘junk’ for Bool Flag" ) } ,
{ "true" , Bool Flag ( false ) , errors . New ( "invalid value ‘true’ for Bool Flag" ) } ,
{ "false" , Bool Flag ( false ) , errors . New ( "invalid value ‘false’ for Bool Flag" ) } ,
{ "ON" , Bool Flag ( false ) , errors . New ( "invalid value ‘ON’ for Bool Flag" ) } ,
{ "OFF" , Bool Flag ( false ) , errors . New ( "invalid value ‘OFF’ for Bool Flag" ) } ,
{ "on" , Bool Flag ( true ) , nil } ,
{ "off" , Bool Flag ( false ) , nil } ,
}
for _ , testCase := range testCases {
bf , err := ParseBrowser Flag ( testCase . flagStr )
bf , err := ParseBool Flag ( testCase . flagStr )
if testCase . expectedErr == nil {
if err != nil {
t . Fatalf ( "error: expected = <nil>, got = %v" , err )