Skip to content

Commit

Permalink
Make code self-host compatible
Browse files Browse the repository at this point in the history
Note that this patch does not port cuerdas.core/istr and cuerdas.core/<<.
  • Loading branch information
arichiardi authored and niwinz committed Aug 20, 2018
1 parent a844372 commit af52064
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -18,3 +18,4 @@ pom.xml.asc
/nashorn_code_cache
/.idea
/cuerdas.iml
.lumo_cache
5 changes: 5 additions & 0 deletions .travis.yml
Expand Up @@ -2,12 +2,17 @@ language: clojure
sudo: false
lein: lein

install:
- sudo ./scripts/install-ci-deps /usr/local
- lumo --version

script:
- lein test-all
- ./scripts/build
- nvm install v6.4.0
- node --version
- node out/tests.js
- lein test-lumo

branches:
only:
Expand Down
19 changes: 19 additions & 0 deletions doc/content.adoc
Expand Up @@ -66,6 +66,24 @@ argument and receives a `nil` will return `nil`.
====


== Self-host ClojureScript

.This library is compatible with self-host ClojureScript

[source, shell]
----
lumo -c $(clojure -Srepro -Sdeps '{:deps {funcool/cuerdas {:mvn/version "X.Y.Z"}}}' -Spath)
----

[source, clojure]
----
cljs.user=> (require '[cuerdas.core :as str])
;; => nil
cljs.user=> (str/collapse-whitespace " foo bar ")
;; => "foo bar"
----


== Functions by Use

=== Cleaning
Expand Down Expand Up @@ -209,6 +227,7 @@ another line

String interpolation macro. Enables easy string formating allowing
symbol substitutions and simple expression evaluation.
At the moment not compatible with self-host ClojureScript.

[source, clojure]
----
Expand Down
21 changes: 15 additions & 6 deletions project.clj
Expand Up @@ -4,18 +4,27 @@
:license {:name "BSD (2-Clause)"
:url "http://opensource.org/licenses/BSD-2-Clause"}

:dependencies [[org.clojure/clojure "1.9.0" :scope "provided"]
[org.clojure/clojurescript "1.10.339" :scope "provided"]]
:dependencies []
:source-paths ["src" "assets"]
:test-paths ["test"]

:jar-exclusions [#"\.swp|\.swo|user.clj"]

:profiles
{:dev {:aliases {"test-all" ["with-profile" "dev,1.8:dev,1.7:dev" "test"]}
{:dev {:dependencies [[org.clojure/clojure "1.9.0" :scope "test"]
[org.clojure/clojurescript "1.10.339" :scope "test"]]
:aliases {"test-all" ["do" ["clean"] ["with-profile" "dev,1.8:dev,1.7:dev" "test"]]
"test-lumo" ["do" ["clean"] ["with-profile" "self-host" "tach" "lumo" "test"]]}
:plugins [[lein-ancient "0.6.15"]]}

:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
:1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}})

:self-host {:exclusions [org.clojure/clojure
org.clojure/clojurescript]
:tach {:test-runner-ns cuerdas.runner
:source-paths ["src" "test"]
:force-non-zero-exit-on-test-failure? true
:cache? false
:debug? true}
:plugins [[lein-tach "1.0.0"]]}

:1.8 {:dependencies [[org.clojure/clojure "1.8.0" :scope "test"]]}
:1.7 {:dependencies [[org.clojure/clojure "1.7.0" :scope "test"]]}})
24 changes: 24 additions & 0 deletions scripts/install-ci-deps
@@ -0,0 +1,24 @@
#!/usr/bin/env sh

set -eu

prefix_dir=${1:-}

if [ -z "$prefix_dir" ]; then
echo "Must pass prefix dir as first parameter"
exit 1
fi

bin_dir="$prefix_dir/bin"
lumo_bin="$bin_dir/lumo"

if [ ! -x "$lumo_bin" ]; then
tmp_dir=$(mktemp -d /tmp/lumo.XXXXXXXXXX) || { echo "Failed to create temp file"; exit 2; }
zip_path="$tmp_dir/lumo.zip"
curl -fsSJLo "$zip_path" https://github.com/anmonteiro/lumo/releases/download/1.8.0/lumo_linux64.zip
unzip -vp "$zip_path" lumo > "$lumo_bin"
chmod +x "$lumo_bin"
echo "Installed Lumo in $bin_dir"
else
echo "Not installing Lumo, already in $bin_dir"
fi
31 changes: 16 additions & 15 deletions test/cuerdas/core_tests.cljc
@@ -1,6 +1,5 @@
(ns cuerdas.core-tests
(:require #?(:cljs [cljs.test :as t]
:clj [clojure.test :as t])
(:require [clojure.test :as t]
[cuerdas.core :as str :include-macros true])
#?(:clj (:import (java.util Locale))))

Expand Down Expand Up @@ -441,19 +440,21 @@
(t/is (= "foo" (str/substr-between "---foo>>bar" "---" ">>")))
(t/is (= "foo" (str/substr-between "---foo>>bar--foo1>>bar" "---" ">>"))))

(t/testing "<<"
(let [v 2]
(t/is (= "the value is 2" (str/<< "the value is ~{v}")))
(t/is (= "the value is 3" (str/<< "the value is ~(inc v)")))
(t/is (= "the value is 4" (str/<< "the value is ~(-> v inc inc)")))
(t/is (= "the value is 2" (str/<< "the value" " is ~{v}")))))

(t/testing "istr"
(let [v 2]
(t/is (= "the value is 2" (str/istr "the value is ~{v}")))
(t/is (= "the value is 3" (str/istr "the value is ~(inc v)")))
(t/is (= "the value is 4" (str/istr "the value is ~(-> v inc inc)")))
(t/is (= "the value is 2" (str/istr "the value" " is ~{v}")))))
#?(:clj
(t/testing "<<"
(let [v 2]
(t/is (= "the value is 2" (str/<< "the value is ~{v}")))
(t/is (= "the value is 3" (str/<< "the value is ~(inc v)")))
(t/is (= "the value is 4" (str/<< "the value is ~(-> v inc inc)")))
(t/is (= "the value is 2" (str/<< "the value" " is ~{v}"))))))

#?(:clj
(t/testing "istr"
(let [v 2]
(t/is (= "the value is 2" (str/istr "the value is ~{v}")))
(t/is (= "the value is 3" (str/istr "the value is ~(inc v)")))
(t/is (= "the value is 4" (str/istr "the value is ~(-> v inc inc)")))
(t/is (= "the value is 2" (str/istr "the value" " is ~{v}"))))))

(t/testing "<<-"
(t/is (= "first line\n indented two\n\n indented four\n"
Expand Down
5 changes: 5 additions & 0 deletions test/cuerdas/runner.cljc
@@ -0,0 +1,5 @@
(ns cuerdas.runner
(:require [clojure.test :as test]
[cuerdas.core-tests]))

(test/run-tests 'cuerdas.core-tests)

0 comments on commit af52064

Please sign in to comment.