Repository: gavv/httpexpect (go)

Issue:
Improve test coverage of Number and String
See coverage reports here:

* https://coveralls.io/builds/54781134/source?filename=number.go
* https://coveralls.io/builds/54781134/source?filename=string.go

There are uncovered branches in Number.NotInRange and String.AsNumber. We should cover them in unit tests.

Pull request description:
185 fix err handle and add unit test of string and number
fix #185

Patch:
diff --git a/string.go b/string.go
index fccda44..e2b3da6 100644
--- a/string.go
+++ b/string.go
@@ -563,7 +563,7 @@ func (s *String) AsNumber(base ...int) *Number {
 		inum, err = strconv.ParseInt(s.value, base[0], 64)
 		num = float64(inum)
 
-		if err == strconv.ErrRange {
+		if errors.Is(err, strconv.ErrRange) {
 			var unum uint64
 
 			unum, err = strconv.ParseUint(s.value, base[0], 64)


Test patch:
diff --git a/number_test.go b/number_test.go
index ce33b5e..e4ce0be 100644
--- a/number_test.go
+++ b/number_test.go
@@ -252,6 +252,14 @@ func TestNumberInRange(t *testing.T) {
 	value.NotInRange(1234+1, 1234-1)
 	value.chain.assertOK(t)
 	value.chain.reset()
+
+	value.NotInRange(1234+1, "1234+2")
+	value.chain.assertFailed(t)
+	value.chain.reset()
+
+	value.NotInRange("1234+1", 1234+2)
+	value.chain.assertFailed(t)
+	value.chain.reset()
 }
 
 func TestNumberConvertEqual(t *testing.T) {
diff --git a/string_test.go b/string_test.go
index 8aba3cd..3776570 100644
--- a/string_test.go
+++ b/string_test.go
@@ -341,6 +341,20 @@ func TestStringAsNumber(t *testing.T) {
 		value2.chain.assertFailed(t)
 		num2.chain.assertFailed(t)
 		assert.Equal(t, float64(0), num2.Raw())
+
+		value3 := NewString(reporter, "8000000000000000")
+		num3 := value3.AsNumber(16)
+		value3.chain.assertOK(t)
+		num3.chain.assertOK(t)
+		assert.Equal(t, float64(9223372036854775808), num3.Raw())
+	})
+
+	t.Run("multiple_base", func(t *testing.T) {
+		value1 := NewString(reporter, "100")
+		num1 := value1.AsNumber(10, 16)
+		value1.chain.assertFailed(t)
+		num1.chain.assertFailed(t)
+		assert.Equal(t, float64(0), num1.Raw())
 	})
 }