From feca0e9c6176b15c8e1c6e446a89d04914e8db8e Mon Sep 17 00:00:00 2001 From: Anton Zadvorny Date: Fri, 12 Jan 2024 12:20:28 +0300 Subject: [PATCH] Test operators --- filter_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/filter_test.go b/filter_test.go index 4de96f2..65d6c03 100644 --- a/filter_test.go +++ b/filter_test.go @@ -54,3 +54,16 @@ func TestFilter(t *testing.T) { assert.Equal(t, expected, Filter(doc1, doc2, doc3)) }) } + +func TestOperators(t *testing.T) { + assert.Equal(t, Eq("field", 1), FilterDocument{"field": {"$eq": 1}}) + assert.Equal(t, Ne("field", 1), FilterDocument{"field": {"$ne": 1}}) + assert.Equal(t, Gt("field", 1), FilterDocument{"field": {"$gt": 1}}) + assert.Equal(t, Gte("field", 1), FilterDocument{"field": {"$gte": 1}}) + assert.Equal(t, Lt("field", 1), FilterDocument{"field": {"$lt": 1}}) + assert.Equal(t, Lte("field", 1), FilterDocument{"field": {"$lte": 1}}) + assert.Equal(t, In("field", []int{1, 2, 3}), FilterDocument{"field": {"$in": []int{1, 2, 3}}}) + assert.Equal(t, Nin("field", []int{1, 2, 3}), FilterDocument{"field": {"$nin": []int{1, 2, 3}}}) + assert.Equal(t, Exists("field", true), FilterDocument{"field": {"$exists": true}}) + assert.Equal(t, Regex("field", "test"), FilterDocument{"field": {"$regex": "test"}}) +}