only accept 32bit ints for Integer type, closes #21

master
Oliver Tonnhofer 2014-04-25 11:32:40 +02:00
parent 96b5f1c394
commit 90154d7c51
2 changed files with 32 additions and 1 deletions

View File

@ -118,7 +118,7 @@ func String(val string, elem *element.OSMElem, match Match) interface{} {
}
func Integer(val string, elem *element.OSMElem, match Match) interface{} {
v, err := strconv.ParseInt(val, 10, 64)
v, err := strconv.ParseInt(val, 10, 32)
if err != nil {
return nil
}

View File

@ -36,6 +36,37 @@ func TestBool(t *testing.T) {
}
func TestInteger(t *testing.T) {
match := Match{}
if v := Integer("", nil, match); v != nil {
t.Errorf(" -> %v", v)
}
if v := Integer("bar", nil, match); v != nil {
t.Errorf("bar -> %v", v)
}
if v := Integer("1e6", nil, match); v != nil {
t.Errorf("1e6 -> %v", v)
}
if v := Integer("0", nil, match); v.(int64) != 0 {
t.Errorf("0 -> %v", v)
}
if v := Integer("123456", nil, match); v.(int64) != 123456 {
t.Errorf("123456 -> %v", v)
}
if v := Integer("-123456", nil, match); v.(int64) != -123456 {
t.Errorf("-123456 -> %v", v)
}
// >2^32, but <2^64, Integer type defaults to int32
if v := Integer("1000000000000000000", nil, match); v != nil {
t.Errorf("1000000000000000000 -> %v", v)
}
// >2^64
if v := Integer("19082139812039812093908123", nil, match); v != nil {
t.Errorf("19082139812039812093908123 -> %v", v)
}
}
func TestMakeSuffixReplace(t *testing.T) {
field := Field{
"name", "name", "string_suffixreplace",