Skip to content

Commit

Permalink
fix: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rawnly committed Apr 25, 2023
1 parent 67fbfe1 commit 717565c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
20 changes: 6 additions & 14 deletions __tests__/parser_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package __tests__

import (
"fmt"
"github.com/rawnly/splash-cli/lib"
"testing"

"github.com/rawnly/splash-cli/lib"
)

type testCase struct {
Expand All @@ -12,6 +12,10 @@ type testCase struct {
}

var photoUrls []testCase = []testCase{
{
expected: "KegVP1pjsb4",
data: "https://unsplash.com/photos/KegVP1pjsb4",
},
{
expected: "fPbLnMMd8BU",
data: "https://unsplash.com/photos/fPbLnMMd8BU",
Expand Down Expand Up @@ -60,18 +64,6 @@ func TestParsePhotoIDFromUrl(t *testing.T) {
}
}

func TestParseCollectionIDFromUrl(t *testing.T) {
for i, tCase := range collectionUrlsForParsing {
id, name := lib.ParseCollectionFromUrl(tCase.data)

result := fmt.Sprintf("%s|%s", id, name)

if result != tCase.expected {
t.Errorf("[%d] Expected \"%s\" received \"%s\"", i, tCase.expected, parseResult(result))
}
}
}

//var urls = []string{
// "https://unsplash.com",
// "https://unsplash.com/collections/8791381/aerial-beaches",
Expand Down
8 changes: 5 additions & 3 deletions lib/expressions/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package expressions

import "regexp"

const CollectionIdExtractor string = "unsplash\\.com\\/collections\\/([A-z0-9]+)\\/([a-z\\-]+)$"
const PhotoIdExtractor string = "unsplash\\.com\\/photos\\/([A-z0-9]+)$"
const (
CollectionIdExtractor string = "unsplash\\.com\\/collections\\/([A-z0-9]+)\\/([a-z\\-]+)\\/?$"
PhotoIdExtractor string = "unsplash\\.com\\/photos\\/([A-z0-9]+)\\/?$"
)

func IsPhotoUrl(url string) bool {
re := regexp.MustCompile(PhotoIdExtractor)
Expand Down Expand Up @@ -40,4 +42,4 @@ func ExtractCollectionId(url string) (id string, name string) {
}

return "", ""
}
}

0 comments on commit 717565c

Please sign in to comment.