1
0
mirror of https://github.com/kataras/iris.git synced 2026-03-04 23:46:06 +00:00

add tests for the new types (int8, int16, int32, uint, uint8, uint16, uint32, uint64)

Former-commit-id: 812b3fdcc47abdeac271473bfdbdd15f0afd0bc0
This commit is contained in:
Gerasimos (Makis) Maropoulos
2018-09-29 04:35:09 +03:00
parent 6d9a35ddba
commit 7568da3283
5 changed files with 176 additions and 10 deletions

View File

@@ -115,8 +115,8 @@ func TestIntEvaluatorRaw(t *testing.T) {
{false, "astring"}, // 0
{false, "astringwith_numb3rS_and_symbol$"}, // 1
{true, "32321"}, // 2
{x64, "9223372036854775807" /*max int64*/}, // 3
{x64, "-9223372036854775808" /*min int64 */}, // 4
{x64, "9223372036854775807" /* max int64 */}, // 3
{x64, "-9223372036854775808" /* min int64 */}, // 4
{false, "-18446744073709553213213213213213121615"}, // 5
{false, "42 18446744073709551615"}, // 6
{false, "--42"}, // 7
@@ -130,6 +130,83 @@ func TestIntEvaluatorRaw(t *testing.T) {
}
}
func TestInt8EvaluatorRaw(t *testing.T) {
tests := []struct {
pass bool
input string
}{
{false, "astring"}, // 0
{false, "astringwith_numb3rS_and_symbol$"}, // 1
{false, "32321"}, // 2
{true, "127" /* max int8 */}, // 3
{true, "-128" /* min int8 */}, // 4
{false, "128"}, // 5
{false, "-129"}, // 6
{false, "-18446744073709553213213213213213121615"}, // 7
{false, "42 18446744073709551615"}, // 8
{false, "--42"}, // 9
{false, "+42"}, // 10
{false, "main.css"}, // 11
{false, "/assets/main.css"}, // 12
}
for i, tt := range tests {
testEvaluatorRaw(t, Int8, tt.input, reflect.Int8, tt.pass, i)
}
}
func TestInt16EvaluatorRaw(t *testing.T) {
tests := []struct {
pass bool
input string
}{
{false, "astring"}, // 0
{false, "astringwith_numb3rS_and_symbol$"}, // 1
{true, "32321"}, // 2
{true, "32767" /* max int16 */}, // 3
{true, "-32768" /* min int16 */}, // 4
{false, "-32769"}, // 5
{false, "32768"}, // 6
{false, "-18446744073709553213213213213213121615"}, // 7
{false, "42 18446744073709551615"}, // 8
{false, "--42"}, // 9
{false, "+42"}, // 10
{false, "main.css"}, // 11
{false, "/assets/main.css"}, // 12
}
for i, tt := range tests {
testEvaluatorRaw(t, Int16, tt.input, reflect.Int16, tt.pass, i)
}
}
func TestInt32EvaluatorRaw(t *testing.T) {
tests := []struct {
pass bool
input string
}{
{false, "astring"}, // 0
{false, "astringwith_numb3rS_and_symbol$"}, // 1
{true, "32321"}, // 2
{true, "1"}, // 3
{true, "42"}, // 4
{true, "2147483647" /* max int32 */}, // 5
{true, "-2147483648" /* min int32 */}, // 6
{false, "-2147483649"}, // 7
{false, "2147483648"}, // 8
{false, "-18446744073709553213213213213213121615"}, // 9
{false, "42 18446744073709551615"}, // 10
{false, "--42"}, // 11
{false, "+42"}, // 12
{false, "main.css"}, // 13
{false, "/assets/main.css"}, // 14
}
for i, tt := range tests {
testEvaluatorRaw(t, Int32, tt.input, reflect.Int32, tt.pass, i)
}
}
func TestInt64EvaluatorRaw(t *testing.T) {
tests := []struct {
pass bool
@@ -155,6 +232,35 @@ func TestInt64EvaluatorRaw(t *testing.T) {
}
}
func TestUintEvaluatorRaw(t *testing.T) {
x64 := strconv.IntSize == 64
tests := []struct {
pass bool
input string
}{
{false, "astring"}, // 0
{false, "astringwith_numb3rS_and_symbol$"}, // 1
{true, "32321"}, // 2
{true, "1"}, // 3
{true, "42"}, // 4
{x64, "18446744073709551615" /* max uint64 */}, // 5
{true, "4294967295" /* max uint32 */}, // 6
{false, "-2147483649"}, // 7
{true, "2147483648"}, // 8
{false, "-18446744073709553213213213213213121615"}, // 9
{false, "42 18446744073709551615"}, // 10
{false, "--42"}, // 11
{false, "+42"}, // 12
{false, "main.css"}, // 13
{false, "/assets/main.css"}, // 14
}
for i, tt := range tests {
testEvaluatorRaw(t, Uint, tt.input, reflect.Uint, tt.pass, i)
}
}
func TestUint8EvaluatorRaw(t *testing.T) {
tests := []struct {
pass bool
@@ -184,6 +290,58 @@ func TestUint8EvaluatorRaw(t *testing.T) {
}
}
func TestUint16EvaluatorRaw(t *testing.T) {
tests := []struct {
pass bool
input string
}{
{false, "astring"}, // 0
{false, "astringwith_numb3rS_and_symbol$"}, // 1
{true, "32321"}, // 2
{true, "65535" /* max uint16 */}, // 3
{true, "0" /* min uint16 */}, // 4
{false, "-32769"}, // 5
{true, "32768"}, // 6
{false, "-18446744073709553213213213213213121615"}, // 7
{false, "42 18446744073709551615"}, // 8
{false, "--42"}, // 9
{false, "+42"}, // 10
{false, "main.css"}, // 11
{false, "/assets/main.css"}, // 12
}
for i, tt := range tests {
testEvaluatorRaw(t, Uint16, tt.input, reflect.Uint16, tt.pass, i)
}
}
func TestUint32EvaluatorRaw(t *testing.T) {
tests := []struct {
pass bool
input string
}{
{false, "astring"}, // 0
{false, "astringwith_numb3rS_and_symbol$"}, // 1
{true, "32321"}, // 2
{true, "1"}, // 3
{true, "42"}, // 4
{true, "4294967295" /* max uint32*/}, // 5
{true, "0" /* min uint32 */}, // 6
{false, "-2147483649"}, // 7
{true, "2147483648"}, // 8
{false, "-18446744073709553213213213213213121615"}, // 9
{false, "42 18446744073709551615"}, // 10
{false, "--42"}, // 11
{false, "+42"}, // 12
{false, "main.css"}, // 13
{false, "/assets/main.css"}, // 14
}
for i, tt := range tests {
testEvaluatorRaw(t, Uint32, tt.input, reflect.Uint32, tt.pass, i)
}
}
func TestUint64EvaluatorRaw(t *testing.T) {
tests := []struct {
pass bool

View File

@@ -48,6 +48,8 @@ var (
simpleNumberEval = MustRegexp("^-?[0-9]+$")
// Int or number type
// both positive and negative numbers, actual value can be min-max int64 or min-max int32 depends on the arch.
// If x64: -9223372036854775808 to 9223372036854775807.
// If x32: -2147483648 to 2147483647 and etc..
Int = NewMacro("int", "number", false, false, func(paramValue string) (interface{}, bool) {
if !simpleNumberEval(paramValue) {
return nil, false
@@ -206,8 +208,8 @@ var (
// Uint as uint type
// actual value can be min-max uint64 or min-max uint32 depends on the arch.
// if x64: 0 to 18446744073709551615
// if x32: 0 to 4294967295 and etc.
// If x64: 0 to 18446744073709551615.
// If x32: 0 to 4294967295 and etc.
Uint = NewMacro("uint", "", false, false, func(paramValue string) (interface{}, bool) {
v, err := strconv.ParseUint(paramValue, 10, strconv.IntSize) // 32,64...
if err != nil {