This project shows how much effort was required to port 4Clojure solutions written in Clojure to ClojureScript (see commit log). It also documents some approaches to execute unit test for various ClojureScript host environments.
Warning! Please do not use this project as a source of hints for solving 4clojure problems. It's best to first solve the problem and only after that looking at others solutions.
All unit tests are in file test/cljc_4clojure_solutions/core_test.cljc
. All non trivial solutions can be found in file src/cljc_4clojure_solutions/core.cljc
. All other files are just "infrastructure".
- Install Java 8.
- Install Leiningen.
Execute lein compile :all
. JVM bytecode .class files can be found in target
directory.
-
By Leiningen command.
Execute
lein test
. -
From REPL.
Execute
lein repl
. Then from the REPL execute:(require '[clojure.test :as t]) (require 'cljc-4clojure-solutions.core-test) (t/run-tests 'cljc-4clojure-solutions.core-test)
In REPL it's easy to test functions directly:
(require '[cljc-4clojure-solutions.core :as core]) (core/num->roman 578) (core/prime 40)
Compile by executing one of commands below. The result is testable.js
file under /resources/private/js
directory.
lein cljsbuild once none # no optimization
lein cljsbuild once whitespace # whitespace optimization
lein cljsbuild once simple # simple optimization
lein cljsbuild once advanced # advanced optimization
lein cljsbuild once node # compilation for Node.js
lein cljsbuild once brepl # compilation for browser REPL
Make sure PhantomJS is correctly installed:
$ phantomjs -v
2.1.3-dev-release
Execute command:
lein doo phantom whitespace once
The whitespace
can be exchanged with simple
or advanced
.
Make sure Node.js is correctly installed:
$ node -v
v8.9.4
Execute command:
lein doo node node once
Execute command:
lein doo nashorn whitespace once
The whitespace
can be exchanged with simple
or advanced
.
Make sure Rhino is correctly installed:
rhino -help
Execute command:
lein doo rhino whitespace once
The whitespace
can be exchanged with simple
or advanced
.
Compile sources to JavaScript:
lein cljsbuild once brepl
Open REPL:
lein repl
In REPL start Weasel server:
(start-weasel)
It will wait for connection from browser. Open resources/private/brepl.html
in modern browser. This causes browser to connect to Weasel and changes REPL prompt to cljs.user=>
.
Run tests by executing:
(require '[cljs.test :as t])
(require 'cljc-4clojure-solutions.core-test)
(t/run-tests 'cljc-4clojure-solutions.core-test)
In REPL it's easy to test functions directly:
(require '[cljc-4clojure-solutions.core :as core])
(core/num->roman 578)
(core/prime 40)
Open REPL:
lein repl
In REPL switch to Node.js REPL:
(start-node)
Run tests by executing:
(require '[cljs.test :as t])
(require 'cljc-4clojure-solutions.core-test)
(t/run-tests 'cljc-4clojure-solutions.core-test)
In REPL it's easy to test functions directly:
(require '[cljc-4clojure-solutions.core :as core])
(core/num->roman 578)
(core/prime 40)
Proceed the same way as with Node.js REPL but run (start-nashorn)
instead of (start-node)
.
Proceed the same way as with Node.js REPL but run (start-rhino)
instead of (start-node)
.
Make sure Planck is correctly installed:
$ planck -h
Run planck with:
planck -c src:test
In planck execute:
(require '[clojure.test :as t])
(require 'cljc-4clojure-solutions.core-test)
(t/run-tests 'cljc-4clojure-solutions.core-test)
Copyright © 2018 Marcin Waldowski
Distributed under the Eclipse Public License version 1.0