func (s *mySuite) TestErrors() { emptyUSD, err := ParseUSD("") s.Equal(fmt.Sprintf("%s", err), "go_utils.ParseUSD: parsing \"\": value out of range") s.Equal(u.TypeOf(emptyUSD), "go_currency.USD") unnecessaryDeciaml, err := ParseUSD("2.") s.Equal(fmt.Sprintf("%s", err), "go_utils.ParseUSD: parsing \"2.\": value out of range") s.Equal(u.TypeOf(unnecessaryDeciaml), "go_currency.USD") usd250, err := ParseUSD(".") s.Equal(fmt.Sprintf("%s", err), "go_utils.ParseUSD: parsing \".\": value out of range") s.Equal(u.TypeOf(usd250), "go_currency.USD") s.Equal(fmt.Sprintf("%s", usd250), "0.00") }
func (s *mySuite) TestReadConfigFile() { //------------------------------------------------ // Read JSON file //------------------------------------------------ /* { "lineitem1": { "description": "SSD Drive", "count": 2, "priceUSD": "250.00" }, "lineitem2": { "description": "RAM Chip", "count": 4, "priceUSD": "125.50" } } */ obj, err := jc.ReadFile("testdata/invoice.json") if err != nil { log.Fatal(err) } lineitem1 := obj.RequiredObject("lineitem1") //------------------------------------------------ // description == "SSD Drive" //------------------------------------------------ s.Equal(lineitem1["description"], "SSD Drive") //------------------------------------------------ // count == 2 //------------------------------------------------ lineitem1_count, err := u.ConvNumToInt(lineitem1["count"]) if err != nil { log.Fatal(err) } s.Equal(lineitem1_count, int(2)) //------------------------------------------------ // priceUSD == 250.00 //------------------------------------------------ item1PriceUSD, err := ParseUSD(lineitem1["priceUSD"].(string)) if err != nil { log.Fatal(err) } usd250, err := ParseUSD("250.00") if err != nil { log.Fatal(err) } s.Equal(item1PriceUSD, usd250) s.Equal(u.TypeOf(usd250), "go_currency.USD") }