Skip to content
Browse files

Merge branch 'master' into multi-methods

Conflicts:
	src/cljs/cljs/core.cljs
  • Loading branch information...
2 parents 1223530 + e083947 commit abc53d9eef77a45abff3f5f3b208549cddd72c21 @ffailla ffailla committed Jul 29, 2011
View
13 devnotes/bcrepl.org
@@ -0,0 +1,13 @@
+* ClojureScript browser connected REPL
+** send cljs compiler output to the browser to be evaluated
+** send results back to the command line process to be printed
+** side effects happen in the browser
+** abstract communication away using goog library
+*** Goog abstraction for websockets? Ideal!
+*** Polling? It will work everywhere.
+*** Ideally an abstraction over both that prefers websockets but doesn't fail and doesn't complain loudly.
+** evaluation daemon for the browser
+** launch browser
+** transparent update of bound symbols? We should test.
+** brepl has its own solution for deps, we'd like to tie into the ClojureScript dependency story
+** require mechanisms are out; the source that forms the repl's environment will need to be updated and the page reloaded
View
13 devnotes/testing
@@ -0,0 +1,13 @@
+Definitely a work-in-progress.
+
+To run tests before you commit:
+
+ script/test
+
+To add tests:
+
+ * Create test fiels in the test/cljs directory.
+ * Write fns that throw an exception on failure.
+ * Call those fns from test/cljs/cljs/test_runner.cljs
+
+
View
2 script/repl
@@ -1,3 +1,3 @@
#!/bin/sh
-java -server -Xmx2G -Xms2G -Xmn256m -cp 'lib/*:src/clj:src/cljs' clojure.main
+java -server -Xmx2G -Xms2G -Xmn256m -cp 'lib/*:src/clj:src/cljs:test/cljs' clojure.main
View
2 script/repljs
@@ -1,5 +1,5 @@
#!/bin/sh
-java -server -Xmx2G -Xms2G -Xmn256m -cp 'lib/*:src/clj:src/cljs' clojure.main -e \
+java -server -Xmx2G -Xms2G -Xmn256m -cp 'lib/*:src/clj:src/cljs:test/cljs' clojure.main -e \
"(require '[cljs.compiler :as comp])
(def jse (comp/repl-env))
(comp/repl jse)"
View
14 script/test
@@ -0,0 +1,14 @@
+mkdir -p out
+
+bin/cljsc test > out/core-test.js
+bin/cljsc test {:optimizations :advanced} > out/core-advanced-test.js
+
+if [ "$V8_HOME" == "" ]; then
+ echo "V8_HOME not set, skipping V8 tests"
+else
+ ${V8_HOME}/d8 out/core-advanced-test.js
+ # TODO: figure out path problem when not in advanced mode
+ # ${V8_HOME}/d8 out/core-test.js
+fi
+
+# TODO : run tests with rhino if available
View
4 src/clj/cljs/compiler.clj
@@ -341,12 +341,12 @@ goog.require = function(rule){Packages.clojure.lang.RT[\"var\"](\"cljs.compiler\
(print arglist)
(dotimes [_ (- (count params) 2)] (print ")"))
(println ");")
- (println (str "return " delegate-name ".call(" (string/join ", " (cons "null" params)) ");")))
+ (println (str "return " delegate-name ".call(" (string/join ", " (cons "this" params)) ");")))
(do
(print (str "var " (last params) " = "))
(print "cljs.core.seq(" arglist ");")
(println ";")
- (println (str "return " delegate-name ".call(" (string/join ", " (cons "null" params)) ");"))))
+ (println (str "return " delegate-name ".call(" (string/join ", " (cons "this" params)) ");"))))
(print "})")))
(defn emit-fn-method
View
667 src/cljs/cljs/core.cljs
@@ -1139,8 +1139,17 @@ reduces them without incurring seq initialization"
;;hrm
(set! js/String.prototype.call
(fn
- ([_ coll] (get coll (js* "this.toString()")))
- ([_ coll not-found] (get coll (js* "this.toString()") not-found))))
+ ([_ coll]
+ (get coll (js* "this.toString()")))
+ ([_ coll not-found]
+ (get coll (js* "this.toString()") not-found))))
+
+(set! js/String.prototype.apply
+ (fn
+ [_ args]
+ (if (< (count args) 2)
+ (.call (js* "this") nil (aget args 0))
+ (.call (js* "this") nil (aget args 0) (aget args 1)))))
; could use reify
;;; LazySeq ;;;
@@ -2337,6 +2346,18 @@ reduces them without incurring seq initialization"
(when (pred (first s))
(cons (first s) (take-while pred (rest s)))))))
+(defn range
+ "Returns a lazy seq of nums from start (inclusive) to end
+ (exclusive), by step, where start defaults to 0, step to 1, and end
+ to infinity."
+ ([] (iterate inc 0))
+ ([end] (range 0 end 1))
+ ([start end] (range start end 1))
+ ([start end step]
+ (take-while
+ (fn [n] (< n end))
+ (iterate (fn [x] (+ x step)) start))))
+
(defn take-nth
"Returns a lazy seq of every nth item in coll."
[n coll]
@@ -2882,612 +2903,6 @@ reduces them without incurring seq initialization"
(assoc ret k (conj (get ret k []) x))))
{} coll))
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Tests ;;;;;;;;;;;;;;;;
-(declare test-multimethods)
-
-(defn ^{:export true} test-stuff []
- (assert (= [4 3 2 1 0] (loop [i 0 j ()]
- (if (< i 5)
- (recur (inc i) (conj j (fn [] i)))
- (map #(%) j)))))
-
- (assert (= [[1 1] [1 2] [1 3] [2 1] [2 2] [2 3]]
- (map #(%) (for [i [1 2] j [1 2 3]] (fn [] [i j])))))
-
- (assert (= 2 (:b {:a 1 :b 2})))
- (assert (= 2 ('b '{:a 1 b 2})))
- (assert (= 2 ({:a 1 :b 2} :b)))
- (assert (= 2 ({1 1 2 2} 2)))
- (assert (= 2 (#{1 2 3} 2)))
-
- (assert (= "baz" (name 'foo/bar/baz)))
- (assert (= "foo/bar" (namespace 'foo/bar/baz)))
- (assert (= "baz" (name :foo/bar/baz)))
- ;(assert (= "foo/bar" (namespace :foo/bar/baz)))
-
- (assert (= {:a :b} (get {[1 2 3] {:a :b}, 4 5} [1 2 3])))
- (assert (= :a (nth [:a :b :c :d] 0)))
- (assert (not (= {:a :b :c nil} {:a :b :d nil})))
- (assert (= (list 3 2 1) [3 2 1]))
- (assert (= [3 2 1] (seq (array 3 2 1))))
- (assert (= () (rest nil)))
- (assert (= () (rest [1])))
- (assert (= () (rest (array 1))))
- (assert (= {"x" "y"} (meta ^{"x" "y"} [])))
- (assert (= {:a :b} (dissoc {:a :b :c :d} :c)))
- (assert (= (hash-map :foo 5)
- (assoc (cljs.core.ObjMap. nil (array) (js-obj)) :foo 5)))
-
- (assert (= "[1 true {:a 2, :b 42} #<Array [3, 4]>]"
- (pr-str [1 true {:a 2 :b 42} (array 3 4)])))
-
- ;;this fails in v8 - why?
- ;(assert (= "symbol\"'string" (pr-str (str 'symbol \" \' "string"))))
-
- (assert (not (= "one" "two")))
- (assert (= 3 (-count "abc")))
- (assert (= 4 (-count (array 1 2 3 4))))
- (assert (= "c" (-nth "abc" 2)))
- (assert (= "quux" (-nth "abc" 3 "quux")))
- (assert (= 1 (-nth (array 1 2 3 4) 0)))
- (assert (= "val" (-nth (array 1 2 3 4) 4 "val")))
- (assert (= "b" (-lookup "abc" 1)))
- (assert (= "harriet" (-lookup "abcd" 4 "harriet")))
- (assert (= 4 (-lookup (array 1 2 3 4) 3)))
- (assert (= "zot" (-lookup (array 1 2 3 4) 4 "zot")))
- (assert (= 10 (-reduce (array 1 2 3 4) +)))
- (assert (= 20 (-reduce (array 1 2 3 4) + 10)))
- (assert (= "cabd" (let
- [jumble (fn [a b] (str (apply str (reverse (str a))) b))]
- (-reduce "abcd" jumble))))
- (assert (= "cafrogbd" (let
- [jumble (fn [a b] (str (apply str (reverse (str a))) b))]
- (-reduce "abcd" jumble "frog"))))
- (assert (= [0 0 1 0 1]
- [(bit-and 1 0)
- (bit-and 0 0)
- (bit-and 1 1)
- (bit-and 42 1)
- (bit-and 41 1)]))
- (assert (= [1 0 1 43 41]
- [(bit-or 1 0)
- (bit-or 0 0)
- (bit-or 1 1)
- (bit-or 42 1)
- (bit-or 41 1)]))
- (assert (= [1 0 0 42 40]
- [(bit-and-not 1 0)
- (bit-and-not 0 0)
- (bit-and-not 1 1)
- (bit-and-not 42 1)
- (bit-and-not 41 1)]))
- (assert (= [0 2 968 16649 0]
- [(bit-clear 1 0)
- (bit-clear 2 0)
- (bit-clear 1000 5)
- (bit-clear 16713 6)
- (bit-clear 1024 10)]))
- (assert (= [0 0 992 18761 0]
- [(bit-flip 1 0)
- (bit-flip 2 1)
- (bit-flip 1000 3)
- (bit-flip 16713 11)
- (bit-flip 1024 10)]))
- (assert (= [-2 -3 999 -16714 -1025]
- [(bit-not 1)
- (bit-not 2)
- (bit-not -1000)
- (bit-not 16713)
- (bit-not 1024)]))
- (assert (= [1 2 1000 18761 1024]
- [(bit-set 1 0)
- (bit-set 2 1)
- (bit-set 1000 3)
- (bit-set 16713 11)
- (bit-set 1024 10)]))
- (assert (= [true true true false true]
- [(bit-test 1 0)
- (bit-test 2 1)
- (bit-test 1000 3)
- (bit-test 16713 11)
- (bit-test 1024 10)]))
- (assert (= [true false true false false false]
- [(true? true)
- (true? false)
- (false? false)
- (false? true)
- (true? js/undefined)
- (false? js/undefined)]))
- ;; apply
- (assert (= 0 (apply + nil)))
- (assert (= 0 (apply + (list))))
- (assert (= 1 (apply + (list 1))))
- (assert (= 3 (apply + 1 (list 2))))
- (assert (= 7 (apply + 1 2 (list 4))))
- (assert (= 15 (apply + 1 2 4 (list 8))))
- (assert (= 31 (apply + 1 2 4 8 (list 16))))
- (assert (= 63 (apply + 1 2 4 8 16 (list 32))))
- (assert (= 127 (apply + 1 2 4 8 16 (list 32 64))))
- (assert (= 4950 (apply + (take 100 (iterate inc 0)))))
- (assert (= () (apply list [])))
- (assert (= [1 2 3] (apply list [1 2 3])))
- (assert (= 6 (apply apply [+ [1 2 3]])))
- ;; apply with infinite sequence
- (assert (= 3 (apply (fn [& args]
- (+ (nth args 0)
- (nth args 1)
- (nth args 2)))
- (iterate inc 0))))
- (assert (= [0 1 2 3 4] (take 5 (apply (fn [& m] m) (iterate inc 0)))))
- (assert (= [1 2 3 4 5] (take 5 (apply (fn [x & m] m) (iterate inc 0)))))
- (assert (= [2 3 4 5 6] (take 5 (apply (fn [x y & m] m) (iterate inc 0)))))
- (assert (= [3 4 5 6 7] (take 5 (apply (fn [x y z & m] m) (iterate inc 0)))))
- (assert (= [4 5 6 7 8] (take 5 (apply (fn [x y z a & m] m) (iterate inc 0)))))
- (assert (= [5 6 7 8 9] (take 5 (apply (fn [x y z a b & m] m) (iterate inc 0)))))
- ;; apply arity tests
- (let [single-arity-non-variadic (fn [x y z] [z y x])
- multiple-arity-non-variadic (fn ([x] x) ([x y] [y x]) ([x y z] [z y x]))
- single-arity-variadic-fixedargs (fn [x y & more] [more y x])
- single-arity-variadic-nofixedargs (fn [& more] more)
- multiple-arity-variadic (fn ([x] x) ([x y] [y x]) ([x y & more] [more y x]))]
- (assert (= [3 2 1] (apply single-arity-non-variadic [1 2 3])))
- (assert (= [3 2 1] (apply single-arity-non-variadic 1 [2 3])))
- (assert (= [3 2 1] (apply single-arity-non-variadic 1 2 [3])))
- (assert (= 42 (apply multiple-arity-non-variadic [42])))
- (assert (= [2 1] (apply multiple-arity-non-variadic [1 2])))
- (assert (= [2 1] (apply multiple-arity-non-variadic 1 [2])))
- (assert (= [3 2 1] (apply multiple-arity-non-variadic [1 2 3])))
- (assert (= [3 2 1] (apply multiple-arity-non-variadic 1 [2 3])))
- (assert (= [3 2 1] (apply multiple-arity-non-variadic 1 2 [3])))
- (assert (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs [1 2 3 4 5])))
- (assert (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 [2 3 4 5])))
- (assert (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 2 [3 4 5])))
- (assert (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 2 3 [4 5])))
- (assert (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 2 3 4 [5])))
- (assert (= [3 4 5] (take 3 (first (apply single-arity-variadic-fixedargs (iterate inc 1))))))
- (assert (= [2 1] (rest (apply single-arity-variadic-fixedargs (iterate inc 1)))))
- (assert (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs [1 2 3 4 5])))
- (assert (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 [2 3 4 5])))
- (assert (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 2 [3 4 5])))
- (assert (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 2 3 [4 5])))
- (assert (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 2 3 4 [5])))
- (assert (= [1 2 3 4 5] (take 5 (apply single-arity-variadic-nofixedargs (iterate inc 1)))))
- (assert (= 42 (apply multiple-arity-variadic [42])))
- (assert (= [2 1] (apply multiple-arity-variadic [1 2])))
- (assert (= [2 1] (apply multiple-arity-variadic 1 [2])))
- (assert (= [[3 4 5] 2 1] (apply multiple-arity-variadic [1 2 3 4 5])))
- (assert (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 [2 3 4 5])))
- (assert (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 2 [3 4 5])))
- (assert (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 2 3 [4 5])))
- (assert (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 2 3 4 [5])))
- (assert (= [3 4 5] (take 3 (first (apply multiple-arity-variadic (iterate inc 1))))))
- (assert (= [2 1] (rest (apply multiple-arity-variadic (iterate inc 1))))))
- (let [a (atom 0)]
- (assert (= 0 (deref a)))
- (assert (= 1 (swap! a inc)))
- (assert (= false (compare-and-set! a 0 42)))
- (assert (= true (compare-and-set! a 1 7)))
- (assert (nil? (meta a)))
- (assert (nil? (get-validator a))))
- (let [a (atom 0)]
- (assert (= 1 (swap! a + 1)))
- (assert (= 4 (swap! a + 1 2)))
- (assert (= 10 (swap! a + 1 2 3)))
- (assert (= 20 (swap! a + 1 2 3 4))))
- (let [a (atom [1] :validator coll? :meta {:a 1})]
- (assert (= coll? (get-validator a)))
- (assert (= {:a 1} (meta a)))
- (alter-meta! a assoc :b 2)
- (assert (= {:a 1 :b 2} (meta a))))
- (assert (nil? (empty nil)))
- (let [e-lazy-seq (empty (with-meta (lazy-seq (cons :a nil)) {:b :c}))]
- (assert (seq? e-lazy-seq))
- (assert (empty? e-lazy-seq))
- (assert (= {:b :c} (meta e-lazy-seq))))
- (let [e-list (empty '^{:b :c} (1 2 3))]
- (assert (seq? e-list))
- (assert (empty? e-list)))
- (let [e-elist (empty '^{:b :c} ())]
- (assert (seq? e-elist))
- (assert (empty? e-elist))
- (assert (= :c (get (meta e-elist) :b))))
- (let [e-cons (empty (with-meta (cons :a nil) {:b :c}))]
- (assert (seq? e-cons))
- (assert (empty? e-cons))
- (assert (= {:b :c} (meta e-cons))))
- (let [e-vec (empty ^{:b :c} [:a :d :g])]
- (assert (vector? e-vec))
- (assert (empty? e-vec))
- (assert (= {:b :c} (meta e-vec))))
- (let [e-omap (empty ^{:b :c} {:a :d :g :h})]
- (assert (map? e-omap))
- (assert (empty? e-omap))
- (assert (= {:b :c} (meta e-omap))))
- (let [e-hmap (empty ^{:b :c} {[1 2] :d :g :h})]
- (assert (map? e-hmap))
- (assert (empty? e-hmap))
- (assert (= {:b :c} (meta e-hmap))))
-
- ;;this fails in v8 advanced mode - what's e?
- #_(let [a (atom nil)]
- (assert (= 1 (try* 1)))
- (assert (= 2 (try* 1 (throw 3) (catch e 2))))
- (assert (= 3 (try* 1 (throw 3) (catch e e))))
- (assert (= 1 (try* 1 (finally (reset! a 42)))))
- (assert (= 42 (deref a))))
-
- (let [a (atom nil)]
- (assert (= 1 (try 1)))
- (assert (= 2 (try 1 (throw (js/Error.)) (catch js/Error e 2))))
- (assert (= 2 (try 1 (throw (js/Error.)) (catch js/Error e 1 2))))
- (assert (= 1 (try 1 (finally (reset! a 42)))))
- (assert (= 42 (deref a))))
-
- (assert (= [3] (nthnext [1 2 3] 2)))
- (let [v [1 2 3]]
- (assert (= v (for [e v] e)))
- (assert (= [[1 1] [2 4] [3 9]] (for [e v :let [m (* e e)]] [e m])))
- (assert (= [1 2] (for [e v :while (< e 3)] e)))
- (assert (= [3] (for [e v :when (> e 2)] e)))
- (assert (= [[1 1] [2 4]] (for [e v :while (< e 3) :let [m (* e e)]] [e m]))))
- (assert (not= 1 2))
- (assert (not (not= 1 1)))
- (assert (not (not-empty [])))
- (assert (boolean (not-empty [1 2 3])))
- (assert (= "joel" (min-key count "joel" "tom servo" "crooooooooow")))
- (assert (= "crooooooooow" (max-key count "joel" "tom servo" "crooooooooow")))
- (assert (= (partition-all 4 [1 2 3 4 5 6 7 8 9])
- [[1 2 3 4] [5 6 7 8] [9]]))
- (assert (= (partition-all 4 2 [1 2 3 4 5 6 7 8 9])
- [[1 2 3 4] [3 4 5 6] [5 6 7 8] [7 8 9] [9]]))
- (assert (= [true true] (take-while true? [true true 2 3 4])))
- (assert (= [[true true] [false false false] [true true]]
- (partition-by true? [true true false false false true true])))
- (assert (= [0 2 4 6 8 10] (take-nth 2 [0 1 2 3 4 5 6 7 8 9 10])))
- (let [a10 (partial + 10)
- a20 (partial + 10 10)
- a21 (partial + 10 10 1)
- a22 (partial + 10 5 4 3)
- a23 (partial + 10 5 4 3 1)]
- (assert (= 110 (a10 100)))
- (assert (= 120 (a20 100)))
- (assert (= 121 (a21 100)))
- (assert (= 122 (a22 100)))
- (assert (= 123 (a23 100))))
- (let [n2 (comp first rest)
- n3 (comp first rest rest)
- n4 (comp first rest rest rest)
- n5 (comp first rest rest rest rest)
- n6 (comp first rest rest rest rest rest)]
- (assert (= 2 (n2 [1 2 3 4 5 6 7])))
- (assert (= 3 (n3 [1 2 3 4 5 6 7])))
- (assert (= 4 (n4 [1 2 3 4 5 6 7])))
- (assert (= 5 (n5 [1 2 3 4 5 6 7])))
- (assert (= 6 (n6 [1 2 3 4 5 6 7]))))
- (let [sf (some-fn number? keyword? symbol?)]
- (assert (sf :foo 1))
- (assert (sf :foo))
- (assert (sf 'bar 1))
- (assert (not (sf [] ()))))
- (let [ep (every-pred number? zero?)]
- (assert (ep 0 0 0))
- (assert (not (ep 1 2 3 0))))
- (assert ((complement number?) :foo))
- (assert (= [1 [2 3] [1 2 3]] ((juxt first rest seq) [1 2 3])))
- (assert (= 5 (max 1 2 3 4 5)))
- (assert (= 5.5 (max 1 2 3 4 5 5.5)))
- (assert (= 1 (min 5 4 3 2 1)))
- (assert (= 0.5 (min 5 4 3 0.5 2 1)))
- (let [x (array 1 2 3)]
- (set! (.foo x) :hello)
- (assert (= (.foo x) :hello)))
-
- (assert (set []))
- (assert (= #{} (set [])))
-
- (assert (= #{"foo"} (set ["foo"])))
- (assert (= #{1 2 3} #{1 3 2}))
- (assert (= #{#{1 2 3} [4 5 6] {7 8} 9 10}
- #{10 9 [4 5 6] {7 8} #{1 2 3}}))
- (assert (not (= #{nil [] {} 0 #{}} #{})))
- (assert (= (count #{nil [] {} 0 #{}}) 5))
- (assert (= (conj #{1} 1) #{1}))
- (assert (= (conj #{1} 2) #{2 1}))
- (assert (= #{} (-empty #{1 2 3 4})))
- (assert (= (reduce + #{1 2 3 4 5}) 15))
- (assert (= 4 (get #{1 2 3 4} 4)))
- (assert (contains? #{1 2 3 4} 4))
- (assert (contains? #{[] nil 0 {} #{}} {}))
- (assert (contains? #{[1 2 3]} [1 2 3]))
- (assert (not (contains? (-disjoin #{1 2 3} 3) 3)))
- (assert (neg? -1))
- (assert (not (neg? 1)))
- (assert (neg? -1.765))
- (assert (not (neg? 0)))
- (assert (= [true false true false true false true false]
- (map integer?
- [1 1.00001 0x7e7 [] (- 88 1001991881) :foo 0 "0"])))
- (assert (= [true false true false true false]
- (map odd? [1 2 3 4 -1 0])))
- (assert (= [true false true false true true]
- (map even? [2 3 4 5 -2 0])))
- (assert (contains? {:a 1 :b 2} :a))
- (assert (not (contains? {:a 1 :b 2} :z)))
- (assert (contains? [5 6 7] 1))
- (assert (contains? [5 6 7] 2))
- (assert (not (contains? [5 6 7] 3)))
- (assert (contains? (to-array [5 6 7]) 1))
- (assert (contains? (to-array [5 6 7]) 2))
- (assert (not (contains? (to-array [5 6 7]) 3)))
- (assert (not (contains? nil 42)))
- (assert (contains? "f" 0))
- (assert (not (contains? "f" 55)))
- (assert (distinct? 1 2 3))
- (assert (not (distinct? 1 2 3 1)))
-
- ;; distinct
- (assert (= (distinct ()) ()))
- (assert (= (distinct '(1)) '(1)))
- (assert (= (distinct '(1 2 3 1 1 1)) '(1 2 3)))
- (assert (= (distinct [1 1 1 2]) '(1 2)))
- (assert (= (distinct [1 2 1 2]) '(1 2)))
- (assert (= (distinct "a") ["a"]))
- (assert (= (distinct "abcabab") ["a" "b" "c"]))
- (assert (= (distinct ["abc" "abc"]) ["abc"]))
- (assert (= (distinct [nil nil]) [nil]))
- (assert (= (distinct [0.0 0.0]) [0.0]))
- (assert (= (distinct ['sym 'sym]) '[sym]))
- (assert (= (distinct [:kw :kw]) [:kw]))
- (assert (= (distinct [42 42]) [42]))
- (assert (= (distinct [[] []]) [[]]))
- (assert (= (distinct ['(1 2) '(1 2)]) '[(1 2)]))
- (assert (= (distinct [() ()]) [()]))
- (assert (= (distinct [[1 2] [1 2]]) [[1 2]]))
- (assert (= (distinct [{:a 1 :b 2} {:a 1 :b 2}]) [{:a 1 :b 2}]))
- (assert (= (distinct [{} {}]) [{}]))
- (assert (= (distinct [#{1 2} #{1 2}]) [#{1 2}]))
- (assert (= (distinct [#{} #{}]) [#{}]))
-
- ;regexps
- ;;these fail in v8 - why?
- ;(assert (= (str (re-pattern "f(.)o")) (str (js* "/f(.)o/"))))
- ;(assert (= (re-find (re-pattern "foo") "foo bar foo baz foo zot") "foo"))
- ;(assert (= (re-find (re-pattern "f(.)o") "foo bar foo baz foo zot") ["foo" "o"]))
- ;(assert (= (re-matches (re-pattern "foo") "foo") "foo"))
- ;(assert (= (re-matches (re-pattern "foo") "foo bar foo baz foo zot") nil))
- ;(assert (= (re-matches (re-pattern "foo.*") "foo bar foo baz foo zot") "foo bar foo baz foo zot"))
- ;(assert (= (re-seq (re-pattern "foo") "foo bar foo baz foo zot") (list "foo" "foo" "foo")))
- ;(assert (= (re-seq (re-pattern "f(.)o") "foo bar foo baz foo zot") (list ["foo" "o"] ["foo" "o"] ["foo" "o"])))
-
- ;; destructuring
- (assert (= [2 1] (let [[a b] [1 2]] [b a])))
- (assert (= #{1 2} (let [[a b] [1 2]] #{a b})))
- (assert (= [1 2] (let [{a :a b :b} {:a 1 :b 2}] [a b])))
- (assert (= [1 2] (let [{:keys [a b]} {:a 1 :b 2}] [a b])))
- (assert (= [1 2 [1 2]] (let [[a b :as v] [1 2]] [a b v])))
- (assert (= [1 42] (let [{:keys [a b] :or {b 42}} {:a 1}] [a b])))
- (assert (= [1 nil] (let [{:keys [a b] :or {c 42}} {:a 1}] [a b])))
- (assert (= [2 1] (let [[a b] '(1 2)] [b a])))
- (assert (= {1 2} (let [[a b] [1 2]] {a b})))
- (assert (= [2 1] (let [[a b] (seq [1 2])] [b a])))
-
- ;; update-in
- (assert (= {:foo {:bar {:baz 1}}}
- (update-in {:foo {:bar {:baz 0}}} [:foo :bar :baz] inc)))
- (assert (= {:foo 1 :bar 2 :baz 10}
- (update-in {:foo 1 :bar 2 :baz 3} [:baz] + 7)))
- (assert (= [{:foo 1, :bar 2} {:foo 1, :bar 3}]
- (update-in [{:foo 1 :bar 2}, {:foo 1 :bar 2}] [1 :bar] inc)))
- (assert (= [{:foo {:bar 2}} {:foo {:bar 3}}]
- (update-in [{:foo {:bar 2}}, {:foo {:bar 2}}] [1 :foo :bar] inc)))
-
- ;; assoc-in
- (assert (= {:foo {:bar {:baz 100}}}
- (assoc-in {:foo {:bar {:baz 0}}} [:foo :bar :baz] 100)))
- (assert (= {:foo 1 :bar 2 :baz 100}
- (assoc-in {:foo 1 :bar 2 :baz 3} [:baz] 100)))
- (assert (= [{:foo [{:bar 2} {:baz 3}]} {:foo [{:bar 2} {:baz 100}]}]
- (assoc-in [{:foo [{:bar 2} {:baz 3}]}, {:foo [{:bar 2} {:baz 3}]}]
- [1 :foo 1 :baz] 100)))
- (assert (= [{:foo 1, :bar 2} {:foo 1, :bar 100}]
- (assoc-in [{:foo 1 :bar 2}, {:foo 1 :bar 2}] [1 :bar] 100)))
-
- ;; get-in
- (assert (= 1 (get-in {:foo 1 :bar 2} [:foo])))
- (assert (= 2 (get-in {:foo {:bar 2}} [:foo :bar])))
- (assert (= 1 (get-in [{:foo 1}, {:foo 2}] [0 :foo])))
- (assert (= 4 (get-in [{:foo 1 :bar [{:baz 1}, {:buzz 2}]}, {:foo 3 :bar [{:baz 3}, {:buzz 4}]}]
- [1 :bar 1 :buzz])))
-
- ;; arrays
- (let [a (to-array [1 2 3])]
- (assert (= [10 20 30] (seq (amap a i ret (* 10 (aget a i))))))
- (assert (= 6 (areduce a i ret 0 (+ ret (aget a i)))))
- (assert (= (seq a) (seq (to-array [1 2 3]))))
- (assert (= 42 (aset a 0 42)))
- (assert (not= (seq a) (seq (to-array [1 2 3]))))
- (assert (not= a (aclone a))))
-
- ;; sort
- (assert (= [1 2 3 4 5] (sort [5 3 1 4 2])))
- (assert (= [1 2 3 4 5] (sort < [5 3 1 4 2])))
- (assert (= [5 4 3 2 1] (sort > [5 3 1 4 2])))
-
- ;; sort-by
- (assert (= ["a" [ 1 2] "foo"] (sort-by count ["foo" "a" [1 2]])))
- (assert (= ["foo" [1 2] "a"] (sort-by count > ["foo" "a" [1 2]])))
-
- ;; js->clj
- (assert (= {"a" 1, "b" 2} (js->clj (js* "{\"a\":1,\"b\":2}"))))
- (assert (= {:a 1, :b 2} (js->clj (js* "{\"a\":1,\"b\":2}") :keywordize-keys true)))
- (assert (= [[{:a 1, :b 2} {:a 1, :b 2}]]
- (js->clj (js* "[[{\"a\":1,\"b\":2}, {\"a\":1,\"b\":2}]]") :keywordize-keys true)))
- (assert (= [[{:a 1, :b 2} {:a 1, :b 2}]]
- (js->clj [[{:a 1, :b 2} {:a 1, :b 2}]])))
-
- ;; last
- (assert (= nil (last nil)))
- (assert (= 3 (last [1 2 3])))
-
- ;; dotimes
- (let [s (atom [])]
- (dotimes [n 5]
- (swap! s conj n))
- (assert (= [0 1 2 3 4] @s)))
-
- ;; doseq
- (let [v [1 2 3 4 5]
- s (atom ())]
- (doseq [n v] (swap! s conj n))
- (assert (= @s (reverse v))))
-
- ;; delay
- ;; (let [d (delay (. (js/Date.) (getTime)))]
- ;; (assert (false? (realized? d)))
- ;; (let [d2 (. (js/Date.) (getTime))]
- ;; (assert (> d2 (deref d))))
- ;; (assert (true? (realized? d)))
- ;; (let [d3 (deref d)]
- ;; (assert (= (deref d) d3))))
-
- ;; assoc
- (assert (= {1 2 3 4} (assoc {} 1 2 3 4)))
- (assert (= {1 2} (assoc {} 1 2)))
- (assert (= [42 2] (assoc [1 2] 0 42)))
-
- ;; dissoc
- (assert (= {} (dissoc {1 2 3 4} 1 3)))
- (assert (= {1 2} (dissoc {1 2 3 4} 3)))
-
- ;; disj
- (assert (= #{1 2 3} (disj #{1 2 3})))
- (assert (= #{1 2} (disj #{1 2 3} 3)))
- (assert (= #{1} (disj #{1 2 3} 2 3)))
-
- ;; memoize
- (let [f (memoize (fn [] (rand)))]
- (f)
- (assert (= (f) (f))))
-
- ;; find
- (assert (= (find {} :a) nil))
- (assert (= (find {:a 1} :a) [:a 1]))
- (assert (= (find {:a 1} :b) nil))
- (assert (= (find {:a 1 :b 2} :a) [:a 1]))
- (assert (= (find {:a 1 :b 2} :b) [:b 2]))
- (assert (= (find {:a 1 :b 2} :c) nil))
- (assert (= (find {} nil) nil))
- (assert (= (find {:a 1} nil) nil))
- (assert (= (find {:a 1 :b 2} nil) nil))
- (assert (= (find [1 2 3] 0) [0 1]))
-
- ;; mod,quot,rem
- (assert (= (quot 4 2) 2))
- (assert (= (quot 3 2) 1))
- (assert (= (quot 6 4) 1))
- (assert (= (quot 0 5) 0))
- (assert (= (quot 42 5) 8))
- (assert (= (quot 42 -5) -8))
- (assert (= (quot -42 -5) 8))
- (assert (= (quot 9 3) 3))
- (assert (= (quot 9 -3) -3))
- (assert (= (quot -9 3) -3))
- (assert (= (quot 2 -5) 0))
- (assert (= (quot -2 5) 0))
- (assert (= (quot 0 3) 0))
- (assert (= (quot 0 -3) 0))
-
- (assert (= (mod 4 2) 0))
- (assert (= (mod 3 2) 1))
- (assert (= (mod 6 4) 2))
- (assert (= (mod 0 5) 0))
- (assert (= (mod 4.5 2.0) 0.5))
- (assert (= (mod 42 5) 2))
- (assert (= (mod 9 3) 0))
- (assert (= (mod 9 -3) 0))
- (assert (= (mod -9 3) 0))
- (assert (= (mod -9 -3) 0))
- (assert (= (mod 0 3) 0))
- (assert (= (mod 3216478362187432 432143214) 120355456))
-
- (assert (= (rem 4 2) 0))
- (assert (= (rem 0 5) 0))
- (assert (= (rem 4.5 2.0) 0.5))
- (assert (= (rem 42 5) 2))
- (assert (= (rem 2 5) 2))
- (assert (= (rem 2 -5) 2))
- (assert (= (rem 0 3) 0))
-
- ;; group-by
- (let [d (group-by second {:a 1 :b 2 :c 1 :d 4 :e 1 :f 2})]
- (assert (= 3 (count (get d 1))))
- (assert (= 2 (count (get d 2))))
- (assert (= 1 (count (get d 4)))))
-
- (assert (= {1 2 3 4 5 6} (merge {1 2} {3 4} {5 6})))
- (assert (= {1 2 3 4} (merge {1 2} {3 4} nil)))
-
- ;; frequencies
- (assert (= {:a 3 :b 2} (frequencies [:a :b :a :b :a])))
-
- ;; reductions
- (assert (= [1 3 6 10 15] (reductions + [1 2 3 4 5])))
-
- ;; keep
- (assert (= [1 3 5 7 9] (keep #(if (odd? %) %) [1 2 3 4 5 6 7 8 9 10])))
- (assert (= [2 4 6 8 10] (keep #(if (even? %) %) [1 2 3 4 5 6 7 8 9 10])))
-
- ;; keep-indexed
- (assert (= [1 3 5 7 9] (keep-indexed #(if (odd? %1) %2) [0 1 2 3 4 5 6 7 8 9 10])))
- (assert (= [2 4 5] (keep-indexed #(if (pos? %2) %1) [-9 0 29 -7 45 3 -8])))
-
- ;; map-indexed
- (assert (= [[0 :a] [1 :b] [2 :c]] (map-indexed #(vector % %2) [:a :b :c])))
-
- ;; merge-with
- (assert (= '{"Foo" ("foo" "FOO" "fOo"), "Bar" ("bar" "BAR" "BAr"), "Baz" ["baz"], "Qux" ["qux" "quux"]}
- (merge-with concat
- {"Foo" ["foo" "FOO"]
- "Bar" ["bar" "BAR"]
- "Baz" ["baz"]}
- {"Foo" ["fOo"]
- "Bar" ["BAr"]
- "Qux" ["qux" "quux"]})))
- (assert (= {:a 111, :b 102, :c 13}
- (merge-with +
- {:a 1 :b 2 :c 3}
- {:a 10 :c 10}
- {:a 100 :b 100})))
-
- (assert (= {:a 3, :b 102, :c 13}
- (apply merge-with [+
- {:a 1 :b 100}
- {:a 1 :b 2 :c 3}
- {:a 1 :c 10}])))
-
- (assert (= '[a c e] (replace '[a b c d e] [0 2 4])))
- (assert (= [:one :zero :two :zero]
- (replace {0 :zero 1 :one 2 :two} '(1 0 2 0))))
-
- ;; split-at
- (assert (= [[1 2] [3 4 5]] (split-at 2 [1 2 3 4 5])))
-
- ;; split-with
- (assert (= [[1 2 3] [4 5]] (split-with (partial >= 3) [1 2 3 4 5])))
-
- ;; trampoline
- (assert (= 10000 (trampoline (fn f [n] (if (>= n 10000) n #(f (inc n)))) 0)))
-
- ;; vary-meta
- (assert (= {:a 1} (meta (vary-meta [] assoc :a 1))))
- (assert (= {:a 1 :b 2} (meta (vary-meta (with-meta [] {:b 2}) assoc :a 1))))
-
- (test-multimethods)
- :ok
- )
-
-#_(js/print (assoc {} :a 1))
-
;; FF multimethods
@@ -3560,9 +2975,9 @@ reduces them without incurring seq initialization"
(swap! global-hierarchy derive tag parent) nil)
([h tag parent]
(assert (not= tag parent))
- ;; (assert (or (class? tag) (instance? cljs.core.Named tag)))
- ;; (assert (instance? cljs.core.INamed tag))
- ;; (assert (instance? cljs.core.INamed parent))
+ ;; (assert (or (class? tag) (instance? clojure.lang.Named tag)))
+ ;; (assert (instance? clojure.lang.INamed tag))
+ ;; (assert (instance? clojure.lang.INamed parent))
(let [tp (:parents h)
td (:descendants h)
ta (:ancestors h)
@@ -3841,25 +3256,25 @@ reduces them without incurring seq initialization"
(assert (= :a-return (foo :a)))
(assert (= :default-return (foo 1)))
- ;; (defmulti area :Shape)
- ;; (defn rect [wd ht] {:Shape :Rect :wd wd :ht ht})
- ;; (defn circle [radius] {:Shape :Circle :radius radius})
- ;; (defmethod area :Rect [r]
- ;; (* (:wd r) (:ht r)))
- ;; (defmethod area :Circle [c]
- ;; (* Math/PI (* (:radius c) (:radius c))))
- ;; (defmethod area :default [x] :oops)
- ;; (def r (rect 4 13))
- ;; (def c (circle 12))
-
- ;; (assert (= 52 (area r)))
- ;; ;;(assert (= 452.3893421169302 (area c)))
- ;; (assert (= :oops (area {})))
+ (defmulti area :Shape)
+ (defn rect [wd ht] {:Shape :Rect :wd wd :ht ht})
+ (defn circle [radius] {:Shape :Circle :radius radius})
+ (defmethod area :Rect [r]
+ (* (:wd r) (:ht r)))
+ (defmethod area :Circle [c]
+ (* Math/PI (* (:radius c) (:radius c))))
+ (defmethod area :default [x] :oops)
+ (def r (rect 4 13))
+ (def c (circle 12))
+
+ (assert (= 52 (area r)))
+ ;;(assert (= 452.3893421169302 (area c)))
+ (assert (= :oops (area {})))
(assert (= 2 (count (methods bar))))
(remove-method bar [::rect ::shape])
(assert (= 1 (count (methods bar))))
(remove-all-methods bar)
(assert (zero? (count (methods bar))))
- )
+ )
View
18 src/cljs/cljs/reader.cljs
@@ -345,22 +345,4 @@ nil if the end of stream has been reached")
(let [r (push-back-reader s)]
(read r true nil false)))
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Tests ;;;;;;;;;;;;;;;;
-
-(defn test-reader
- []
- (assert (= 1 (read-string "1")))
- (assert (= 2 (read-string "#_nope 2")))
- (assert (= [3 4] (read-string "[3 4]")))
- (assert (= "foo" (read-string "\"foo\"")))
- (assert (= :hello (read-string ":hello")))
- (assert (= 'goodbye (read-string "goodbye")))
- (assert (= #{1 2 3} (read-string "#{1 2 3}")))
- (assert (= '(7 8 9) (read-string "(7 8 9)")))
- (assert (= '(deref foo) (read-string "@foo")))
- (assert (= '(quote bar) (read-string "'bar")))
- (assert (= \a (read-string "\\a")))
- (assert (= {:tag 'String} (meta (read-string "^String {:a 1}"))))
- (assert (= [:a 'b #{'c {:d [:e :f :g]}}]
- (read-string "[:a b #{c {:d [:e :f :g]}}]"))))
View
608 test/cljs/cljs/core_test.cljs
@@ -0,0 +1,608 @@
+(ns cljs.core-test)
+
+(defn test-stuff []
+ (assert (= [4 3 2 1 0] (loop [i 0 j ()]
+ (if (< i 5)
+ (recur (inc i) (conj j (fn [] i)))
+ (map #(%) j)))))
+
+ (assert (= [[1 1] [1 2] [1 3] [2 1] [2 2] [2 3]]
+ (map #(%) (for [i [1 2] j [1 2 3]] (fn [] [i j])))))
+
+ (assert (= 2 (:b {:a 1 :b 2})))
+ (assert (= 2 ('b '{:a 1 b 2})))
+ (assert (= 2 ({:a 1 :b 2} :b)))
+ (assert (= 2 ({1 1 2 2} 2)))
+ (assert (= 2 (#{1 2 3} 2)))
+
+ (assert (= "baz" (name 'foo/bar/baz)))
+ (assert (= "foo/bar" (namespace 'foo/bar/baz)))
+ (assert (= "baz" (name :foo/bar/baz)))
+ ;(assert (= "foo/bar" (namespace :foo/bar/baz)))
+
+ (assert (= {:a :b} (get {[1 2 3] {:a :b}, 4 5} [1 2 3])))
+ (assert (= :a (nth [:a :b :c :d] 0)))
+ (assert (not (= {:a :b :c nil} {:a :b :d nil})))
+ (assert (= (list 3 2 1) [3 2 1]))
+ (assert (= [3 2 1] (seq (array 3 2 1))))
+ (assert (= () (rest nil)))
+ (assert (= () (rest [1])))
+ (assert (= () (rest (array 1))))
+ (assert (= {"x" "y"} (meta ^{"x" "y"} [])))
+ (assert (= {:a :b} (dissoc {:a :b :c :d} :c)))
+ (assert (= (hash-map :foo 5)
+ (assoc (cljs.core.ObjMap. nil (array) (js-obj)) :foo 5)))
+
+ (assert (= "[1 true {:a 2, :b 42} #<Array [3, 4]>]"
+ (pr-str [1 true {:a 2 :b 42} (array 3 4)])))
+
+ ;;this fails in v8 - why?
+ ;(assert (= "symbol\"'string" (pr-str (str 'symbol \" \' "string"))))
+
+ (assert (not (= "one" "two")))
+ (assert (= 3 (-count "abc")))
+ (assert (= 4 (-count (array 1 2 3 4))))
+ (assert (= "c" (-nth "abc" 2)))
+ (assert (= "quux" (-nth "abc" 3 "quux")))
+ (assert (= 1 (-nth (array 1 2 3 4) 0)))
+ (assert (= "val" (-nth (array 1 2 3 4) 4 "val")))
+ (assert (= "b" (-lookup "abc" 1)))
+ (assert (= "harriet" (-lookup "abcd" 4 "harriet")))
+ (assert (= 4 (-lookup (array 1 2 3 4) 3)))
+ (assert (= "zot" (-lookup (array 1 2 3 4) 4 "zot")))
+ (assert (= 10 (-reduce (array 1 2 3 4) +)))
+ (assert (= 20 (-reduce (array 1 2 3 4) + 10)))
+ (assert (= "cabd" (let
+ [jumble (fn [a b] (str (apply str (reverse (str a))) b))]
+ (-reduce "abcd" jumble))))
+ (assert (= "cafrogbd" (let
+ [jumble (fn [a b] (str (apply str (reverse (str a))) b))]
+ (-reduce "abcd" jumble "frog"))))
+ (assert (= [0 0 1 0 1]
+ [(bit-and 1 0)
+ (bit-and 0 0)
+ (bit-and 1 1)
+ (bit-and 42 1)
+ (bit-and 41 1)]))
+ (assert (= [1 0 1 43 41]
+ [(bit-or 1 0)
+ (bit-or 0 0)
+ (bit-or 1 1)
+ (bit-or 42 1)
+ (bit-or 41 1)]))
+ (assert (= [1 0 0 42 40]
+ [(bit-and-not 1 0)
+ (bit-and-not 0 0)
+ (bit-and-not 1 1)
+ (bit-and-not 42 1)
+ (bit-and-not 41 1)]))
+ (assert (= [0 2 968 16649 0]
+ [(bit-clear 1 0)
+ (bit-clear 2 0)
+ (bit-clear 1000 5)
+ (bit-clear 16713 6)
+ (bit-clear 1024 10)]))
+ (assert (= [0 0 992 18761 0]
+ [(bit-flip 1 0)
+ (bit-flip 2 1)
+ (bit-flip 1000 3)
+ (bit-flip 16713 11)
+ (bit-flip 1024 10)]))
+ (assert (= [-2 -3 999 -16714 -1025]
+ [(bit-not 1)
+ (bit-not 2)
+ (bit-not -1000)
+ (bit-not 16713)
+ (bit-not 1024)]))
+ (assert (= [1 2 1000 18761 1024]
+ [(bit-set 1 0)
+ (bit-set 2 1)
+ (bit-set 1000 3)
+ (bit-set 16713 11)
+ (bit-set 1024 10)]))
+ (assert (= [true true true false true]
+ [(bit-test 1 0)
+ (bit-test 2 1)
+ (bit-test 1000 3)
+ (bit-test 16713 11)
+ (bit-test 1024 10)]))
+ (assert (= [true false true false false false]
+ [(true? true)
+ (true? false)
+ (false? false)
+ (false? true)
+ (true? js/undefined)
+ (false? js/undefined)]))
+ ;; apply
+ (assert (= 0 (apply + nil)))
+ (assert (= 0 (apply + (list))))
+ (assert (= 1 (apply + (list 1))))
+ (assert (= 3 (apply + 1 (list 2))))
+ (assert (= 7 (apply + 1 2 (list 4))))
+ (assert (= 15 (apply + 1 2 4 (list 8))))
+ (assert (= 31 (apply + 1 2 4 8 (list 16))))
+ (assert (= 63 (apply + 1 2 4 8 16 (list 32))))
+ (assert (= 127 (apply + 1 2 4 8 16 (list 32 64))))
+ (assert (= 4950 (apply + (take 100 (iterate inc 0)))))
+ (assert (= () (apply list [])))
+ (assert (= [1 2 3] (apply list [1 2 3])))
+ (assert (= 6 (apply apply [+ [1 2 3]])))
+ ;; apply with infinite sequence
+ (assert (= 3 (apply (fn [& args]
+ (+ (nth args 0)
+ (nth args 1)
+ (nth args 2)))
+ (iterate inc 0))))
+ (assert (= [0 1 2 3 4] (take 5 (apply (fn [& m] m) (iterate inc 0)))))
+ (assert (= [1 2 3 4 5] (take 5 (apply (fn [x & m] m) (iterate inc 0)))))
+ (assert (= [2 3 4 5 6] (take 5 (apply (fn [x y & m] m) (iterate inc 0)))))
+ (assert (= [3 4 5 6 7] (take 5 (apply (fn [x y z & m] m) (iterate inc 0)))))
+ (assert (= [4 5 6 7 8] (take 5 (apply (fn [x y z a & m] m) (iterate inc 0)))))
+ (assert (= [5 6 7 8 9] (take 5 (apply (fn [x y z a b & m] m) (iterate inc 0)))))
+ ;; apply arity tests
+ (let [single-arity-non-variadic (fn [x y z] [z y x])
+ multiple-arity-non-variadic (fn ([x] x) ([x y] [y x]) ([x y z] [z y x]))
+ single-arity-variadic-fixedargs (fn [x y & more] [more y x])
+ single-arity-variadic-nofixedargs (fn [& more] more)
+ multiple-arity-variadic (fn ([x] x) ([x y] [y x]) ([x y & more] [more y x]))]
+ (assert (= [3 2 1] (apply single-arity-non-variadic [1 2 3])))
+ (assert (= [3 2 1] (apply single-arity-non-variadic 1 [2 3])))
+ (assert (= [3 2 1] (apply single-arity-non-variadic 1 2 [3])))
+ (assert (= 42 (apply multiple-arity-non-variadic [42])))
+ (assert (= [2 1] (apply multiple-arity-non-variadic [1 2])))
+ (assert (= [2 1] (apply multiple-arity-non-variadic 1 [2])))
+ (assert (= [3 2 1] (apply multiple-arity-non-variadic [1 2 3])))
+ (assert (= [3 2 1] (apply multiple-arity-non-variadic 1 [2 3])))
+ (assert (= [3 2 1] (apply multiple-arity-non-variadic 1 2 [3])))
+ (assert (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs [1 2 3 4 5])))
+ (assert (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 [2 3 4 5])))
+ (assert (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 2 [3 4 5])))
+ (assert (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 2 3 [4 5])))
+ (assert (= [[3 4 5] 2 1] (apply single-arity-variadic-fixedargs 1 2 3 4 [5])))
+ (assert (= [3 4 5] (take 3 (first (apply single-arity-variadic-fixedargs (iterate inc 1))))))
+ (assert (= [2 1] (rest (apply single-arity-variadic-fixedargs (iterate inc 1)))))
+ (assert (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs [1 2 3 4 5])))
+ (assert (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 [2 3 4 5])))
+ (assert (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 2 [3 4 5])))
+ (assert (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 2 3 [4 5])))
+ (assert (= [1 2 3 4 5] (apply single-arity-variadic-nofixedargs 1 2 3 4 [5])))
+ (assert (= [1 2 3 4 5] (take 5 (apply single-arity-variadic-nofixedargs (iterate inc 1)))))
+ (assert (= 42 (apply multiple-arity-variadic [42])))
+ (assert (= [2 1] (apply multiple-arity-variadic [1 2])))
+ (assert (= [2 1] (apply multiple-arity-variadic 1 [2])))
+ (assert (= [[3 4 5] 2 1] (apply multiple-arity-variadic [1 2 3 4 5])))
+ (assert (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 [2 3 4 5])))
+ (assert (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 2 [3 4 5])))
+ (assert (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 2 3 [4 5])))
+ (assert (= [[3 4 5] 2 1] (apply multiple-arity-variadic 1 2 3 4 [5])))
+ (assert (= [3 4 5] (take 3 (first (apply multiple-arity-variadic (iterate inc 1))))))
+ (assert (= [2 1] (rest (apply multiple-arity-variadic (iterate inc 1))))))
+ (let [a (atom 0)]
+ (assert (= 0 (deref a)))
+ (assert (= 1 (swap! a inc)))
+ (assert (= false (compare-and-set! a 0 42)))
+ (assert (= true (compare-and-set! a 1 7)))
+ (assert (nil? (meta a)))
+ (assert (nil? (get-validator a))))
+ (let [a (atom 0)]
+ (assert (= 1 (swap! a + 1)))
+ (assert (= 4 (swap! a + 1 2)))
+ (assert (= 10 (swap! a + 1 2 3)))
+ (assert (= 20 (swap! a + 1 2 3 4))))
+ (let [a (atom [1] :validator coll? :meta {:a 1})]
+ (assert (= coll? (get-validator a)))
+ (assert (= {:a 1} (meta a)))
+ (alter-meta! a assoc :b 2)
+ (assert (= {:a 1 :b 2} (meta a))))
+ (assert (nil? (empty nil)))
+ (let [e-lazy-seq (empty (with-meta (lazy-seq (cons :a nil)) {:b :c}))]
+ (assert (seq? e-lazy-seq))
+ (assert (empty? e-lazy-seq))
+ (assert (= {:b :c} (meta e-lazy-seq))))
+ (let [e-list (empty '^{:b :c} (1 2 3))]
+ (assert (seq? e-list))
+ (assert (empty? e-list)))
+ (let [e-elist (empty '^{:b :c} ())]
+ (assert (seq? e-elist))
+ (assert (empty? e-elist))
+ (assert (= :c (get (meta e-elist) :b))))
+ (let [e-cons (empty (with-meta (cons :a nil) {:b :c}))]
+ (assert (seq? e-cons))
+ (assert (empty? e-cons))
+ (assert (= {:b :c} (meta e-cons))))
+ (let [e-vec (empty ^{:b :c} [:a :d :g])]
+ (assert (vector? e-vec))
+ (assert (empty? e-vec))
+ (assert (= {:b :c} (meta e-vec))))
+ (let [e-omap (empty ^{:b :c} {:a :d :g :h})]
+ (assert (map? e-omap))
+ (assert (empty? e-omap))
+ (assert (= {:b :c} (meta e-omap))))
+ (let [e-hmap (empty ^{:b :c} {[1 2] :d :g :h})]
+ (assert (map? e-hmap))
+ (assert (empty? e-hmap))
+ (assert (= {:b :c} (meta e-hmap))))
+
+ ;;this fails in v8 advanced mode - what's e?
+ #_(let [a (atom nil)]
+ (assert (= 1 (try* 1)))
+ (assert (= 2 (try* 1 (throw 3) (catch e 2))))
+ (assert (= 3 (try* 1 (throw 3) (catch e e))))
+ (assert (= 1 (try* 1 (finally (reset! a 42)))))
+ (assert (= 42 (deref a))))
+
+ (let [a (atom nil)]
+ (assert (= 1 (try 1)))
+ (assert (= 2 (try 1 (throw (js/Error.)) (catch js/Error e 2))))
+ (assert (= 2 (try 1 (throw (js/Error.)) (catch js/Error e 1 2))))
+ (assert (= 1 (try 1 (finally (reset! a 42)))))
+ (assert (= 42 (deref a))))
+
+ (assert (= [3] (nthnext [1 2 3] 2)))
+ (let [v [1 2 3]]
+ (assert (= v (for [e v] e)))
+ (assert (= [[1 1] [2 4] [3 9]] (for [e v :let [m (* e e)]] [e m])))
+ (assert (= [1 2] (for [e v :while (< e 3)] e)))
+ (assert (= [3] (for [e v :when (> e 2)] e)))
+ (assert (= [[1 1] [2 4]] (for [e v :while (< e 3) :let [m (* e e)]] [e m]))))
+ (assert (not= 1 2))
+ (assert (not (not= 1 1)))
+ (assert (not (not-empty [])))
+ (assert (boolean (not-empty [1 2 3])))
+ (assert (= "joel" (min-key count "joel" "tom servo" "crooooooooow")))
+ (assert (= "crooooooooow" (max-key count "joel" "tom servo" "crooooooooow")))
+ (assert (= (partition-all 4 [1 2 3 4 5 6 7 8 9])
+ [[1 2 3 4] [5 6 7 8] [9]]))
+ (assert (= (partition-all 4 2 [1 2 3 4 5 6 7 8 9])
+ [[1 2 3 4] [3 4 5 6] [5 6 7 8] [7 8 9] [9]]))
+ (assert (= [true true] (take-while true? [true true 2 3 4])))
+ (assert (= [[true true] [false false false] [true true]]
+ (partition-by true? [true true false false false true true])))
+ (assert (= [0 2 4 6 8 10] (take-nth 2 [0 1 2 3 4 5 6 7 8 9 10])))
+ (let [a10 (partial + 10)
+ a20 (partial + 10 10)
+ a21 (partial + 10 10 1)
+ a22 (partial + 10 5 4 3)
+ a23 (partial + 10 5 4 3 1)]
+ (assert (= 110 (a10 100)))
+ (assert (= 120 (a20 100)))
+ (assert (= 121 (a21 100)))
+ (assert (= 122 (a22 100)))
+ (assert (= 123 (a23 100))))
+ (let [n2 (comp first rest)
+ n3 (comp first rest rest)
+ n4 (comp first rest rest rest)
+ n5 (comp first rest rest rest rest)
+ n6 (comp first rest rest rest rest rest)]
+ (assert (= 2 (n2 [1 2 3 4 5 6 7])))
+ (assert (= 3 (n3 [1 2 3 4 5 6 7])))
+ (assert (= 4 (n4 [1 2 3 4 5 6 7])))
+ (assert (= 5 (n5 [1 2 3 4 5 6 7])))
+ (assert (= 6 (n6 [1 2 3 4 5 6 7]))))
+ (let [sf (some-fn number? keyword? symbol?)]
+ (assert (sf :foo 1))
+ (assert (sf :foo))
+ (assert (sf 'bar 1))
+ (assert (not (sf [] ()))))
+ (let [ep (every-pred number? zero?)]
+ (assert (ep 0 0 0))
+ (assert (not (ep 1 2 3 0))))
+ (assert ((complement number?) :foo))
+ (assert (= [1 [2 3] [1 2 3]] ((juxt first rest seq) [1 2 3])))
+ (assert (= 5 (max 1 2 3 4 5)))
+ (assert (= 5.5 (max 1 2 3 4 5 5.5)))
+ (assert (= 1 (min 5 4 3 2 1)))
+ (assert (= 0.5 (min 5 4 3 0.5 2 1)))
+ (let [x (array 1 2 3)]
+ (set! (.foo x) :hello)
+ (assert (= (.foo x) :hello)))
+
+ (assert (set []))
+ (assert (= #{} (set [])))
+
+ (assert (= #{"foo"} (set ["foo"])))
+ (assert (= #{1 2 3} #{1 3 2}))
+ (assert (= #{#{1 2 3} [4 5 6] {7 8} 9 10}
+ #{10 9 [4 5 6] {7 8} #{1 2 3}}))
+ (assert (not (= #{nil [] {} 0 #{}} #{})))
+ (assert (= (count #{nil [] {} 0 #{}}) 5))
+ (assert (= (conj #{1} 1) #{1}))
+ (assert (= (conj #{1} 2) #{2 1}))
+ (assert (= #{} (-empty #{1 2 3 4})))
+ (assert (= (reduce + #{1 2 3 4 5}) 15))
+ (assert (= 4 (get #{1 2 3 4} 4)))
+ (assert (contains? #{1 2 3 4} 4))
+ (assert (contains? #{[] nil 0 {} #{}} {}))
+ (assert (contains? #{[1 2 3]} [1 2 3]))
+ (assert (not (contains? (-disjoin #{1 2 3} 3) 3)))
+ (assert (neg? -1))
+ (assert (not (neg? 1)))
+ (assert (neg? -1.765))
+ (assert (not (neg? 0)))
+ (assert (= [true false true false true false true false]
+ (map integer?
+ [1 1.00001 0x7e7 [] (- 88 1001991881) :foo 0 "0"])))
+ (assert (= [true false true false true false]
+ (map odd? [1 2 3 4 -1 0])))
+ (assert (= [true false true false true true]
+ (map even? [2 3 4 5 -2 0])))
+ (assert (contains? {:a 1 :b 2} :a))
+ (assert (not (contains? {:a 1 :b 2} :z)))
+ (assert (contains? [5 6 7] 1))
+ (assert (contains? [5 6 7] 2))
+ (assert (not (contains? [5 6 7] 3)))
+ (assert (contains? (to-array [5 6 7]) 1))
+ (assert (contains? (to-array [5 6 7]) 2))
+ (assert (not (contains? (to-array [5 6 7]) 3)))
+ (assert (not (contains? nil 42)))
+ (assert (contains? "f" 0))
+ (assert (not (contains? "f" 55)))
+ (assert (distinct? 1 2 3))
+ (assert (not (distinct? 1 2 3 1)))
+
+ ;; distinct
+ (assert (= (distinct ()) ()))
+ (assert (= (distinct '(1)) '(1)))
+ (assert (= (distinct '(1 2 3 1 1 1)) '(1 2 3)))
+ (assert (= (distinct [1 1 1 2]) '(1 2)))
+ (assert (= (distinct [1 2 1 2]) '(1 2)))
+ (assert (= (distinct "a") ["a"]))
+ (assert (= (distinct "abcabab") ["a" "b" "c"]))
+ (assert (= (distinct ["abc" "abc"]) ["abc"]))
+ (assert (= (distinct [nil nil]) [nil]))
+ (assert (= (distinct [0.0 0.0]) [0.0]))
+ (assert (= (distinct ['sym 'sym]) '[sym]))
+ (assert (= (distinct [:kw :kw]) [:kw]))
+ (assert (= (distinct [42 42]) [42]))
+ (assert (= (distinct [[] []]) [[]]))
+ (assert (= (distinct ['(1 2) '(1 2)]) '[(1 2)]))
+ (assert (= (distinct [() ()]) [()]))
+ (assert (= (distinct [[1 2] [1 2]]) [[1 2]]))
+ (assert (= (distinct [{:a 1 :b 2} {:a 1 :b 2}]) [{:a 1 :b 2}]))
+ (assert (= (distinct [{} {}]) [{}]))
+ (assert (= (distinct [#{1 2} #{1 2}]) [#{1 2}]))
+ (assert (= (distinct [#{} #{}]) [#{}]))
+
+ ;regexps
+ ;;these fail in v8 - why?
+ ;(assert (= (str (re-pattern "f(.)o")) (str (js* "/f(.)o/"))))
+ ;(assert (= (re-find (re-pattern "foo") "foo bar foo baz foo zot") "foo"))
+ ;(assert (= (re-find (re-pattern "f(.)o") "foo bar foo baz foo zot") ["foo" "o"]))
+ ;(assert (= (re-matches (re-pattern "foo") "foo") "foo"))
+ ;(assert (= (re-matches (re-pattern "foo") "foo bar foo baz foo zot") nil))
+ ;(assert (= (re-matches (re-pattern "foo.*") "foo bar foo baz foo zot") "foo bar foo baz foo zot"))
+ ;(assert (= (re-seq (re-pattern "foo") "foo bar foo baz foo zot") (list "foo" "foo" "foo")))
+ ;(assert (= (re-seq (re-pattern "f(.)o") "foo bar foo baz foo zot") (list ["foo" "o"] ["foo" "o"] ["foo" "o"])))
+
+ ;; destructuring
+ (assert (= [2 1] (let [[a b] [1 2]] [b a])))
+ (assert (= #{1 2} (let [[a b] [1 2]] #{a b})))
+ (assert (= [1 2] (let [{a :a b :b} {:a 1 :b 2}] [a b])))
+ (assert (= [1 2] (let [{:keys [a b]} {:a 1 :b 2}] [a b])))
+ (assert (= [1 2 [1 2]] (let [[a b :as v] [1 2]] [a b v])))
+ (assert (= [1 42] (let [{:keys [a b] :or {b 42}} {:a 1}] [a b])))
+ (assert (= [1 nil] (let [{:keys [a b] :or {c 42}} {:a 1}] [a b])))
+ (assert (= [2 1] (let [[a b] '(1 2)] [b a])))
+ (assert (= {1 2} (let [[a b] [1 2]] {a b})))
+ (assert (= [2 1] (let [[a b] (seq [1 2])] [b a])))
+
+ ;; update-in
+ (assert (= {:foo {:bar {:baz 1}}}
+ (update-in {:foo {:bar {:baz 0}}} [:foo :bar :baz] inc)))
+ (assert (= {:foo 1 :bar 2 :baz 10}
+ (update-in {:foo 1 :bar 2 :baz 3} [:baz] + 7)))
+ (assert (= [{:foo 1, :bar 2} {:foo 1, :bar 3}]
+ (update-in [{:foo 1 :bar 2}, {:foo 1 :bar 2}] [1 :bar] inc)))
+ (assert (= [{:foo {:bar 2}} {:foo {:bar 3}}]
+ (update-in [{:foo {:bar 2}}, {:foo {:bar 2}}] [1 :foo :bar] inc)))
+
+ ;; assoc-in
+ (assert (= {:foo {:bar {:baz 100}}}
+ (assoc-in {:foo {:bar {:baz 0}}} [:foo :bar :baz] 100)))
+ (assert (= {:foo 1 :bar 2 :baz 100}
+ (assoc-in {:foo 1 :bar 2 :baz 3} [:baz] 100)))
+ (assert (= [{:foo [{:bar 2} {:baz 3}]} {:foo [{:bar 2} {:baz 100}]}]
+ (assoc-in [{:foo [{:bar 2} {:baz 3}]}, {:foo [{:bar 2} {:baz 3}]}]
+ [1 :foo 1 :baz] 100)))
+ (assert (= [{:foo 1, :bar 2} {:foo 1, :bar 100}]
+ (assoc-in [{:foo 1 :bar 2}, {:foo 1 :bar 2}] [1 :bar] 100)))
+
+ ;; get-in
+ (assert (= 1 (get-in {:foo 1 :bar 2} [:foo])))
+ (assert (= 2 (get-in {:foo {:bar 2}} [:foo :bar])))
+ (assert (= 1 (get-in [{:foo 1}, {:foo 2}] [0 :foo])))
+ (assert (= 4 (get-in [{:foo 1 :bar [{:baz 1}, {:buzz 2}]}, {:foo 3 :bar [{:baz 3}, {:buzz 4}]}]
+ [1 :bar 1 :buzz])))
+
+ ;; arrays
+ (let [a (to-array [1 2 3])]
+ (assert (= [10 20 30] (seq (amap a i ret (* 10 (aget a i))))))
+ (assert (= 6 (areduce a i ret 0 (+ ret (aget a i)))))
+ (assert (= (seq a) (seq (to-array [1 2 3]))))
+ (assert (= 42 (aset a 0 42)))
+ (assert (not= (seq a) (seq (to-array [1 2 3]))))
+ (assert (not= a (aclone a))))
+
+ ;; sort
+ (assert (= [1 2 3 4 5] (sort [5 3 1 4 2])))
+ (assert (= [1 2 3 4 5] (sort < [5 3 1 4 2])))
+ (assert (= [5 4 3 2 1] (sort > [5 3 1 4 2])))
+
+ ;; sort-by
+ (assert (= ["a" [ 1 2] "foo"] (sort-by count ["foo" "a" [1 2]])))
+ (assert (= ["foo" [1 2] "a"] (sort-by count > ["foo" "a" [1 2]])))
+
+ ;; js->clj
+ (assert (= {"a" 1, "b" 2} (js->clj (js* "{\"a\":1,\"b\":2}"))))
+ (assert (= {:a 1, :b 2} (js->clj (js* "{\"a\":1,\"b\":2}") :keywordize-keys true)))
+ (assert (= [[{:a 1, :b 2} {:a 1, :b 2}]]
+ (js->clj (js* "[[{\"a\":1,\"b\":2}, {\"a\":1,\"b\":2}]]") :keywordize-keys true)))
+ (assert (= [[{:a 1, :b 2} {:a 1, :b 2}]]
+ (js->clj [[{:a 1, :b 2} {:a 1, :b 2}]])))
+
+ ;; last
+ (assert (= nil (last nil)))
+ (assert (= 3 (last [1 2 3])))
+
+ ;; dotimes
+ (let [s (atom [])]
+ (dotimes [n 5]
+ (swap! s conj n))
+ (assert (= [0 1 2 3 4] @s)))
+
+ ;; doseq
+ (let [v [1 2 3 4 5]
+ s (atom ())]
+ (doseq [n v] (swap! s conj n))
+ (assert (= @s (reverse v))))
+
+ ;; delay
+ ;; (let [d (delay (. (js/Date.) (getTime)))]
+ ;; (assert (false? (realized? d)))
+ ;; (let [d2 (. (js/Date.) (getTime))]
+ ;; (assert (> d2 (deref d))))
+ ;; (assert (true? (realized? d)))
+ ;; (let [d3 (deref d)]
+ ;; (assert (= (deref d) d3))))
+
+ ;; assoc
+ (assert (= {1 2 3 4} (assoc {} 1 2 3 4)))
+ (assert (= {1 2} (assoc {} 1 2)))
+ (assert (= [42 2] (assoc [1 2] 0 42)))
+
+ ;; dissoc
+ (assert (= {} (dissoc {1 2 3 4} 1 3)))
+ (assert (= {1 2} (dissoc {1 2 3 4} 3)))
+
+ ;; disj
+ (assert (= #{1 2 3} (disj #{1 2 3})))
+ (assert (= #{1 2} (disj #{1 2 3} 3)))
+ (assert (= #{1} (disj #{1 2 3} 2 3)))
+
+ ;; memoize
+ (let [f (memoize (fn [] (rand)))]
+ (f)
+ (assert (= (f) (f))))
+
+ ;; find
+ (assert (= (find {} :a) nil))
+ (assert (= (find {:a 1} :a) [:a 1]))
+ (assert (= (find {:a 1} :b) nil))
+ (assert (= (find {:a 1 :b 2} :a) [:a 1]))
+ (assert (= (find {:a 1 :b 2} :b) [:b 2]))
+ (assert (= (find {:a 1 :b 2} :c) nil))
+ (assert (= (find {} nil) nil))
+ (assert (= (find {:a 1} nil) nil))
+ (assert (= (find {:a 1 :b 2} nil) nil))
+ (assert (= (find [1 2 3] 0) [0 1]))
+
+ ;; mod,quot,rem
+ (assert (= (quot 4 2) 2))
+ (assert (= (quot 3 2) 1))
+ (assert (= (quot 6 4) 1))
+ (assert (= (quot 0 5) 0))
+ (assert (= (quot 42 5) 8))
+ (assert (= (quot 42 -5) -8))
+ (assert (= (quot -42 -5) 8))
+ (assert (= (quot 9 3) 3))
+ (assert (= (quot 9 -3) -3))
+ (assert (= (quot -9 3) -3))
+ (assert (= (quot 2 -5) 0))
+ (assert (= (quot -2 5) 0))
+ (assert (= (quot 0 3) 0))
+ (assert (= (quot 0 -3) 0))
+
+ (assert (= (mod 4 2) 0))
+ (assert (= (mod 3 2) 1))
+ (assert (= (mod 6 4) 2))
+ (assert (= (mod 0 5) 0))
+ (assert (= (mod 4.5 2.0) 0.5))
+ (assert (= (mod 42 5) 2))
+ (assert (= (mod 9 3) 0))
+ (assert (= (mod 9 -3) 0))
+ (assert (= (mod -9 3) 0))
+ (assert (= (mod -9 -3) 0))
+ (assert (= (mod 0 3) 0))
+ (assert (= (mod 3216478362187432 432143214) 120355456))
+
+ (assert (= (rem 4 2) 0))
+ (assert (= (rem 0 5) 0))
+ (assert (= (rem 4.5 2.0) 0.5))
+ (assert (= (rem 42 5) 2))
+ (assert (= (rem 2 5) 2))
+ (assert (= (rem 2 -5) 2))
+ (assert (= (rem 0 3) 0))
+
+ ;; range
+ (assert (= (range 10) (list 0 1 2 3 4 5 6 7 8 9)))
+ (assert (= (range 10 20) (list 10 11 12 13 14 15 16 17 18 19)))
+ (assert (= (range 10 20 2) (list 10 12 14 16 18)))
+ (assert (= (take 20 (range)) (list 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)))
+
+ ;; group-by
+ (let [d (group-by second {:a 1 :b 2 :c 1 :d 4 :e 1 :f 2})]
+ (assert (= 3 (count (get d 1))))
+ (assert (= 2 (count (get d 2))))
+ (assert (= 1 (count (get d 4)))))
+
+ (assert (= {1 2 3 4 5 6} (merge {1 2} {3 4} {5 6})))
+ (assert (= {1 2 3 4} (merge {1 2} {3 4} nil)))
+
+ ;; frequencies
+ (assert (= {:a 3 :b 2} (frequencies [:a :b :a :b :a])))
+
+ ;; reductions
+ (assert (= [1 3 6 10 15] (reductions + [1 2 3 4 5])))
+
+ ;; keep
+ (assert (= [1 3 5 7 9] (keep #(if (odd? %) %) [1 2 3 4 5 6 7 8 9 10])))
+ (assert (= [2 4 6 8 10] (keep #(if (even? %) %) [1 2 3 4 5 6 7 8 9 10])))
+
+ ;; keep-indexed
+ (assert (= [1 3 5 7 9] (keep-indexed #(if (odd? %1) %2) [0 1 2 3 4 5 6 7 8 9 10])))
+ (assert (= [2 4 5] (keep-indexed #(if (pos? %2) %1) [-9 0 29 -7 45 3 -8])))
+
+ ;; map-indexed
+ (assert (= [[0 :a] [1 :b] [2 :c]] (map-indexed #(vector % %2) [:a :b :c])))
+
+ ;; merge-with
+ (assert (= '{"Foo" ("foo" "FOO" "fOo"), "Bar" ("bar" "BAR" "BAr"), "Baz" ["baz"], "Qux" ["qux" "quux"]}
+ (merge-with concat
+ {"Foo" ["foo" "FOO"]
+ "Bar" ["bar" "BAR"]
+ "Baz" ["baz"]}
+ {"Foo" ["fOo"]
+ "Bar" ["BAr"]
+ "Qux" ["qux" "quux"]})))
+ (assert (= {:a 111, :b 102, :c 13}
+ (merge-with +
+ {:a 1 :b 2 :c 3}
+ {:a 10 :c 10}
+ {:a 100 :b 100})))
+
+ (assert (= {:a 3, :b 102, :c 13}
+ (apply merge-with [+
+ {:a 1 :b 100}
+ {:a 1 :b 2 :c 3}
+ {:a 1 :c 10}])))
+
+ (assert (= '[a c e] (replace '[a b c d e] [0 2 4])))
+ (assert (= [:one :zero :two :zero]
+ (replace {0 :zero 1 :one 2 :two} '(1 0 2 0))))
+
+ ;; split-at
+ (assert (= [[1 2] [3 4 5]] (split-at 2 [1 2 3 4 5])))
+
+ ;; split-with
+ (assert (= [[1 2 3] [4 5]] (split-with (partial >= 3) [1 2 3 4 5])))
+
+ ;; trampoline
+ (assert (= 10000 (trampoline (fn f [n] (if (>= n 10000) n #(f (inc n)))) 0)))
+
+ ;; vary-meta
+ (assert (= {:a 1} (meta (vary-meta [] assoc :a 1))))
+ (assert (= {:a 1 :b 2} (meta (vary-meta (with-meta [] {:b 2}) assoc :a 1))))
+ :ok
+ )
+
+
View
20 test/cljs/cljs/reader_test.cljs
@@ -0,0 +1,20 @@
+(ns cljs.reader-test
+ (:require [cljs.reader :as reader]))
+
+(defn test-reader
+ []
+ (assert (= 1 (reader/read-string "1")))
+ (assert (= 2 (reader/read-string "#_nope 2")))
+ (assert (= [3 4] (reader/read-string "[3 4]")))
+ (assert (= "foo" (reader/read-string "\"foo\"")))
+ (assert (= :hello (reader/read-string ":hello")))
+ (assert (= 'goodbye (reader/read-string "goodbye")))
+ (assert (= #{1 2 3} (reader/read-string "#{1 2 3}")))
+ (assert (= '(7 8 9) (reader/read-string "(7 8 9)")))
+ (assert (= '(deref foo) (reader/read-string "@foo")))
+ (assert (= '(quote bar) (reader/read-string "'bar")))
+ (assert (= \a (reader/read-string "\\a")))
+ (assert (= {:tag 'String} (meta (reader/read-string "^String {:a 1}"))))
+ (assert (= [:a 'b #{'c {:d [:e :f :g]}}]
+ (reader/read-string "[:a b #{c {:d [:e :f :g]}}]")))
+ :ok)
View
10 test/cljs/cljs/test_runner.cljs
@@ -0,0 +1,10 @@
+(ns cljs.test-runner
+ (:require [cljs.core-test :as core-test]
+ [cljs.reader-test :as reader-test]))
+
+(core-test/test-stuff)
+(reader-test/test-reader)
+
+(println "Tests completed without exception")
+
+

0 comments on commit abc53d9

Please sign in to comment.
Something went wrong with that request. Please try again.