From 2ea2204a8beaa9a7ecb4047cccf79b1698fc21f4 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 30 Apr 2012 21:57:42 +0200 Subject: [PATCH] add test --- parse_test.go | 23 +++++++++++++++++------ zscan_rr.go | 13 +++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/parse_test.go b/parse_test.go index 2fce27f9..8ae9e228 100644 --- a/parse_test.go +++ b/parse_test.go @@ -252,12 +252,23 @@ func TestParseNSEC(t *testing.T) { } func TestParseLOC(t *testing.T) { - l1, e := NewRR("SW1A2AA.find.me.uk. 604797 IN LOC 51 30 12.748 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m") - if e != nil { - t.Log("Failed to parse LOC RR: " + e.Error()) - t.Fatal() - } else { - t.Logf("RR is OK: `%s'\n", l1.String()) + lt := map[string]string{ + "SW1A2AA.find.me.uk. LOC 51 30 12.748 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m": + "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t51 30 12.748 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m", + } + for i, o := range lt { + rr, e := NewRR(i) + if e != nil { + t.Log("Failed to parse RR: " + e.Error()) + t.Fail() + continue + } + if rr.String() != o { + t.Logf("`%s' should be equal to\n`%s', but is `%s'\n", i, o, rr.String()) + t.Fail() + } else { + t.Logf("RR is OK: `%s'", rr.String()) + } } } diff --git a/zscan_rr.go b/zscan_rr.go index 04952dea..a76bc028 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -449,10 +449,10 @@ func setLOC(h RR_Header, c chan lex, f string) (RR, *ParseError) { if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok { goto East } - if i, e := strconv.Atoi(l.token); e != nil { + if i, e := strconv.ParseFloat(l.token, 32); e != nil { return nil, &ParseError{f, "bad LOC Latitude seconds", l} } else { - rr.Latitude += 1000 * 60 * 60 * uint32(i) + rr.Latitude += uint32(1000 * 60 * 60 * i) } <-c // _BLANK // Either number, 'N' or 'S' @@ -465,6 +465,7 @@ func setLOC(h RR_Header, c chan lex, f string) (RR, *ParseError) { East: // East + <-c // _BLANK l = <-c if i, e := strconv.Atoi(l.token); e != nil { return nil, &ParseError{f, "bad LOC Longitude", l} @@ -488,10 +489,10 @@ East: if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok { goto Altitude } - if i, e := strconv.Atoi(l.token); e != nil { + if i, e := strconv.ParseFloat(l.token, 32); e != nil { return nil, &ParseError{f, "bad LOC Longitude seconds", l} } else { - rr.Longitude += 1000 * 60 * 60 * uint32(i) + rr.Longitude += uint32(1000 * 60 * 60 * i) } <-c // _BLANK // Either number, 'E' or 'W' @@ -508,10 +509,10 @@ Altitude: if l.token[len(l.token)-1] == 'M' || l.token[len(l.token)-1] == 'm' { l.token = l.token[0 : len(l.token)-1] } - if i, e := strconv.Atoi(l.token); e != nil { + if i, e := strconv.ParseFloat(l.token, 32); e != nil { return nil, &ParseError{f, "bad LOC Altitude", l} } else { - rr.Altitude = uint32(i*100.0 + 10000000.0) // +0.5 in ldns? + rr.Altitude = uint32(i*100.0 + 10000000.0 + 0.5) } // And now optionally the other values