Permalink
Browse files

clojure: function and vars are evaluated accurately, instead of causi…

…ng an error (#84)

* clojure: function and vars are evaluated accurately, instead of causing an error

* test: use lein doo + add tests
  • Loading branch information...
viebel committed Jul 4, 2016
1 parent 22b63c9 commit e3bce34b11e181cdd14fe055f5cba8913f481159
View
@@ -3,4 +3,4 @@ machine:
- sudo curl --output /usr/local/bin/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1
test:
override:
- lein cljsbuild once test
- lein doo phantom test once
View
@@ -1,4 +1,4 @@
(defproject klipse "1.7.0"
(defproject klipse "1.8.0"
:description "Cljs compiler in cljs"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.36"]
@@ -21,14 +21,13 @@
:clean-targets ^{:protect false} ["resources/public/dev/js"
"resources/public/plugin_prod/js"
"resources/public/plugin/js"]
:plugins [[lein-cljsbuild "1.1.1"]]
:plugins [[lein-cljsbuild "1.1.1"]
[lein-doo "0.1.6"]]
:source-paths ["src"]
:cljsbuild {
:test-commands {"unit" ["phantomjs" "test/phantom/unit-test.js" "test/phantom/unit-test.html"]}
:builds {
:test {
:source-paths ["test" "src/klipse/cards/test"]
:notify-command ["phantomjs" "test/phantom/unit-test.js" "test/phantom/unit-test.html"]
:compiler {
:output-to "resources/private/test/klipse.testable.js"
:output-dir "resources/private/test"
@@ -16,7 +16,7 @@
</div>
<div id="compiler" style="height: 100%;"></div>
<script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>
<script src="dev/js/klipse.js?version=1.7.0"></script>
<script src="dev/js/klipse.js?version=1.8.0"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@@ -11,7 +11,7 @@
<h1> clojure evaluation</h1>
<h2> The basics </h2>
<div class="clojure">
class="clojure">
(
<span>
map inc [1 2 3]
@@ -23,6 +23,20 @@ <h2> The basics </h2>
<span class="clojure"> (foo 19) </span>
<br/>
<p>
Functions should be evaluated to their code.
</p>
<span class="clojure">
(defn foo [])
[foo]
</span>
<p>
Variables should be evaluated to their names.
</p>
<span class="clojure">
(def my-var "cool")
</span>
<h2>data-eval-context </h2>
<h2>data-eval-context not set</h2>
<p> by default, the evaluation context is <b>statement</b>: it allows to evaluate several expressions. But it is sometimes buggy for single expressions. For instance, `(if 1 2 3)` is evaluated as nil: </p>
@@ -16,6 +16,7 @@
(defn error->clj [[status error]]
[status {:message (.. error -message)}])
(deftest test-eval
"eval with expected failures"
(are [input-clj message]
@@ -80,3 +81,25 @@
(are [input-clj output-clj]
(a= (remove-chars (second (eval input-clj))) output-clj)
"(type 1)" "#object[Number \"function Number() {\n [native code]\n}\"]"))
(deftest test-eval-functions
"eval with functions"
(are [input-clj output-clj]
(a= (remove-chars (second (eval input-clj))) output-clj)
"(ns my.func) (defn foo [] 1) foo" "#'my.func/foo"
"(ns my.func) (defn foo [] 2) [foo]" "[#object[my$func$foo\"functionmy$func$foo(){return(2);}\"]]"
))
(deftest test-eval-vars
"eval with vars"
(are [input-clj output-clj]
(= (second (eval input-clj)) output-clj)
"(ns my.vars) (def a 1)" "#'my.vars/a"
"(ns my.vars) (def b 1) b" "#'my.vars/b"
"(ns my.vars) (def c 1) [c]" [1]
))
View
@@ -67,7 +67,7 @@
(try
(read-string s)
(catch js/Object e
e)))
s)))
(defn convert-eval-res [{:keys [form warning error value success?]}]
(let [status (if error :error :ok)
View
@@ -5,6 +5,6 @@
(enable-console-print!)
(gadjett/settings! :max-function-calls 100)
(def version "1.7.0")
(def version "1.8.0")
(println "KLIPSE version:" version)
View
@@ -1,19 +1,10 @@
(ns test.runner
(:require
[cljs.test :as test :refer-macros [run-all-tests] :refer [report]]
[doo.runner :refer-macros [doo-tests]]
[klipse.cards.test.eval]
[klipse.cards.test.compile]
))
(enable-console-print!)
(defmethod report [::test/default :summary] [m]
(println "\nRan" (:test m) "tests containing"
(+ (:pass m) (:fail m) (:error m)) "assertions.")
(println (:fail m) "failures," (:error m) "errors.")
(aset js/window "test-failures" (+ (:fail m) (:error m))))
(defn ^:export run[]
(println "res: " (run-all-tests #"klipse.cards.test.*")))
(doo-tests 'klipse.cards.test.eval
'klipse.cards.test.compile)

0 comments on commit e3bce34

Please sign in to comment.