|
| 1 | +;; clojure.repl parity (F-011). |
| 2 | +(ns suites.repl-test |
| 3 | + (:require [clojure.test :refer [deftest is testing]] |
| 4 | + [clojure.repl :as repl])) |
| 5 | + |
| 6 | +;; --- demunge --- |
| 7 | +;; demunge maps every `$` (the JVM nested-class separator) to `/`, on top of |
| 8 | +;; reversing the munge char tokens. cljw reversed the tokens but left `$` |
| 9 | +;; in place, found while writing the dev tooling in cljw. |
| 10 | +(deftest demunge-maps-dollar-to-slash |
| 11 | + (testing "the class$fn separator becomes ns/fn" |
| 12 | + (is (= "clojure.core/map" (repl/demunge "clojure.core$map")))) |
| 13 | + (testing "every $ maps to / (nested classes)" |
| 14 | + (is (= "a/b/c" (repl/demunge "a$b$c")))) |
| 15 | + (testing "$ maps alongside the munge tokens" |
| 16 | + (is (= "foo/fn?" (repl/demunge "foo$fn_QMARK_"))) |
| 17 | + (is (= "//x" (repl/demunge "_SLASH_$x")))) |
| 18 | + (testing "a name with no $ still reverses the munge tokens" |
| 19 | + (is (= "no-dollar" (repl/demunge "no_dollar"))))) |
| 20 | + |
| 21 | +;; --- munge (clojure.core, the inverse of demunge) --- |
| 22 | +;; Escapes every character illegal in a Java identifier as a `_TOKEN_`, |
| 23 | +;; preserving the argument's type (string or symbol). |
| 24 | +(deftest munge-escapes-special-chars |
| 25 | + (testing "string in, string out" |
| 26 | + (is (= "foo_bar_QMARK_" (munge "foo-bar?"))) |
| 27 | + (is (= "a_SLASH_b.c_d" (munge "a/b.c-d"))) |
| 28 | + (is (= "a_AMPERSAND_b_BAR_c" (munge "a&b|c")))) |
| 29 | + (testing "symbol in, symbol out" |
| 30 | + (is (= 'foo_bar_QMARK_ (munge 'foo-bar?))) |
| 31 | + (is (symbol? (munge 'a)))) |
| 32 | + (testing "a name needing no escaping is unchanged" |
| 33 | + (is (= "ok" (munge "ok")))) |
| 34 | + (testing "munge then demunge round-trips a hyphenated name" |
| 35 | + (is (= "foo-bar" (repl/demunge (munge "foo-bar")))))) |
| 36 | + |
| 37 | +;; --- stack-element-str (cljw-native frame map input) --- |
| 38 | +;; clj takes a JVM StackTraceElement; cljw has only Clojure frames, so it |
| 39 | +;; takes a frame map and produces clj's Clojure-frame render string. |
| 40 | +(deftest stack-element-str-renders-a-frame |
| 41 | + (testing "a frame map renders as ns/fn (file:line)" |
| 42 | + (is (= "clojure.core/map (core.clj:2743)" |
| 43 | + (repl/stack-element-str {:ns "clojure.core" :fn "map" :file "core.clj" :line 2743})))) |
| 44 | + (testing "a frame with no ns omits the ns/ prefix" |
| 45 | + (is (= "eval1 (NO_SOURCE_FILE:1)" |
| 46 | + (repl/stack-element-str {:fn "eval1" :file "NO_SOURCE_FILE" :line 1}))))) |
0 commit comments