Debian Codegraph @

test/api.fnl

raw
1 (local t (require :test.faith))
2
3 (local expected {
4 :comment "function"
5 :comment? "function"
6 :compile "function"
7 :compile-stream "function"
8 :compile-string "function"
9 :doc "function"
10 :dofile "function"
11 :eval "function"
12 :getinfo "function"
13 :install "function"
14 :list "function"
15 :list? "function"
16 :load-code "function"
17 :macro-loaded "table"
18 :macro-path "string"
19 :macro-searchers "table"
20 :make-searcher "function"
21 :metadata "table"
22 :multi-sym? "function"
23 :parser "function"
24 :path "string"
25 :repl "callable"
26 :runtime-version "function"
27 :search-module "function"
28 :searcher "function"
29 :sequence "function"
30 :sequence? "function"
31 :sym "function"
32 :sym-char? "function"
33 :sym? "function"
34 :syntax "function"
35 :table? "function"
36 :traceback "function"
37 :varg "function"
38 :varg? "function"
39 :version "string"
40 :view "function"
41 :ast-source "function"})
42
43 (local expected-aliases {
44 :compileStream "function"
45 :compileString "function"
46 :loadCode "function"
47 :macroLoaded "table"
48 :macroPath "string"
49 :macroSearchers "table"
50 :makeSearcher "function"
51 :runtimeVersion "function"
52 :searchModule "function"})
53
54 (local expected-deprecations {
55 :compile1 "function"
56 :gensym "function"
57 :granulate "function"
58 :make_searcher "function"
59 :mangle "function"
60 :scope "function"
61 :string-stream "function"
62 :stringStream "function"
63 :unmangle "function"})
64
65 (fn supertype [expect v]
66 (let [vt (type v)]
67 (if (and (= expect :callable)
68 (or (= vt :function) (and (= vt :table)
69 (?. (getmetatable v) :__call))))
70 :callable
71 vt)))
72
73 (fn test-api-exposure []
74 (let [fennel (require :fennel) current {}]
75
76 (each [key value (pairs fennel)]
77 (tset current key (type value)))
78
79 (each [key kind (pairs expected)]
80 (t.is (. fennel key) (.. "expect fennel." key " to exists"))
81 (t.= (supertype kind (. fennel key)) kind
82 (.. "expect fennel." key " to be \"" kind "\"")))
83
84 (each [key kind (pairs expected-aliases)]
85 (t.is (. fennel key) (.. "expect alias fennel." key " to exists"))
86 (t.= (supertype kind (. fennel key)) kind
87 (.. "expect alias fennel." key " to be \"" kind "\"")))
88
89 (each [key kind (pairs expected-deprecations)]
90 (t.is (. fennel key) (.. "expect deprecated fennel." key " to exists"))
91 (t.= (supertype kind (. fennel key)) kind
92 (.. "expect deprecated fennel." key " to be \"" kind "\"")))
93
94 (each [key value (pairs fennel)]
95 (t.is (or (. expected key)
96 (. expected-aliases key)
97 (. expected-deprecations key))
98 (.. "fennel." key " not expected to be in the public api")))))
99
100 {: test-api-exposure}