MCPcopy Index your code
hub / github.com/gavv/httpexpect / AsBoolean

Method AsBoolean

string.go:1204–1229  ·  view source on GitHub ↗

AsBoolean parses true/false value string and returns a new Boolean instance with result. Accepts string values "true", "True", "false", "False". Example: str := NewString(t, "true") str.AsBoolean().IsTrue()

()

Source from the content-addressed store, hash-verified

1202// str := NewString(t, "true")
1203// str.AsBoolean().IsTrue()
1204func (s *String) AsBoolean() *Boolean {
1205 opChain := s.chain.enter("AsBoolean()")
1206 defer opChain.leave()
1207
1208 if opChain.failed() {
1209 return newBoolean(opChain, false)
1210 }
1211
1212 switch s.value {
1213 case "true", "True":
1214 return newBoolean(opChain, true)
1215
1216 case "false", "False":
1217 return newBoolean(opChain, false)
1218 }
1219
1220 opChain.fail(AssertionFailure{
1221 Type: AssertValid,
1222 Actual: &AssertionValue{s.value},
1223 Errors: []error{
1224 errors.New("expected: string can be parsed to boolean"),
1225 },
1226 })
1227
1228 return newBoolean(opChain, false)
1229}
1230
1231// AsDateTime parses date/time from string and returns a new DateTime instance
1232// with result.

Callers 2

TestString_AsBooleanFunction · 0.95
TestString_FailedChainFunction · 0.80

Calls 5

newBooleanFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 2

TestString_AsBooleanFunction · 0.76
TestString_FailedChainFunction · 0.64