Skip to content

Commit

Permalink
Add test for regex, nin and not
Browse files Browse the repository at this point in the history
  • Loading branch information
sneljo1 committed Dec 20, 2017
1 parent 28d4fa2 commit c9d1694
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/nin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package test

import (
"github.com/wearetheledger/go-couchdb-query-engine/query"
"testing"
)

func TestNin(t *testing.T) {

t.Run("size should not equal any elements", func(t *testing.T) {

res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
"selector": map[string]interface{}{
"size": map[string]interface{}{
"$nin": []int{
1000, 99,
},
},
},
})

if err != nil {
t.Error(err)
}

if len(res) != 3 {
t.Error("Query should have returned 3 results")
}
})

t.Run("owner should not equal any elements", func(t *testing.T) {

res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
"selector": map[string]interface{}{
"owner": map[string]interface{}{
"$nin": []string{
"maria", "aaron",
},
},
},
})

if err != nil {
t.Error(err)
}

if len(res) != 3 {
t.Error("Query should have returned 3 results")
}
})
}
49 changes: 49 additions & 0 deletions test/not_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package test

import (
"github.com/wearetheledger/go-couchdb-query-engine/query"
"testing"
)

func TestNot(t *testing.T) {

t.Run("Size should equal 3", func(t *testing.T) {
res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
"selector": map[string]interface{}{
"size": map[string]interface{}{
"$not": map[string]interface{}{
"$eq": 3,
},
},
},
})

if err != nil {
t.Error(err)
}

if len(res) != 2 {
t.Error("Query should have returned 2 result")
}
})

t.Run("ObjectType should equal marble", func(t *testing.T) {
res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
"selector": map[string]interface{}{
"objectType": map[string]interface{}{
"$not": map[string]interface{}{
"$eq": "MARBLE",
},
},
},
})

if err != nil {
t.Error(err)
}

if len(res) != 0 {
t.Error("Query should have returned 0 results")
}
})
}
47 changes: 47 additions & 0 deletions test/regex_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package test

import (
"github.com/wearetheledger/go-couchdb-query-engine/query"
"testing"
)

func TestRegex(t *testing.T) {

t.Run("Owner property should include B", func(t *testing.T) {

res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
"selector": map[string]interface{}{
"owner": map[string]interface{}{
"$regex": "^b",
},
},
})

if err != nil {
t.Error(err)
}

if len(res) != 1 {
t.Error("Query should have returned 1 results")
}
})

t.Run("Owner property should include letters", func(t *testing.T) {

res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
"selector": map[string]interface{}{
"owner": map[string]interface{}{
"$regex": "[a-z]",
},
},
})

if err != nil {
t.Error(err)
}

if len(res) != 3 {
t.Error("Query should have returned 3 results")
}
})
}

0 comments on commit c9d1694

Please sign in to comment.