-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
973fcc8
commit 0db8a7a
Showing
3 changed files
with
38 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
package utils | ||
|
||
import ( | ||
"bytes" | ||
"github.com/PuerkitoBio/goquery" | ||
"github.com/stretchr/testify/assert" | ||
"io/ioutil" | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
func TestParseInt(t *testing.T) { | ||
assert.Equal(t, int64(1234567890), ParseInt("1.234.567.890")) | ||
} | ||
|
||
func TestParseInt2(t *testing.T) { | ||
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/unversioned/deathstar_price.html") | ||
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTMLBytes)) | ||
title := doc.Find("li.metal").AttrOr("title", "") | ||
metalStr := regexp.MustCompile(`([\d.]+)`).FindStringSubmatch(title)[1] | ||
metal := ParseInt(metalStr) | ||
assert.Equal(t, int64(5000000), metal) | ||
|
||
pageHTMLBytes, _ = ioutil.ReadFile("../../samples/unversioned/mrd_price.html") | ||
doc, _ = goquery.NewDocumentFromReader(bytes.NewReader(pageHTMLBytes)) | ||
title = doc.Find("li.metal").AttrOr("title", "") | ||
metalStr = regexp.MustCompile(`([\d.]+)`).FindStringSubmatch(title)[1] | ||
metal = ParseInt(metalStr) | ||
assert.Equal(t, int64(1555733200), metal) | ||
} | ||
|
||
func TestToInt(t *testing.T) { | ||
assert.Equal(t, 1234567890, ToInt([]byte("1234567890"))) | ||
} | ||
|
||
func TestMinInt(t *testing.T) { | ||
assert.Equal(t, int64(2), MinInt(5, 2, 3)) | ||
} | ||
|
||
func TestI64Ptr(t *testing.T) { | ||
v := int64(6) | ||
assert.Equal(t, &v, I64Ptr(6)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters