|
1 | 1 | (ns cljs.analyzer-tests |
2 | | - (:require [cljs.analyzer :as a]) |
| 2 | + (:require [clojure.java.io :as io] |
| 3 | + [cljs.analyzer :as a] |
| 4 | + [cljs.env :as e]) |
3 | 5 | (:use clojure.test)) |
4 | 6 |
|
5 | 7 | ;;****************************************************************************** |
|
31 | 33 |
|
32 | 34 | (deftest all-warn |
33 | 35 | (is (every? #(= 1 %) (map (fn [[name form]] (a/all-warn (warn-count form))) warning-forms)))) |
| 36 | + |
| 37 | +;; ============================================================================= |
| 38 | +;; Inference tests |
| 39 | + |
| 40 | +(def test-cenv (atom {})) |
| 41 | +(def test-env (assoc-in (a/empty-env) [:ns :name] 'cljs.core)) |
| 42 | + |
| 43 | +(e/with-compiler-env test-cenv |
| 44 | + (a/analyze-file (io/file "src/cljs/cljs/core.cljs"))) |
| 45 | + |
| 46 | +(deftest basic-inference |
| 47 | + (is (= (e/with-compiler-env test-cenv |
| 48 | + (:tag (a/analyze test-env '1))) |
| 49 | + 'number)) |
| 50 | + (is (= (e/with-compiler-env test-cenv |
| 51 | + (:tag (a/analyze test-env '"foo"))) |
| 52 | + 'string)) |
| 53 | + (is (= (e/with-compiler-env test-cenv |
| 54 | + (:tag (a/analyze test-env '(make-array 10)))) |
| 55 | + 'array)) |
| 56 | + (is (= (e/with-compiler-env test-cenv |
| 57 | + (:tag (a/analyze test-env '(js-obj)))) |
| 58 | + 'object)) |
| 59 | + (is (= (e/with-compiler-env test-cenv |
| 60 | + (:tag (a/analyze test-env '[]))) |
| 61 | + 'cljs.core/IVector)) |
| 62 | + (is (= (e/with-compiler-env test-cenv |
| 63 | + (:tag (a/analyze test-env '{}))) |
| 64 | + 'cljs.core/IMap)) |
| 65 | + (is (= (e/with-compiler-env test-cenv |
| 66 | + (:tag (a/analyze test-env '#{}))) |
| 67 | + 'cljs.core/ISet)) |
| 68 | + (is (= (e/with-compiler-env test-cenv |
| 69 | + (:tag (a/analyze test-env ()))) |
| 70 | + 'cljs.core/IList)) |
| 71 | + (is (= (e/with-compiler-env test-cenv |
| 72 | + (:tag (a/analyze test-env '(fn [x] x)))) |
| 73 | + 'function))) |
| 74 | + |
| 75 | +(deftest if-inference |
| 76 | + (is (= (e/with-compiler-env test-cenv |
| 77 | + (:tag (a/analyze test-env '(if true "foo" 1)))) |
| 78 | + '#{number string}))) |
| 79 | + |
| 80 | +(deftest lib-inference |
| 81 | + (is (= (e/with-compiler-env test-cenv |
| 82 | + (:tag (a/analyze test-env '(-conj [] 1)))) |
| 83 | + 'clj)) |
| 84 | + (is (= (e/with-compiler-env test-cenv |
| 85 | + (:tag (a/analyze test-env '(conj [] 1)))) |
| 86 | + 'clj)) |
| 87 | + (is (= (e/with-compiler-env test-cenv |
| 88 | + (:tag (a/analyze test-env '(assoc nil :foo :bar)))) |
| 89 | + 'clj)) |
| 90 | + (is (= (e/with-compiler-env test-cenv |
| 91 | + (:tag (a/analyze test-env '(dissoc {:foo :bar} :foo)))) |
| 92 | + 'clj))) |
0 commit comments