Permalink
Browse files

Clean up and refactor CLJS port

- Change CLJS namespace to cljs.tools.cli
  (precedents: cljs.core.async, cljs.core.typed)
- Use leiningen.dalap middleware
- Favor lein-dalap ^{:cljs form} replacement metadata over #_(:cljs form)
  for better legibility
  • Loading branch information...
guns committed Dec 10, 2013
1 parent d63f158 commit de2786e5b7aac1a1bf25be330463a2b8afe415d6
Showing with 22 additions and 19 deletions.
  1. +1 −0 project.clj
  2. +1 −1 src/main/clojure/cljs/tools/cli.cljs
  3. +20 −18 src/test/clojure/clojure/tools/cli_test.clj
View
@@ -19,6 +19,7 @@
:plugins [[lein-cljsbuild "1.0.0"]
[com.birdseye-sw/lein-dalap "0.1.1"]
[com.cemerick/clojurescript.test "0.2.1"]]
+ :hooks [leiningen.dalap]
:cljsbuild {:builds [{:source-paths ["src/main/clojure/cljs"
"src/test/clojure/cljs"]
:compiler {:output-to "target/cli_test.js"
@@ -1,4 +1,4 @@
-(ns clojure.tools.cli
+(ns cljs.tools.cli
{:author "Sung Pae"}
(:require [clojure.string :as s]
goog.string.format
@@ -1,14 +1,18 @@
-(ns clojure.tools.cli-test (:require [clojure.tools.cli :as cli]
- #_(:cljs cemerick.cljs.test))
- (:use [clojure.string :only [join]]
- [clojure.tools.cli :only [parse-opts summarize]]
- ^:clj [clojure.test :only [deftest is testing]])
+(ns ^{:cljs 'cljs.tools.cli-test}
+ clojure.tools.cli-test
+ ^{:cljs
+ '(:require [cljs.tools.cli :as cli :refer [parse-opts summarize]]
+ [clojure.string :refer [join]]
+ cemerick.cljs.test)}
+ (:use [clojure.tools.cli :as cli :only [parse-opts summarize]]
+ [clojure.string :only [join]]
+ [clojure.test :only [deftest is testing]])
#_(:cljs (:require-macros [cemerick.cljs.test :refer [deftest is testing]])))
;; Refer private vars
-(def tokenize-args ^:clj #'cli/tokenize-args #_(:cljs cli/tokenize-args))
-(def compile-option-specs ^:clj #'cli/compile-option-specs #_(:cljs cli/compile-option-specs))
-(def parse-option-tokens ^:clj #'cli/parse-option-tokens #_(:cljs cli/parse-option-tokens))
+(def tokenize-args ^{:cljs cli/tokenize-args} #'cli/tokenize-args)
+(def compile-option-specs ^{:cljs cli/compile-option-specs} #'cli/compile-option-specs)
+(def parse-option-tokens ^{:cljs cli/parse-option-tokens} #'cli/parse-option-tokens)
(deftest test-tokenize-args
(testing "expands clumped short options"
@@ -45,13 +49,13 @@
[nil nil nil "DESC"]
["-f" "--foo" "FOO" "desc"]])))
(testing "throws AssertionError on unset :id or duplicate :id, :short-opt, :long-opt"
- (is (thrown? ^:clj AssertionError #_(:cljs js/Error)
+ (is (thrown? ^{:cljs js/Error} AssertionError
(compile-option-specs [["-a" :id nil]])))
- (is (thrown? ^:clj AssertionError #_(:cljs js/Error)
+ (is (thrown? ^{:cljs js/Error} AssertionError
(compile-option-specs [["-a" "--alpha"] ["-b" :id :alpha]])))
- (is (thrown? ^:clj AssertionError #_(:cljs js/Error)
+ (is (thrown? ^{:cljs js/Error} AssertionError
(compile-option-specs [{:id :a :short-opt "-a"} {:id :b :short-opt "-a"}])))
- (is (thrown? ^:clj AssertionError #_(:cljs js/Error)
+ (is (thrown? ^{:cljs js/Error} AssertionError
(compile-option-specs [{:id :alpha :long-opt "--alpha"} {:id :beta :long-opt "--alpha"}]))))
(testing "desugars `--long-opt=value`"
(is (= (map (juxt :id :long-opt :required)
@@ -71,9 +75,9 @@
(seq (filter (partial re-seq re) coll)))
(defn parse-int [x]
- ^:clj (Integer/parseInt x)
- #_(:cljs (do (assert (re-seq #"^\d" x))
- (js/parseInt x))))
+ ^{:cljs (do (assert (re-seq #"^\d" x))
+ (js/parseInt x))}
+ (Integer/parseInt x))
(deftest test-parse-option-tokens
(testing "parses and validates option arguments"
@@ -165,9 +169,7 @@
(let [specs [["-f" "--file PATH"
:validate [#(not= \/ (first %)) "Must be a relative path"]]
["-p" "--port PORT"
- :parse-fn (fn [x]
- ^:clj parse-int
- #_(:cljs (do (assert (re-seq #"^\d" x)) (js/parseInt x))))
+ :parse-fn parse-int
:validate [#(< 0 % 0x10000) "Must be between 0 and 65536"]]]
errors (:errors (parse-opts ["-f" "/foo/bar" "-p0"] specs))]
(is (has-error? #"Must be a relative path" errors))

0 comments on commit de2786e

Please sign in to comment.