Skip to content

Commit

Permalink
address: only run libpostal tests with the build tag provided
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Dec 19, 2024
1 parent d1aa810 commit a093b3f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 69 deletions.
72 changes: 72 additions & 0 deletions pkg/address/address_libpostal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//go:build libpostal

package address

import (
"fmt"
"testing"

"github.com/moov-io/watchman/pkg/search"

postal "github.com/openvenues/gopostal/parser"
"github.com/stretchr/testify/require"
)

func TestParseAddress(t *testing.T) {
cases := []struct {
input string
expected search.Address
}{
{
input: "101 Maple Street Apt 202 Bigcity, New York 11222",
expected: search.Address{
Line1: "101 maple street",
Line2: "apt 202",
City: "bigcity",
PostalCode: "11222",
State: "new york",
},
},
}
for _, tc := range cases {
name := fmt.Sprintf("%#v", tc.expected)

t.Run(name, func(t *testing.T) {
got := ParseAddress(tc.input)
require.Equal(t, tc.expected, got)
})
}
}

func TestOrganizeLibpostalComponents(t *testing.T) {
cases := []struct {
parts []postal.ParsedComponent
expected search.Address
}{
{
parts: []postal.ParsedComponent{
{Label: "house_number", Value: "101"},
{Label: "road", Value: "Main Street"},
{Label: "city", Value: "Springfield"},
{Label: "state", Value: "Illinois"},
{Label: "postcode", Value: "62704"},
{Label: "country", Value: "United States"},
},
expected: search.Address{
Line1: "101 Main Street",
City: "Springfield",
PostalCode: "62704",
State: "Illinois",
Country: "United States",
},
},
}
for _, tc := range cases {
name := fmt.Sprintf("%#v", tc.expected)

t.Run(name, func(t *testing.T) {
got := organizeLibpostalComponents(tc.parts)
require.Equal(t, tc.expected, got)
})
}
}
71 changes: 2 additions & 69 deletions pkg/address/address_test.go
Original file line number Diff line number Diff line change
@@ -1,70 +1,3 @@
package address

import (
"fmt"
"testing"

"github.com/moov-io/watchman/pkg/search"

postal "github.com/openvenues/gopostal/parser"
"github.com/stretchr/testify/require"
)
//go:build !libpostal

func TestParseAddress(t *testing.T) {
cases := []struct {
input string
expected search.Address
}{
{
input: "101 Maple Street Apt 202 Bigcity, New York 11222",
expected: search.Address{
Line1: "101 maple street",
Line2: "apt 202",
City: "bigcity",
PostalCode: "11222",
State: "new york",
},
},
}
for _, tc := range cases {
name := fmt.Sprintf("%#v", tc.expected)

t.Run(name, func(t *testing.T) {
got := ParseAddress(tc.input)
require.Equal(t, tc.expected, got)
})
}
}

func TestOrganizeLibpostalComponents(t *testing.T) {
cases := []struct {
parts []postal.ParsedComponent
expected search.Address
}{
{
parts: []postal.ParsedComponent{
{Label: "house_number", Value: "101"},
{Label: "road", Value: "Main Street"},
{Label: "city", Value: "Springfield"},
{Label: "state", Value: "Illinois"},
{Label: "postcode", Value: "62704"},
{Label: "country", Value: "United States"},
},
expected: search.Address{
Line1: "101 Main Street",
City: "Springfield",
PostalCode: "62704",
State: "Illinois",
Country: "United States",
},
},
}
for _, tc := range cases {
name := fmt.Sprintf("%#v", tc.expected)

t.Run(name, func(t *testing.T) {
got := organizeLibpostalComponents(tc.parts)
require.Equal(t, tc.expected, got)
})
}
}
package address

0 comments on commit a093b3f

Please sign in to comment.