Skip to content

Commit

Permalink
Merge pull request #11 from austin1237/regular-expression
Browse files Browse the repository at this point in the history
regular expression used instead of string.Contains and added tests.
  • Loading branch information
austin1237 authored Feb 16, 2024
2 parents c9501d1 + 43fe373 commit 0e64cd6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scraper/interest/interest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package interest

import (
"fmt"
"regexp"
"scraper/job"
"strings"
"sync"
)

func CheckIfInterested(description string) bool {
keywords := []string{"typescript", "node", "nodejs", "node.js", "go ", "golang", "go,", "go)", "(go"}
keywords := []string{"typescript", "node", "nodejs", "node.js", "go", "golang"}
// Check if keywords are present in the job's text
descriptionToLower := strings.ToLower(description)
for _, keyword := range keywords {
if strings.Contains(descriptionToLower, keyword) {
pattern := "\\b" + keyword + "\\b"
match, _ := regexp.MatchString(pattern, descriptionToLower)
if match {
return true
}
}
Expand Down
52 changes: 52 additions & 0 deletions scraper/interest/interest_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package interest

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCheckIfInterested(t *testing.T) {
tests := []struct {
name string
description string
want bool
}{
{
name: "contains typescript",
description: "This is a job for a TypeScript developer",
want: true,
},
{
name: "contains node",
description: "This is a job for a Node.js developer",
want: true,
},
{
name: "contains go",
description: "This is a job for a Go developer",
want: true,
},
{
name: "contains go",
description: "This is a job for go.",
want: true,
},
{
name: "contains django",
description: "This is a job for a django developer in Chicago",
want: false,
},
{
name: "does not contain keyword",
description: "This is a job for a Python developer",
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, CheckIfInterested(tt.description))
})
}
}

0 comments on commit 0e64cd6

Please sign in to comment.