Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Created September 8, 2020 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sogaiu/77f2bc36be4cbe41fd2363edcd740d2b to your computer and use it in GitHub Desktop.
Save sogaiu/77f2bc36be4cbe41fd2363edcd740d2b to your computer and use it in GitHub Desktop.
sample use of test.check of tree-sitter-clojure via libpython-clj
;; XXX: sorry no require stuff atm
(def radix-str
(gen/let [sign (gen/elements ["" "+" "-"])
radix (gen/choose 2 36)
r-or-R (gen/elements ["R" "r"])
n gen/nat
nums (gen/vector (gen/choose 0 (dec radix))
(inc n))
caps (gen/vector gen/boolean
(inc n))]
(str sign
radix
r-or-R
(cs/join (map (fn [num cap]
(if (<= num 9)
(char (+ num 48))
(char (+ num (if cap 55 87)))))
nums
caps)))))
(def parses-radix-prop
(prop/for-all [radix-as-str radix-str]
(let [tree (parse-str radix-as-str)
root-node (py/get-attr tree "root_node")
children (py/get-attr root-node "children")
n-children (count children)
child (py/get-item children 0)
child-type (py/get-attr child "type")]
(and (= n-children 1)
(= child-type "number")))))
(check/quick-check 10000 parses-radix-prop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment