Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
fbbd09d4
Commit
fbbd09d4
authored
1 year ago
by
Danis Kirasirov
Browse files
Options
Downloads
Patches
Plain Diff
Добавлены тесты
parent
a2d0bee5
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkg/expr/expr_test.go
+9
-1
9 additions, 1 deletion
pkg/expr/expr_test.go
pkg/expr/mongo.go
+3
-3
3 additions, 3 deletions
pkg/expr/mongo.go
pkg/expr/mongo_test.go
+18
-5
18 additions, 5 deletions
pkg/expr/mongo_test.go
with
30 additions
and
9 deletions
pkg/expr/expr_test.go
+
9
−
1
View file @
fbbd09d4
...
...
@@ -39,7 +39,15 @@ func TestIsExpression(t *testing.T) {
{
"time"
,
fmt
.
Sprintf
(
"d > Time.Time('%s')"
,
now
.
Format
(
time
.
RFC3339
)),
true
},
{
"in"
,
"In(s, [1,2,3])"
,
true
},
{
"in"
,
"In(s, 1)"
,
true
},
{
"exists"
,
"exists(s)"
,
true
},
{
"exists#1"
,
"exists(s)"
,
true
},
{
"exists#2"
,
"exists"
,
false
},
{
"len#1"
,
"len(s) == 1"
,
true
},
{
"len#2"
,
"len(s) != 1"
,
true
},
{
"len#3"
,
"len(s) > 1"
,
true
},
{
"len#4"
,
"len(s) >= 1"
,
true
},
{
"len#5"
,
"len(s) < 1"
,
true
},
{
"len#6"
,
"len(s) <= 1"
,
true
},
{
"len#7"
,
"len"
,
false
},
{
"text search or id"
,
"id"
,
false
},
{
"numbers"
,
"3"
,
false
},
}
...
...
This diff is collapsed.
Click to expand it.
pkg/expr/mongo.go
+
3
−
3
View file @
fbbd09d4
...
...
@@ -410,10 +410,10 @@ func (c *compiler) CallNode(node *ast.CallNode) interface{} {
return
bson
.
M
{
fields
:
bson
.
M
{
"$in"
:
array
}}
case
"exists"
:
field
:=
c
.
identifier
(
node
.
Arguments
[
0
])
if
field
==
""
{
panic
(
"incorrect argument, empty field name"
)
if
len
(
node
.
Arguments
)
!=
1
{
panic
(
"exists() expects exactly 1 argument"
)
}
field
:=
c
.
identifier
(
node
.
Arguments
[
0
])
return
bson
.
M
{
"$or"
:
bson
.
A
{
bson
.
M
{
field
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
}},
bson
.
M
{
field
:
bson
.
M
{
"$ne"
:
nil
}},
...
...
This diff is collapsed.
Click to expand it.
pkg/expr/mongo_test.go
+
18
−
5
View file @
fbbd09d4
...
...
@@ -30,12 +30,25 @@ func TestConvertToMongo(t *testing.T) {
{
"equal"
,
"s == 3"
,
nil
,
bson
.
M
{
"s"
:
3
},
false
},
{
"in array"
,
"s in [1,2,3]"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
,
2
,
3
}}},
false
},
{
"not in array"
,
"s not in [1,2,3]"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$nin"
:
[]
interface
{}{
1
,
2
,
3
}}},
false
},
{
"exists"
,
"exists(s)"
,
nil
,
bson
.
M
{
"$or"
:
bson
.
A
{
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
}},
bson
.
M
{
"s"
:
bson
.
M
{
"$ne"
:
nil
}}}},
false
},
{
"len equal"
,
"len(s) == 1"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$size"
:
1
}},
false
},
{
"len equal empty"
,
"len(s) == 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}},
false
},
{
"exists#1"
,
"exists(s)"
,
nil
,
bson
.
M
{
"$or"
:
bson
.
A
{
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
}},
bson
.
M
{
"s"
:
bson
.
M
{
"$ne"
:
nil
}}}},
false
},
{
"exists#2"
,
"exists(s, s)"
,
nil
,
nil
,
true
},
{
"len#1"
,
"len(s)"
,
nil
,
nil
,
true
},
{
"len#2"
,
"len(s) <> 1"
,
nil
,
nil
,
true
},
{
"len#3"
,
"len(s) == -1"
,
nil
,
nil
,
true
},
{
"len#4"
,
"len(s, s) == -1"
,
nil
,
nil
,
true
},
{
"len#5"
,
"len(s) == s"
,
nil
,
nil
,
true
},
{
"len eq"
,
"len(s) == 1"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$size"
:
1
}},
false
},
{
"len eq zero"
,
"len(s) == 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}},
false
},
{
"len ne"
,
"len(s) != 1"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$not"
:
bson
.
M
{
"$size"
:
1
}}},
false
},
{
"len ne zero"
,
"len(s) != 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$ne"
:
bson
.
A
{},
"$type"
:
"array"
}},
false
},
{
"len gt"
,
"len(s) > 1"
,
nil
,
bson
.
M
{
"s.1"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len gt 0"
,
"len(s) > 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
,
"$ne"
:
bson
.
A
{}}},
false
},
{
"len gt zero"
,
"len(s) > 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
,
"$ne"
:
bson
.
A
{}}},
false
},
{
"len gte"
,
"len(s) >= 1"
,
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len gte zero"
,
"len(s) >= 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
}},
false
},
{
"len lt"
,
"len(s) < 1"
,
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
false
}},
false
},
{
"len lt zero"
,
"len(s) < 0"
,
nil
,
nil
,
true
},
{
"len lte"
,
"len(s) <= 1"
,
nil
,
bson
.
M
{
"s.1"
:
bson
.
M
{
"$exists"
:
false
}},
false
},
{
"len lte zero"
,
"len(s) <= 0"
,
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
false
}},
false
},
{
"field#1"
,
"s.test > 3"
,
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"field#2"
,
"s['test'] > 3"
,
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"field#3"
,
"s[test] > 3"
,
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment