clementine 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +4 -2
- data/LICENSE.txt +22 -0
- data/README.md +11 -6
- data/Rakefile +22 -0
- data/clementine.gemspec +2 -1
- data/ext/clojure-clojurescript-bef56a7/.gitignore +13 -0
- data/ext/clojure-clojurescript-bef56a7/Clojurescript.iml +12 -0
- data/ext/clojure-clojurescript-bef56a7/README.md +29 -0
- data/ext/clojure-clojurescript-bef56a7/benchmark/cljs/benchmark_runner.cljs +155 -0
- data/ext/clojure-clojurescript-bef56a7/bin/cljsc +21 -0
- data/ext/clojure-clojurescript-bef56a7/bin/cljsc.bat +18 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/bin/cljsc.clj +0 -0
- data/ext/clojure-clojurescript-bef56a7/devnotes/README.org +35 -0
- data/ext/clojure-clojurescript-bef56a7/devnotes/bcrepl.org +13 -0
- data/ext/clojure-clojurescript-bef56a7/devnotes/cljs.org +500 -0
- data/ext/clojure-clojurescript-bef56a7/devnotes/corelib.org +583 -0
- data/ext/clojure-clojurescript-bef56a7/devnotes/day1.org +203 -0
- data/ext/clojure-clojurescript-bef56a7/devnotes/day2.org +44 -0
- data/ext/clojure-clojurescript-bef56a7/devnotes/talk.org +126 -0
- data/ext/clojure-clojurescript-bef56a7/devnotes/testing +13 -0
- data/ext/clojure-clojurescript-bef56a7/devnotes/todo.org +121 -0
- data/ext/clojure-clojurescript-bef56a7/epl-v10.html +261 -0
- data/ext/clojure-clojurescript-bef56a7/pom.template.xml +88 -0
- data/ext/clojure-clojurescript-bef56a7/samples/dom/.gitignore +2 -0
- data/ext/clojure-clojurescript-bef56a7/samples/dom/src/dom/test.cljs +48 -0
- data/ext/clojure-clojurescript-bef56a7/samples/dom/test.html +30 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello-js/.gitignore +2 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello-js/README.md +53 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello-js/externed-lib.js +7 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello-js/externs.js +3 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello-js/hello-extern.html +14 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello-js/hello-js-dev.html +18 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello-js/hello-js.html +17 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello-js/my-external-lib.js +3 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello-js/src/hello-js/core.cljs +9 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello-js/src/hello-js/extern-example.cljs +5 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello/.gitignore +2 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello/README.md +34 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello/hello-dev.html +18 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello/hello.html +13 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello/src/hello/core.cljs +8 -0
- data/ext/clojure-clojurescript-bef56a7/samples/hello/src/hello/foo/bar.cljs +4 -0
- data/ext/clojure-clojurescript-bef56a7/samples/nodehello.cljs +18 -0
- data/ext/clojure-clojurescript-bef56a7/samples/nodels.cljs +17 -0
- data/ext/clojure-clojurescript-bef56a7/samples/repl/.gitignore +2 -0
- data/ext/clojure-clojurescript-bef56a7/samples/repl/README.md +101 -0
- data/ext/clojure-clojurescript-bef56a7/samples/repl/index.html +27 -0
- data/ext/clojure-clojurescript-bef56a7/samples/repl/src/repl/test.cljs +73 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/.gitignore +2 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/README.md +42 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/index-advanced.html +80 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/index.html +88 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/reset.css +48 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/anneal.cljs +66 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/core.cljs +307 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/dom-helpers.cljs +95 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/layout.cljs +100 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/leaderboard.cljs +40 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/radial.cljs +91 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/showgraph.cljs +121 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/timeline.cljs +39 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/style.css +301 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/test_data.txt +1 -0
- data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/tweet_maps.txt +1 -0
- data/ext/clojure-clojurescript-bef56a7/script/benchmark +30 -0
- data/ext/clojure-clojurescript-bef56a7/script/bootstrap +70 -0
- data/ext/clojure-clojurescript-bef56a7/script/browser-repl +16 -0
- data/ext/clojure-clojurescript-bef56a7/script/build +59 -0
- data/ext/clojure-clojurescript-bef56a7/script/clean +5 -0
- data/ext/clojure-clojurescript-bef56a7/script/closure-library-release/google-closure-library-third-party.pom.template +59 -0
- data/ext/clojure-clojurescript-bef56a7/script/closure-library-release/google-closure-library.pom.template +54 -0
- data/ext/clojure-clojurescript-bef56a7/script/closure-library-release/make-closure-library-jars.sh +87 -0
- data/ext/clojure-clojurescript-bef56a7/script/compile +41 -0
- data/ext/clojure-clojurescript-bef56a7/script/repl +13 -0
- data/ext/clojure-clojurescript-bef56a7/script/repl.bat +13 -0
- data/ext/clojure-clojurescript-bef56a7/script/repljs +15 -0
- data/ext/clojure-clojurescript-bef56a7/script/repljs.bat +14 -0
- data/ext/clojure-clojurescript-bef56a7/script/test +38 -0
- data/ext/clojure-clojurescript-bef56a7/script/test-compile +30 -0
- data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/analyzer.clj +975 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/clj/cljs/closure.clj +173 -73
- data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/compiler.clj +1081 -0
- data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/core.clj +1158 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/clj/cljs/repl.clj +51 -25
- data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/repl/browser.clj +258 -0
- data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/repl/reflect.clj +75 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/clj/cljs/repl/rhino.clj +6 -5
- data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/repl/server.clj +173 -0
- data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/tagged_literals.clj +30 -0
- data/ext/clojure-clojurescript-bef56a7/src/cljs/cljs/core.cljs +7197 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/cljs/nodejs.cljs +1 -1
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/cljs/nodejs_externs.js +0 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/cljs/nodejscli.cljs +1 -1
- data/ext/clojure-clojurescript-bef56a7/src/cljs/cljs/reader.cljs +551 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/browser/dom.cljs +59 -13
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/browser/event.cljs +0 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/browser/net.cljs +8 -7
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/browser/repl.cljs +2 -2
- data/ext/clojure-clojurescript-bef56a7/src/cljs/clojure/core/reducers.cljs +298 -0
- data/ext/clojure-clojurescript-bef56a7/src/cljs/clojure/data.cljs +162 -0
- data/ext/clojure-clojurescript-bef56a7/src/cljs/clojure/reflect.cljs +48 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/set.cljs +0 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/string.cljs +4 -10
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/walk.cljs +0 -0
- data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/zip.cljs +0 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/binding_test.cljs +7 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/binding_test_other_ns.cljs +3 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/core_test.cljs +1678 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/import_test.cljs +11 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/import_test/foo.cljs +5 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/letfn_test.cljs +19 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/macro_test.cljs +6 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/macro_test/macros.clj +5 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/ns_test.cljs +14 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/ns_test/bar.cljs +3 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/ns_test/foo.cljs +7 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/reader_test.cljs +124 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/clojure/data_test.cljs +22 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/clojure/string_test.cljs +97 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/foo/ns_shadow_test.cljs +9 -0
- data/ext/clojure-clojurescript-bef56a7/test/cljs/test_runner.cljs +26 -0
- data/lib/clementine.rb +3 -24
- data/lib/clementine/clojurescript_engine.rb +9 -48
- data/lib/clementine/clojurescript_engine/base.rb +15 -0
- data/lib/clementine/clojurescript_engine/jruby.rb +46 -0
- data/lib/clementine/{clojurescript_engine_mri.rb → clojurescript_engine/mri.rb} +17 -10
- data/lib/clementine/version.rb +1 -1
- data/test/clojurescript_engine_test.rb +36 -14
- metadata +177 -83
- data/vendor/assets/lib/clojure.jar +0 -0
- data/vendor/assets/lib/compiler.jar +0 -0
- data/vendor/assets/lib/goog.jar +0 -0
- data/vendor/assets/lib/js.jar +0 -0
- data/vendor/assets/src/clj/cljs/compiler.clj +0 -1341
- data/vendor/assets/src/clj/cljs/core.clj +0 -702
- data/vendor/assets/src/clj/cljs/repl/browser.clj +0 -341
- data/vendor/assets/src/cljs/cljs/core.cljs +0 -3330
- data/vendor/assets/src/cljs/cljs/reader.cljs +0 -360
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
(ns cljs.import-test
|
|
2
|
+
(:import goog.math.Long
|
|
3
|
+
cljs.import-test.foo.Bar
|
|
4
|
+
cljs.import-test.foo.Quux))
|
|
5
|
+
|
|
6
|
+
(defn test-import []
|
|
7
|
+
(assert (fn? Long))
|
|
8
|
+
(assert (.equals (Long. 4 6) (.add (Long. 1 2) (Long. 3 4))))
|
|
9
|
+
(assert (= "12" (Long/fromInt 12)))
|
|
10
|
+
(assert (= 12 (.-x (Bar. 12))))
|
|
11
|
+
(assert (= 12 (.-x (Quux. 12)))))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
(ns cljs.letfn-test)
|
|
2
|
+
|
|
3
|
+
(defn test-letfn []
|
|
4
|
+
(letfn [(ev? [x]
|
|
5
|
+
(if (zero? x)
|
|
6
|
+
true
|
|
7
|
+
(od? (dec x))))
|
|
8
|
+
(od? [x]
|
|
9
|
+
(if (zero? x)
|
|
10
|
+
false
|
|
11
|
+
(ev? (dec x))))]
|
|
12
|
+
(assert (ev? 0))
|
|
13
|
+
(assert (ev? 10))
|
|
14
|
+
(assert (not (ev? 1)))
|
|
15
|
+
(assert (not (ev? 11)))
|
|
16
|
+
(assert (not (od? 0)))
|
|
17
|
+
(assert (not (od? 10)))
|
|
18
|
+
(assert (od? 1))
|
|
19
|
+
(assert (od? 11))))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
(ns cljs.ns-test
|
|
2
|
+
(:refer-clojure :exclude [+])
|
|
3
|
+
(:require [cljs.ns-test.foo :refer [baz]])
|
|
4
|
+
(:use [cljs.ns-test.bar :only [quux]]))
|
|
5
|
+
|
|
6
|
+
(def + -)
|
|
7
|
+
|
|
8
|
+
(defn test-ns []
|
|
9
|
+
(assert (= 4 (clojure.core/+ 2 1 1)))
|
|
10
|
+
(assert (= 0 (cljs.ns-test/+ 2 1 1)))
|
|
11
|
+
(assert (= 0 (+ 2 1 1)))
|
|
12
|
+
(assert (= 123 (baz)))
|
|
13
|
+
(assert (= 123 (quux)))
|
|
14
|
+
:ok)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
(ns cljs.reader-test
|
|
2
|
+
(:require [cljs.reader :as reader]
|
|
3
|
+
[goog.object :as o]))
|
|
4
|
+
|
|
5
|
+
(deftype T [a b])
|
|
6
|
+
(defrecord R [a b])
|
|
7
|
+
|
|
8
|
+
(defn test-reader
|
|
9
|
+
[]
|
|
10
|
+
(assert (= 1 (reader/read-string "1")))
|
|
11
|
+
(assert (= 2 (reader/read-string "#_nope 2")))
|
|
12
|
+
(assert (= -1 (reader/read-string "-1")))
|
|
13
|
+
(assert (= -1.5 (reader/read-string "-1.5")))
|
|
14
|
+
(assert (= [3 4] (reader/read-string "[3 4]")))
|
|
15
|
+
(assert (= "foo" (reader/read-string "\"foo\"")))
|
|
16
|
+
(assert (= :hello (reader/read-string ":hello")))
|
|
17
|
+
(assert (= 'goodbye (reader/read-string "goodbye")))
|
|
18
|
+
(assert (= #{1 2 3} (reader/read-string "#{1 2 3}")))
|
|
19
|
+
(assert (= '(7 8 9) (reader/read-string "(7 8 9)")))
|
|
20
|
+
(assert (= '(deref foo) (reader/read-string "@foo")))
|
|
21
|
+
(assert (= '(quote bar) (reader/read-string "'bar")))
|
|
22
|
+
(assert (= 'foo/bar (reader/read-string "foo/bar")))
|
|
23
|
+
(assert (= \a (reader/read-string "\\a")))
|
|
24
|
+
(assert (= {:tag 'String} (meta (reader/read-string "^String {:a 1}"))))
|
|
25
|
+
(assert (= [:a 'b #{'c {:d [:e :f :g]}}]
|
|
26
|
+
(reader/read-string "[:a b #{c {:d [:e :f :g]}}]")))
|
|
27
|
+
(assert (= :foo/bar (reader/read-string ":foo/bar")))
|
|
28
|
+
(assert (= nil (reader/read-string "nil")))
|
|
29
|
+
(assert (= true (reader/read-string "true")))
|
|
30
|
+
(assert (= false (reader/read-string "false")))
|
|
31
|
+
(assert (= "string" (reader/read-string "\"string\"")))
|
|
32
|
+
(assert (= "escape chars \t \r \n \\ \" \b \f" (reader/read-string "\"escape chars \\t \\r \\n \\\\ \\\" \\b \\f\"")))
|
|
33
|
+
|
|
34
|
+
;; queue literals
|
|
35
|
+
(assert (= cljs.core.PersistentQueue/EMPTY
|
|
36
|
+
(reader/read-string "#queue []")))
|
|
37
|
+
|
|
38
|
+
(assert (= (-> cljs.core.PersistentQueue/EMPTY (conj 1))
|
|
39
|
+
(reader/read-string "#queue [1]")))
|
|
40
|
+
|
|
41
|
+
(assert (= (into cljs.core.PersistentQueue/EMPTY [1 2])
|
|
42
|
+
(reader/read-string "#queue [1 2]")))
|
|
43
|
+
|
|
44
|
+
;; inst
|
|
45
|
+
(let [est-inst (reader/read-string "#inst \"2010-11-12T13:14:15.666-05:00\"")
|
|
46
|
+
utc-inst (reader/read-string "#inst \"2010-11-12T18:14:15.666-00:00\"")]
|
|
47
|
+
|
|
48
|
+
(assert (= (.valueOf (js/Date. "2010-11-12T13:14:15.666-05:00"))
|
|
49
|
+
(.valueOf est-inst)))
|
|
50
|
+
|
|
51
|
+
(assert (= (.valueOf est-inst)
|
|
52
|
+
(.valueOf (reader/read-string (pr-str est-inst)))))
|
|
53
|
+
|
|
54
|
+
(assert (= (.valueOf est-inst)
|
|
55
|
+
(.valueOf utc-inst)))
|
|
56
|
+
|
|
57
|
+
(doseq [month (range 1 13) day (range 1 29) hour (range 1 23)]
|
|
58
|
+
(let [s (str "#inst \"2010-" month "-" day "T" hour ":14:15.666-06:00\"")]
|
|
59
|
+
(assert (= (-> s reader/read-string .valueOf)
|
|
60
|
+
(-> s reader/read-string pr-str reader/read-string .valueOf))))))
|
|
61
|
+
|
|
62
|
+
;; uuid literals
|
|
63
|
+
(let [u (reader/read-string "#uuid \"550e8400-e29b-41d4-a716-446655440000\"")]
|
|
64
|
+
(assert (= u (reader/read-string "#uuid \"550e8400-e29b-41d4-a716-446655440000\"")))
|
|
65
|
+
|
|
66
|
+
(assert (not (identical? u (reader/read-string "#uuid \"550e8400-e29b-41d4-a716-446655440000\""))))
|
|
67
|
+
|
|
68
|
+
(assert (= u (-> u pr-str reader/read-string))))
|
|
69
|
+
|
|
70
|
+
;; new tag parsers
|
|
71
|
+
|
|
72
|
+
(reader/register-tag-parser! 'foo identity)
|
|
73
|
+
|
|
74
|
+
(assert (= [1 2] (reader/read-string "#foo [1 2]")))
|
|
75
|
+
|
|
76
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
77
|
+
;; Unicode Tests
|
|
78
|
+
|
|
79
|
+
; sample unicode strings, symbols, keywords
|
|
80
|
+
(doseq [unicode
|
|
81
|
+
["اختبار" ; arabic
|
|
82
|
+
"ทดสอบ" ; thai
|
|
83
|
+
"こんにちは" ; japanese hiragana
|
|
84
|
+
"你好" ; chinese traditional
|
|
85
|
+
"אַ גוט יאָר" ; yiddish
|
|
86
|
+
"cześć" ; polish
|
|
87
|
+
"привет" ; russian
|
|
88
|
+
|
|
89
|
+
;; RTL languages skipped below because tricky to insert
|
|
90
|
+
;; ' and : at the "start"
|
|
91
|
+
|
|
92
|
+
'ทดสอบ
|
|
93
|
+
'こんにちは
|
|
94
|
+
'你好
|
|
95
|
+
'cześć
|
|
96
|
+
'привет
|
|
97
|
+
|
|
98
|
+
:ทดสอบ
|
|
99
|
+
:こんにちは
|
|
100
|
+
:你好
|
|
101
|
+
:cześć
|
|
102
|
+
:привет
|
|
103
|
+
|
|
104
|
+
;compound data
|
|
105
|
+
{:привет :ru "你好" :cn}
|
|
106
|
+
]]
|
|
107
|
+
(let [input (pr-str unicode)
|
|
108
|
+
read (reader/read-string input)]
|
|
109
|
+
(assert (= unicode read)
|
|
110
|
+
(str "Failed to read-string \"" unicode "\" from: " input))))
|
|
111
|
+
|
|
112
|
+
; unicode error cases
|
|
113
|
+
(doseq [unicode-error
|
|
114
|
+
["\"abc \\ua\"" ; truncated
|
|
115
|
+
"\"abc \\x0z ...etc\"" ; incorrect code
|
|
116
|
+
"\"abc \\u0g00 ..etc\"" ; incorrect code
|
|
117
|
+
]]
|
|
118
|
+
(let [r (try
|
|
119
|
+
(reader/read-string unicode-error)
|
|
120
|
+
:failed-to-throw
|
|
121
|
+
(catch js/Error e :ok))]
|
|
122
|
+
(assert (= r :ok) (str "Failed to throw reader error for: " unicode-error))))
|
|
123
|
+
|
|
124
|
+
:ok)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(ns clojure.data-test
|
|
2
|
+
(:require [clojure.data :refer [diff]]))
|
|
3
|
+
|
|
4
|
+
(defn test-data []
|
|
5
|
+
(assert (= [nil nil nil] (diff nil nil)))
|
|
6
|
+
(assert (= [1 2 nil] (diff 1 2)))
|
|
7
|
+
(assert (= [nil nil [1 2 3]] (diff [1 2 3] '(1 2 3))))
|
|
8
|
+
(assert (= [1 [:a :b] nil] (diff 1 [:a :b])))
|
|
9
|
+
(assert (= [{:a 1} :b nil] (diff {:a 1} :b)))
|
|
10
|
+
(assert (= [:team #{:p1 :p2} nil] (diff :team #{:p1 :p2})))
|
|
11
|
+
(assert (= [{0 :a} [:a] nil] (diff {0 :a} [:a])))
|
|
12
|
+
(assert (= [nil [nil 2] [1]] (diff [1] [1 2])))
|
|
13
|
+
(assert (= [nil nil [1 2]] (diff [1 2] (into-array [1 2]))))
|
|
14
|
+
(assert (= [#{:a} #{:b} #{:c :d}] (diff #{:a :c :d} #{:b :c :d})))
|
|
15
|
+
(assert (= [nil nil {:a 1}] (diff {:a 1} {:a 1})))
|
|
16
|
+
(assert (= [{:a #{2}} {:a #{4}} {:a #{3}}] (diff {:a #{2 3}} {:a #{3 4}})))
|
|
17
|
+
(assert (= [nil nil [1 2]] (diff [1 2] (into-array [1 2]))))
|
|
18
|
+
(assert (= [nil nil [1 2]] (diff (into-array [1 2]) [1 2])))
|
|
19
|
+
(assert (= [{:a {:c [1]}} {:a {:c [0]}} {:a {:c [nil 2] :b 1}}]
|
|
20
|
+
(diff {:a {:b 1 :c [1 2]}} {:a {:b 1 :c [0 2]}})))
|
|
21
|
+
(assert (= [{:a nil} {:a false} {:b nil :c false}]
|
|
22
|
+
(diff {:a nil :b nil :c false} {:a false :b nil :c false}))))
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
(ns clojure.string-test
|
|
2
|
+
(:require [clojure.string :as s]))
|
|
3
|
+
|
|
4
|
+
(defn test-string
|
|
5
|
+
[]
|
|
6
|
+
;; reverse
|
|
7
|
+
(assert (= "" (s/reverse "")))
|
|
8
|
+
(assert (= "tab" (s/reverse "bat")))
|
|
9
|
+
;; replace
|
|
10
|
+
(assert (= "faabar" (s/replace "foobar" \o \a)))
|
|
11
|
+
(assert (= "barbarbar" (s/replace "foobarfoo" "foo" "bar")))
|
|
12
|
+
(assert (= "FOObarFOO" (s/replace "foobarfoo" #"foo" s/upper-case)))
|
|
13
|
+
(assert (= "barbar)foo" (s/replace "foo(bar)foo" "foo(" "bar")))
|
|
14
|
+
;; join
|
|
15
|
+
(assert (= "" (s/join nil)))
|
|
16
|
+
(assert (= "" (s/join [])))
|
|
17
|
+
(assert (= "1" (s/join [1])))
|
|
18
|
+
(assert (= "12" (s/join [1 2])))
|
|
19
|
+
(assert (= "1,2,3" (s/join \, [1 2 3])))
|
|
20
|
+
(assert (= "" (s/join \, [])))
|
|
21
|
+
(assert (= "1 and-a 2 and-a 3" (s/join " and-a " [1 2 3])))
|
|
22
|
+
;; capitalize
|
|
23
|
+
(assert (= "FOOBAR" (s/upper-case "Foobar")))
|
|
24
|
+
(assert (= "foobar" (s/lower-case "FooBar")))
|
|
25
|
+
(assert (= "Foobar" (s/capitalize "foobar")))
|
|
26
|
+
(assert (= "Foobar" (s/capitalize "FOOBAR")))
|
|
27
|
+
;; split
|
|
28
|
+
(assert (= ["a" "b"] (s/split "a-b" #"-")))
|
|
29
|
+
(assert (= ["a" "b" "c"] (s/split "a-b-c" #"-" -1)))
|
|
30
|
+
(assert (= ["a" "b" "c"] (s/split "a-b-c" #"-" 0)))
|
|
31
|
+
(assert (= ["a-b-c"] (s/split "a-b-c" #"-" 1)))
|
|
32
|
+
(assert (= ["a" "b-c"] (s/split "a-b-c" #"-" 2)))
|
|
33
|
+
(assert (= ["a" "b" "c"] (s/split "a-b-c" #"-" 3)))
|
|
34
|
+
(assert (= ["a" "b" "c"] (s/split "a-b-c" #"-" 4)))
|
|
35
|
+
(assert (vector? (s/split "abc" #"-")))
|
|
36
|
+
(assert (= ["a-b-c"] (s/split "a-b-c" #"x" 2)))
|
|
37
|
+
;; split-lines
|
|
38
|
+
(let [result (s/split-lines "one\ntwo\r\nthree")]
|
|
39
|
+
(assert (= ["one" "two" "three"] result))
|
|
40
|
+
(assert (vector? result)))
|
|
41
|
+
(assert (= (list "foo") (s/split-lines "foo")))
|
|
42
|
+
;; blank
|
|
43
|
+
(assert (s/blank? nil))
|
|
44
|
+
(assert (s/blank? ""))
|
|
45
|
+
(assert (s/blank? " "))
|
|
46
|
+
(assert (s/blank? " \t \n \r "))
|
|
47
|
+
(assert (not (s/blank? " foo ")))
|
|
48
|
+
;; escape
|
|
49
|
+
(assert (= "<foo&bar>"
|
|
50
|
+
(s/escape "<foo&bar>" {\& "&" \< "<" \> ">"})))
|
|
51
|
+
(assert (= " \\\"foo\\\" "
|
|
52
|
+
(s/escape " \"foo\" " {\" "\\\""})))
|
|
53
|
+
(assert (= "faabor"
|
|
54
|
+
(s/escape "foobar" {\a \o, \o \a})))
|
|
55
|
+
;; replace-first
|
|
56
|
+
(assert (= "barbarfoo" (s/replace-first "foobarfoo" "foo" "bar")))
|
|
57
|
+
(assert (= "barbarfoo" (s/replace-first "foobarfoo" #"foo" "bar")))
|
|
58
|
+
(assert (= "z.ology" (s/replace-first "zoology" \o \.)))
|
|
59
|
+
(assert (= "FOObarfoo" (s/replace-first "foobarfoo" #"foo" s/upper-case)))
|
|
60
|
+
;; trim
|
|
61
|
+
(assert (= "foo " (s/triml " foo ")))
|
|
62
|
+
(assert (= "" (s/triml " ")))
|
|
63
|
+
(assert (= " foo" (s/trimr " foo ")))
|
|
64
|
+
(assert (= "" (s/trimr " ")))
|
|
65
|
+
(assert (= "foo" (s/trim " foo \r\n")))
|
|
66
|
+
;; trim-newline
|
|
67
|
+
(assert (= "foo" (s/trim-newline "foo\n")))
|
|
68
|
+
(assert (= "foo" (s/trim-newline "foo\r\n")))
|
|
69
|
+
(assert (= "foo" (s/trim-newline "foo")))
|
|
70
|
+
(assert (= "foo\r " (s/trim-newline "foo\r ")))
|
|
71
|
+
(assert (= "" (s/trim-newline "")))
|
|
72
|
+
:ok)
|
|
73
|
+
|
|
74
|
+
(comment
|
|
75
|
+
|
|
76
|
+
(deftest char-sequence-handling
|
|
77
|
+
(are [result f args] (let [[^CharSequence s & more] args]
|
|
78
|
+
(= result (apply f (StringBuffer. s) more)))
|
|
79
|
+
"paz" s/reverse ["zap"]
|
|
80
|
+
"foo:bar" s/replace ["foo-bar" \- \:]
|
|
81
|
+
"ABC" s/replace ["abc" #"\w" s/upper-case]
|
|
82
|
+
"faa" s/replace ["foo" #"o" (StringBuffer. "a")]
|
|
83
|
+
"baz::quux" s/replace-first ["baz--quux" #"--" "::"]
|
|
84
|
+
"baz::quux" s/replace-first ["baz--quux" (StringBuffer. "--") (StringBuffer. "::")]
|
|
85
|
+
"zim-zam" s/replace-first ["zim zam" #" " (StringBuffer. "-")]
|
|
86
|
+
"Pow" s/capitalize ["POW"]
|
|
87
|
+
"BOOM" s/upper-case ["boom"]
|
|
88
|
+
"whimper" s/lower-case ["whimPER"]
|
|
89
|
+
["foo" "bar"] s/split ["foo-bar" #"-"]
|
|
90
|
+
"calvino" s/trim [" calvino "]
|
|
91
|
+
"calvino " s/triml [" calvino "]
|
|
92
|
+
" calvino" s/trimr [" calvino "]
|
|
93
|
+
"the end" s/trim-newline ["the end\r\n\r\r\n"]
|
|
94
|
+
true s/blank? [" "]
|
|
95
|
+
["a" "b"] s/split-lines ["a\nb"]
|
|
96
|
+
"fa la la" s/escape ["fo lo lo" {\o \a}]))
|
|
97
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
(ns test-runner
|
|
2
|
+
(:require [cljs.core-test :as core-test]
|
|
3
|
+
[cljs.reader-test :as reader-test]
|
|
4
|
+
[cljs.binding-test :as binding-test]
|
|
5
|
+
[cljs.ns-test :as ns-test]
|
|
6
|
+
[clojure.string-test :as string-test]
|
|
7
|
+
[clojure.data-test :as data-test]
|
|
8
|
+
[cljs.macro-test :as macro-test]
|
|
9
|
+
[cljs.letfn-test :as letfn-test]
|
|
10
|
+
[foo.ns-shadow-test :as ns-shadow-test]))
|
|
11
|
+
|
|
12
|
+
(set! *print-fn* js/print)
|
|
13
|
+
|
|
14
|
+
(core-test/test-stuff)
|
|
15
|
+
(reader-test/test-reader)
|
|
16
|
+
(string-test/test-string)
|
|
17
|
+
(data-test/test-data)
|
|
18
|
+
(binding-test/test-binding)
|
|
19
|
+
(ns-test/test-ns)
|
|
20
|
+
(macro-test/test-macros)
|
|
21
|
+
(letfn-test/test-letfn)
|
|
22
|
+
(ns-shadow-test/test-shadow)
|
|
23
|
+
|
|
24
|
+
(println "Tests completed without exception")
|
|
25
|
+
|
|
26
|
+
|
data/lib/clementine.rb
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
require "clementine/version"
|
|
3
3
|
require 'clementine/options'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
CLOJURESCRIPT_HOME = File.dirname(__FILE__) + "/../vendor/assets"
|
|
9
|
-
$: << CLOJURESCRIPT_HOME + "/lib"
|
|
10
|
-
require 'clojure'
|
|
11
|
-
|
|
12
|
-
%w{compiler.jar goog.jar js.jar}.each {|name| $CLASSPATH << CLOJURESCRIPT_HOME + "/lib/" + name}
|
|
13
|
-
%w{clj cljs}.each {|path| $CLASSPATH << CLOJURESCRIPT_HOME + "/src/" + path}
|
|
14
|
-
|
|
15
|
-
require "clementine/clojurescript_engine"
|
|
16
|
-
require "clementine/clojurescript_template"
|
|
17
|
-
require "clementine/clementine_rails" if defined?(Rails)
|
|
18
|
-
end
|
|
19
|
-
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
|
|
20
|
-
CLOJURESCRIPT_HOME = File.dirname(__FILE__) + "/../vendor/assets"
|
|
21
|
-
CLASSPATH = []
|
|
22
|
-
%w{clojure.jar compiler.jar goog.jar js.jar}.each {|name| CLASSPATH << CLOJURESCRIPT_HOME + "/lib/" + name}
|
|
23
|
-
%w{clj cljs}.each {|path| CLASSPATH << CLOJURESCRIPT_HOME + "/src/" + path}
|
|
24
|
-
require "clementine/clojurescript_engine_mri"
|
|
25
|
-
require "clementine/clojurescript_template"
|
|
26
|
-
require "clementine/clementine_rails" if defined?(Rails)
|
|
27
|
-
end
|
|
4
|
+
require 'clementine/clojurescript_engine'
|
|
5
|
+
require "clementine/clojurescript_template"
|
|
6
|
+
require "clementine/clementine_rails" if defined?(Rails)
|
|
@@ -1,49 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
CLOJURESCRIPT_HOME = File.join(File.dirname(__FILE__), "../../ext/clojure-clojurescript-bef56a7")
|
|
2
|
+
CLOJURESCRIPT_LIB = File.join(File.dirname(__FILE__), "../")
|
|
3
|
+
|
|
4
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
|
5
|
+
require "clementine/clojurescript_engine/jruby"
|
|
6
|
+
elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
|
|
7
|
+
require "clementine/clojurescript_engine/mri"
|
|
8
|
+
else
|
|
9
|
+
raise LoadError, "No ClojureScriptEngine implementation for this ruby."
|
|
3
10
|
end
|
|
4
|
-
|
|
5
|
-
module Clementine
|
|
6
|
-
|
|
7
|
-
class ClojureScriptEngine
|
|
8
|
-
def initialize(file, options)
|
|
9
|
-
@file = file
|
|
10
|
-
@options = options
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def compile
|
|
14
|
-
@options = Clementine.options if @options.empty?
|
|
15
|
-
cl_opts = PersistentHashMap.create(convert_options(@options))
|
|
16
|
-
RT.loadResourceScript("cljs/closure.clj")
|
|
17
|
-
builder = RT.var("cljs.closure", "build")
|
|
18
|
-
builder.invoke(@file, cl_opts)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
#private
|
|
22
|
-
def convert_options(options)
|
|
23
|
-
opts = {}
|
|
24
|
-
options = options.empty? ? default_opts : options
|
|
25
|
-
options.each do |k, v|
|
|
26
|
-
cl_key = Keyword.intern(Clementine.ruby2clj(k.to_s))
|
|
27
|
-
case
|
|
28
|
-
when (v.kind_of? Symbol)
|
|
29
|
-
cl_value = Keyword.intern(Clementine.ruby2clj(v.to_s))
|
|
30
|
-
else
|
|
31
|
-
cl_value = v
|
|
32
|
-
end
|
|
33
|
-
opts[cl_key] = cl_value
|
|
34
|
-
end
|
|
35
|
-
opts
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def default_opts
|
|
39
|
-
key = "output_dir"
|
|
40
|
-
value = ""
|
|
41
|
-
if defined?(Rails)
|
|
42
|
-
value = File.join(Rails.root, "app", "assets", "javascripts", "clementine")
|
|
43
|
-
else
|
|
44
|
-
value = Dir.pwd
|
|
45
|
-
end
|
|
46
|
-
{key => value}
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|