feat: create And method

pull/12/head
sundowndev 2020-09-05 16:53:58 +02:00
parent 9da2506700
commit 981b9721ed
2 changed files with 19 additions and 1 deletions

View File

@ -65,6 +65,12 @@ func (e *GoogleSearch) Or() *GoogleSearch {
return e
}
// And puts an AND operator in the request
func (e *GoogleSearch) And() *GoogleSearch {
e.tags = append(e.tags, operatorAnd)
return e
}
// Intext searches for the occurrences of keywords all at once or one at a time.
func (e *GoogleSearch) Intext(text string) *GoogleSearch {
e.tags = append(e.tags, e.concat(intextTag, text, true))

View File

@ -114,7 +114,7 @@ func TestInit(t *testing.T) {
assert.Equal(result, "-html -htm -php -md5sums", "they should be equal")
})
t.Run("should handle or tag correctly", func(t *testing.T) {
t.Run("should handle 'OR' tag correctly", func(t *testing.T) {
dork = NewGoogleSearch()
result := dork.
@ -126,6 +126,18 @@ func TestInit(t *testing.T) {
assert.Equal(result, "site:facebook.com | site:twitter.com", "they should be equal")
})
t.Run("should handle 'AND' tag correctly", func(t *testing.T) {
dork = NewGoogleSearch()
result := dork.
Intitle("facebook").
And().
Intitle("twitter").
String()
assert.Equal(result, "intitle:\"facebook\" + intitle:\"twitter\"", "they should be equal")
})
t.Run("should handle group tag correctly", func(t *testing.T) {
dork = NewGoogleSearch()