forked from tonsky/datascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_find.cljc
52 lines (46 loc) · 2.46 KB
/
parser_find.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(ns datascript.test.parser-find
(:require
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript.core :as d]
[datascript.db :as db]
[datascript.parser :as dp]
[datascript.test.core :as tdc]))
#?(:cljs
(def Throwable js/Error))
(deftest test-parse-find
(is (= (dp/parse-find '[?a ?b])
(dp/->FindRel [(dp/->Variable '?a) (dp/->Variable '?b)])))
(is (= (dp/parse-find '[[?a ...]])
(dp/->FindColl (dp/->Variable '?a))))
(is (= (dp/parse-find '[?a .])
(dp/->FindScalar (dp/->Variable '?a))))
(is (= (dp/parse-find '[[?a ?b]])
(dp/->FindTuple [(dp/->Variable '?a) (dp/->Variable '?b)]))))
(deftest test-parse-aggregate
(is (= (dp/parse-find '[?a (count ?b)])
(dp/->FindRel [(dp/->Variable '?a) (dp/->Aggregate (dp/->PlainSymbol 'count) [(dp/->Variable '?b)])])))
(is (= (dp/parse-find '[[(count ?a) ...]])
(dp/->FindColl (dp/->Aggregate (dp/->PlainSymbol 'count) [(dp/->Variable '?a)]))))
(is (= (dp/parse-find '[(count ?a) .])
(dp/->FindScalar (dp/->Aggregate (dp/->PlainSymbol 'count) [(dp/->Variable '?a)]))))
(is (= (dp/parse-find '[[(count ?a) ?b]])
(dp/->FindTuple [(dp/->Aggregate (dp/->PlainSymbol 'count) [(dp/->Variable '?a)]) (dp/->Variable '?b)]))))
(deftest test-parse-custom-aggregates
(is (= (dp/parse-find '[(aggregate ?f ?a)])
(dp/->FindRel [(dp/->Aggregate (dp/->Variable '?f) [(dp/->Variable '?a)])])))
(is (= (dp/parse-find '[?a (aggregate ?f ?b)])
(dp/->FindRel [(dp/->Variable '?a) (dp/->Aggregate (dp/->Variable '?f) [(dp/->Variable '?b)])])))
(is (= (dp/parse-find '[[(aggregate ?f ?a) ...]])
(dp/->FindColl (dp/->Aggregate (dp/->Variable '?f) [(dp/->Variable '?a)]))))
(is (= (dp/parse-find '[(aggregate ?f ?a) .])
(dp/->FindScalar (dp/->Aggregate (dp/->Variable '?f) [(dp/->Variable '?a)]))))
(is (= (dp/parse-find '[[(aggregate ?f ?a) ?b]])
(dp/->FindTuple [(dp/->Aggregate (dp/->Variable '?f) [(dp/->Variable '?a)]) (dp/->Variable '?b)]))))
(deftest test-parse-find-elements
(is (= (dp/parse-find '[(count ?b 1 $x) .])
(dp/->FindScalar (dp/->Aggregate (dp/->PlainSymbol 'count)
[(dp/->Variable '?b)
(dp/->Constant 1)
(dp/->SrcVar '$x)])))))
#_(t/test-ns 'datascript.test.find-parser)