Sandboxed gopher-lua with time, memory and call-stack limits from [sandbox], a goquery-backed doc API, price parsing, and the 'check', 'plugin test' and 'fixtures' commands. Sellers are first_party, fulfilled (shipped by the shop) or third_party, and items accept fulfilled by default; used-only offers are not available. Plugin tests run on real pages that 'dibs fixtures' fetches into an untracked directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.6 KiB
Go
43 lines
1.6 KiB
Go
package price
|
|
|
|
import "testing"
|
|
|
|
func TestParse(t *testing.T) {
|
|
for in, want := range map[string]struct {
|
|
value float64
|
|
currency string
|
|
}{
|
|
"1.299,99 €": {1299.99, "EUR"},
|
|
"£1,299.99": {1299.99, "GBP"},
|
|
"1 299,99 €": {1299.99, "EUR"},
|
|
"1\u00a0299,99\u00a0€": {1299.99, "EUR"},
|
|
"1\u202f299,99 €": {1299.99, "EUR"},
|
|
"129,99 €": {129.99, "EUR"},
|
|
"129,99€": {129.99, "EUR"},
|
|
"€129.99": {129.99, "EUR"},
|
|
"$1,299.99": {1299.99, "USD"},
|
|
"US$ 49.00": {49, "USD"},
|
|
"EUR 12,50": {12.5, "EUR"},
|
|
"12.50 GBP": {12.5, "GBP"},
|
|
"CHF 1'299.90": {1299.9, "CHF"},
|
|
"1.299 €": {1299, "EUR"},
|
|
"1,299": {1299, ""},
|
|
"1.299.000,00 €": {1299000, "EUR"},
|
|
"12,5": {12.5, ""},
|
|
"9.99": {9.99, ""},
|
|
"49": {49, ""},
|
|
"Preis: 59,99 € inkl. MwSt.": {59.99, "EUR"},
|
|
" £7. ": {7, "GBP"},
|
|
"99,00 zł": {99, "PLN"},
|
|
} {
|
|
v, c, ok := Parse(in)
|
|
if !ok || v != want.value || c != want.currency { t.Errorf("Parse(%q) = %v, %q, %v; want %v, %q", in, v, c, ok, want.value, want.currency) }
|
|
}
|
|
}
|
|
|
|
func TestParseNoPrice(t *testing.T) {
|
|
for _, in := range []string{"", "Derzeit nicht verfügbar", "€", "kostenlos"} {
|
|
if v, c, ok := Parse(in); ok { t.Errorf("Parse(%q) = %v, %q, true; want no price", in, v, c) }
|
|
}
|
|
}
|