New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds a new Ask to questioner for bools with a default value. Also adds tests. #6449
Adds a new Ask to questioner for bools with a default value. Also adds tests. #6449
Conversation
gov2/demotools/question.go
Outdated
func (questioner Questioner) AskBoolWithDefault(question string, expected string, defaultValue string) bool { | ||
answer := questioner.Ask(question) | ||
return strings.ToLower(answer) == expected || strings.ToLower(expected) == strings.ToLower(defaultValue) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works fine, but I almost would prefer defaultResponse bool
instead of defaultValue
and then
return strings.ToLower(answer) == expected || defaultResponse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made me realize I was missing some test coverage for when the default response is affirmative but the provided response by the user is negative. I'll rewrite and then take a look at using a bool instead of a string.
fb1289e
to
4729243
Compare
func TestQuestioner_AskBoolWithDefault_yY_Blank(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "y", "Y", "", true) | ||
} | ||
|
||
func TestQuestioner_AskBoolWithDefault_yN_Blank(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "y", "N", "", false) | ||
} | ||
func TestQuestioner_AskBoolWithDefault_nY_Blank(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "n", "Y", "", false) | ||
} | ||
func TestQuestioner_AskBoolWithDefault_nN_Blank(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "n", "N", "", true) | ||
} | ||
|
||
func TestQuestioner_AskBoolWithDefault_yY_y(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "y", "Y", "y", true) | ||
} | ||
func TestQuestioner_AskBoolWithDefault_yN_y(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "y", "N", "y", true) | ||
} | ||
func TestQuestioner_AskBoolWithDefault_nY_y(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "n", "Y", "y", false) | ||
} | ||
func TestQuestioner_AskBoolWithDefault_nN_y(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "n", "N", "y", false) | ||
} | ||
|
||
func TestQuestioner_AskBoolWithDefault_yY_n(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "y", "Y", "n", false) | ||
} | ||
func TestQuestioner_AskBoolWithDefault_yN_n(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "y", "N", "n", false) | ||
} | ||
func TestQuestioner_AskBoolWithDefault_nY_n(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "n", "Y", "n", true) | ||
} | ||
func TestQuestioner_AskBoolWithDefault_nN_n(t *testing.T) { | ||
AskBoolWithDefault_ByArguments(t, "n", "N", "n", true) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a lot of these are redundant, because y or n doesn't matter, it's more like a or b, and aA or bB are equivalent, so your set of cases should be:
aA""
aB""
aAa
aAb
aBa
aBb
It might not be fewer lines, but I might have made a struct and then a list of objects, like:
type testArgs struct {
expected string
defaultVal string
entry string
result bool
}
tests := []testArgs{
{"a", "A", "", true},
... etc ...
}
No description provided.