pax_global_header00006660000000000000000000000064142427677440014533gustar00rootroot0000000000000052 comment=526dd862555ca7ee9488f818ca2e1108d8208a0b camel-snake-kebab-version-0.4.3/000077500000000000000000000000001424276774400164445ustar00rootroot00000000000000camel-snake-kebab-version-0.4.3/.circleci/000077500000000000000000000000001424276774400202775ustar00rootroot00000000000000camel-snake-kebab-version-0.4.3/.circleci/config.yml000066400000000000000000000026151424276774400222730ustar00rootroot00000000000000# Clojure CircleCI 2.0 configuration file # # Check https://circleci.com/docs/2.0/language-clojure/ for more details # version: 2 jobs: build: docker: # specify the version you desire here - image: circleci/clojure:lein-2.9.1-node # Specify service dependencies here if necessary # CircleCI maintains a library of pre-built images # documented at https://circleci.com/docs/2.0/circleci-images/ # - image: circleci/postgres:9.4 working_directory: ~/repo environment: LEIN_ROOT: "true" # Customize the JVM maximum heap limit JVM_OPTS: -Xmx3200m steps: - checkout # Download and cache dependencies - restore_cache: keys: - v1-dependencies-{{ checksum "project.clj" }} # fallback to using the latest cache if no exact match is found - v1-dependencies- - run: lein deps - save_cache: paths: - ~/.m2 key: v1-dependencies-{{ checksum "project.clj" }} # install planck - run: sudo apt-get update - run: sudo apt-get install libgnutls30 - run: sudo apt-get install libjavascriptcoregtk-4.0-18 - run: sudo apt-get install libzip4 - run: wget https://planck-repl.org/releases/2.25.0-debian-9.0-x86_64/planck && chmod a+x planck && sudo mv planck /usr/local/bin # run tests! - run: lein test-all camel-snake-kebab-version-0.4.3/.github/000077500000000000000000000000001424276774400200045ustar00rootroot00000000000000camel-snake-kebab-version-0.4.3/.github/CODEOWNERS000066400000000000000000000000111424276774400213670ustar00rootroot00000000000000* @qerub camel-snake-kebab-version-0.4.3/.gitignore000066400000000000000000000001641424276774400204350ustar00rootroot00000000000000/target /lib /classes /checkouts pom.xml .nrepl-port /out *.jar *.class .lein-deps-sum .lein-failures .lein-plugins camel-snake-kebab-version-0.4.3/AUTHORS.md000066400000000000000000000001311424276774400201060ustar00rootroot00000000000000* Christoffer Sawicki * ToBeReplaced * Brendan Bates * Vincent Pizzo * Sebastian Bensusancamel-snake-kebab-version-0.4.3/LICENSE.txt000066400000000000000000000260671424276774400203020ustar00rootroot00000000000000Eclipse Public License - v 1.0 THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 1. DEFINITIONS "Contribution" means: a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and b) in the case of each subsequent Contributor: i) changes to the Program, and ii) additions to the Program; where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. "Contributor" means any person or entity that distributes the Program. "Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. "Program" means the Contributions distributed in accordance with this Agreement. "Recipient" means anyone who receives the Program under this Agreement, including all Contributors. 2. GRANT OF RIGHTS a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. 3. REQUIREMENTS A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: a) it complies with the terms and conditions of this Agreement; and b) its license agreement: i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. When the Program is made available in source code form: a) it must be made available under this Agreement; and b) a copy of this Agreement must be included with each copy of the Program. Contributors may not remove or alter any copyright notices contained within the Program. Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. 4. COMMERCIAL DISTRIBUTION Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. 5. NO WARRANTY EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. 6. DISCLAIMER OF LIABILITY EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 7. GENERAL If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.camel-snake-kebab-version-0.4.3/NEWS.md000066400000000000000000000022741424276774400175470ustar00rootroot00000000000000# News ## 2022-05-23: 0.4.3 * `transform-keys` now keeps metadata. ## 2020-10-18: 0.4.2 * Supports self-hosted ClojureScript. * Splits strings consistently between CLJ and CLJS. * Doesn't throw NPE when input only consists of separator(s). * Doesn't throw AssertionError on `nil` input. ## 2019-11-24: 0.4.1 * Declares macro-generated symbols so that tools like Cursive that use static analysis can find them. ## 2016-04-16: 0.4.0 - The Malmö Release * Uses reader conditionals instead of cljx. * Requires Clojure[Script] version >= 1.7. ## 2015-01-17: 0.3.0 * Optional new argument `:separator` allows you to control how words are separated. * **Breaking changes:** * `CamelCase` has been renamed to `PascalCase`. * `SNAKE_CASE` has been renamed to `SCREAMING_SNAKE_CASE`. * `Snake_case` has been removed. * The above changes makes the library AOT compilable on case-insensitive filesystems. In practice, this means you can e.g. use `lein ring uberwar` on Windows and OS X. ## 2014-07-28: 0.2.0 * Supports ClojureScript! * Has new regex-free internals. * Handles non-ASCII chars better. * **Breaking change:** The namespace `camel-snake-kebab` has been renamed to `camel-snake-kebab.core`. camel-snake-kebab-version-0.4.3/ORIGINATOR000066400000000000000000000000071424276774400200410ustar00rootroot00000000000000@qerub camel-snake-kebab-version-0.4.3/README.md000066400000000000000000000006571424276774400177330ustar00rootroot00000000000000[![Clojars Project](https://img.shields.io/clojars/v/camel-snake-kebab.svg)](https://clojars.org/camel-snake-kebab) [![cljdoc badge](https://cljdoc.org/badge/camel-snake-kebab)](https://cljdoc.org/d/camel-snake-kebab/camel-snake-kebab/CURRENT) [![CircleCI](https://circleci.com/gh/clj-commons/camel-snake-kebab.svg?style=svg)](https://circleci.com/gh/clj-commons/camel-snake-kebab) GOTO https://clj-commons.org/camel-snake-kebab/ camel-snake-kebab-version-0.4.3/deps.edn000066400000000000000000000000031424276774400200600ustar00rootroot00000000000000{} camel-snake-kebab-version-0.4.3/project.clj000066400000000000000000000022031424276774400206010ustar00rootroot00000000000000(defproject camel-snake-kebab "0.4.3" :min-lein-version "2.5.2" :description "A library for word case conversions." :url "https://clj-commons.org/camel-snake-kebab/" :license {:name "Eclipse Public License 1.0" :url "http://www.eclipse.org/legal/epl-v10.html"} :scm {:name "git" :url "https://github.com/clj-commons/camel-snake-kebab"} :profiles {:dev {:dependencies [[org.clojure/clojure "1.10.0"] [org.clojure/clojurescript "1.10.520" :scope "provided"]] :plugins [[lein-cljsbuild "1.1.3"] [lein-doo "0.1.11"]]}} :jar-exclusions [#"\.DS_Store"] :source-paths ["src"] :test-paths ["test"] :cljsbuild {:builds [{:id "test" :source-paths ["src" "test"] :compiler {:output-to "target/testable.js" :main "camel-snake-kebab.test-runner" :target :nodejs :optimizations :simple}}]} :aliases {"test-all" ["do" "test," "doo" "node" "test" "once," "doo" "planck" "test" "once"]}) camel-snake-kebab-version-0.4.3/src/000077500000000000000000000000001424276774400172335ustar00rootroot00000000000000camel-snake-kebab-version-0.4.3/src/camel_snake_kebab/000077500000000000000000000000001424276774400226215ustar00rootroot00000000000000camel-snake-kebab-version-0.4.3/src/camel_snake_kebab/core.cljc000066400000000000000000000040371424276774400244120ustar00rootroot00000000000000(ns camel-snake-kebab.core (:require [clojure.string] [camel-snake-kebab.internals.misc :as misc] #?(:clj [camel-snake-kebab.internals.macros :refer [defconversion]] :cljs [camel-snake-kebab.internals.alter-name])) ;; Needed for expansion of defconversion #?(:cljs (:require-macros [camel-snake-kebab.internals.macros :refer [defconversion]]))) (declare ->PascalCase ->Camel_Snake_Case ->camelCase ->SCREAMING_SNAKE_CASE ->snake_case ->kebab-case ->HTTP-Header-Case ->PascalCaseKeyword ->camelCaseKeyword ->SCREAMING_SNAKE_CASE_KEYWORD ->snake_case_keyword ->kebab-case-keyword ->Camel_Snake_Case_Keyword ->HTTP-Header-Case-Keyword ->PascalCaseString ->camelCaseString ->SCREAMING_SNAKE_CASE_STRING ->snake_case_string ->kebab-case-string ->Camel_Snake_Case_String ->HTTP-Header-Case-String ->PascalCaseSymbol ->camelCaseSymbol ->SCREAMING_SNAKE_CASE_SYMBOL ->snake_case_symbol ->kebab-case-symbol ->Camel_Snake_Case_Symbol ->HTTP-Header-Case-Symbol) (defn convert-case "Converts the case of a string according to the rule for the first word, remaining words, and the separator." [first-fn rest-fn sep s & rest] (apply misc/convert-case first-fn rest-fn sep s rest)) ;; These are fully qualified to workaround some issue with ClojureScript: (defconversion "PascalCase" clojure.string/capitalize clojure.string/capitalize "") (defconversion "Camel_Snake_Case" clojure.string/capitalize clojure.string/capitalize "_") (defconversion "camelCase" clojure.string/lower-case clojure.string/capitalize "" ) (defconversion "SCREAMING_SNAKE_CASE" clojure.string/upper-case clojure.string/upper-case "_") (defconversion "snake_case" clojure.string/lower-case clojure.string/lower-case "_") (defconversion "kebab-case" clojure.string/lower-case clojure.string/lower-case "-") (defconversion "HTTP-Header-Case" camel-snake-kebab.internals.misc/capitalize-http-header camel-snake-kebab.internals.misc/capitalize-http-header "-") camel-snake-kebab-version-0.4.3/src/camel_snake_kebab/extras.cljc000066400000000000000000000004561424276774400247710ustar00rootroot00000000000000(ns camel-snake-kebab.extras (:require [clojure.walk :refer [postwalk]])) (defn transform-keys "Recursively transforms all map keys in coll with t." [t coll] (letfn [(transform [[k v]] [(t k) v])] (postwalk (fn [x] (if (map? x) (with-meta (into {} (map transform x)) (meta x)) x)) coll))) camel-snake-kebab-version-0.4.3/src/camel_snake_kebab/internals/000077500000000000000000000000001424276774400246205ustar00rootroot00000000000000camel-snake-kebab-version-0.4.3/src/camel_snake_kebab/internals/alter_name.cljc000066400000000000000000000011651424276774400275670ustar00rootroot00000000000000(ns ^:no-doc camel-snake-kebab.internals.alter-name #?(:clj (:import (clojure.lang Keyword Symbol)))) (defprotocol AlterName (alter-name [this f] "Alters the name of this with f.")) (extend-protocol AlterName #?(:clj String :cljs string) (alter-name [this f] (-> this f)) Keyword (alter-name [this f] (if (namespace this) (throw (ex-info "Namespaced keywords are not supported" {:input this})) (-> this name f keyword))) Symbol (alter-name [this f] (if (namespace this) (throw (ex-info "Namespaced symbols are not supported" {:input this})) (-> this name f symbol)))) camel-snake-kebab-version-0.4.3/src/camel_snake_kebab/internals/macros.cljc000066400000000000000000000026511424276774400267450ustar00rootroot00000000000000(ns ^:no-doc camel-snake-kebab.internals.macros #?(:cljs (:refer-clojure :exclude [resolve])) (:require [camel-snake-kebab.internals.alter-name :refer [alter-name]] [camel-snake-kebab.internals.misc :refer [convert-case]])) #?(:cljs (defn resolve [sym] ;; On self-hosted ClojureScript, macros are evaluated under the `:cljs` conditional branch ;; In that case, we need to use `eval` in order to resolve variables instead of `resolve` (eval `(~'var ~sym)))) (defn type-preserving-function [case-label first-fn rest-fn sep] `(defn ~(symbol (str "->" case-label)) [s# & rest#] (let [convert-case# #(apply convert-case ~first-fn ~rest-fn ~sep % rest#)] (alter-name s# convert-case#)))) (defn type-converting-functions [case-label first-fn rest-fn sep] (letfn [(make-name [type-label] (->> (str case-label " " type-label) (convert-case (resolve first-fn) (resolve rest-fn) sep) (str "->") (symbol)))] (for [[type-label type-converter] {"string" `identity "symbol" `symbol "keyword" `keyword}] `(defn ~(make-name type-label) [s# & rest#] (~type-converter (apply convert-case ~first-fn ~rest-fn ~sep (name s#) rest#)))))) (defmacro defconversion [case-label first-fn rest-fn sep] `(do ~(type-preserving-function case-label first-fn rest-fn sep) ~@(type-converting-functions case-label first-fn rest-fn sep))) camel-snake-kebab-version-0.4.3/src/camel_snake_kebab/internals/misc.cljc000066400000000000000000000012621424276774400264110ustar00rootroot00000000000000(ns ^:no-doc camel-snake-kebab.internals.misc (:require [camel-snake-kebab.internals.string-separator :refer [split generic-separator]] [clojure.string :refer [join upper-case capitalize]])) (defn convert-case [first-fn rest-fn sep s & {:keys [separator] :or {separator generic-separator}}] (if-let [[first & rest] (seq (split separator s))] (join sep (cons (first-fn first) (map rest-fn rest))) "")) (def upper-case-http-headers #{"CSP" "ATT" "WAP" "IP" "HTTP" "CPU" "DNT" "SSL" "UA" "TE" "WWW" "XSS" "MD5"}) (defn capitalize-http-header [s] (or (upper-case-http-headers (upper-case s)) (capitalize s))) camel-snake-kebab-version-0.4.3/src/camel_snake_kebab/internals/string_separator.cljc000066400000000000000000000053531424276774400310510ustar00rootroot00000000000000(ns ^:no-doc camel-snake-kebab.internals.string-separator (:require [clojure.string :as string]) #?(:clj (:import (java.util.regex Pattern)))) #?(:clj (set! *warn-on-reflection* true)) (defprotocol StringSeparator (split [this s] ": StringSeparator -> String -> NonEmptySeq[String]")) #?(:clj (letfn [(split-by-pattern [^Pattern p, ^String s] (string/split s p)) ;; These could be optimized e.g. by using StringUtils in Apache Commons: (split-by-string [^String p, ^String s] (split-by-pattern (-> p Pattern/quote Pattern/compile) s)) (split-by-char [^Character p, ^String s] (split-by-string (String/valueOf p) s))] (extend Pattern StringSeparator {:split split-by-pattern}) (extend String StringSeparator {:split split-by-string}) (extend Character StringSeparator {:split split-by-char})) :cljs (extend-protocol StringSeparator ;; Notes: ;; * Characters are just strings in ClojureScript. ;; * Using js/RegExp generates a warning, but what's the right way? js/RegExp (split [this s] (string/split s this)) string (split [this s] (string/split s this)))) (defn classify-char [c] (case c (\0 \1 \2 \3 \4 \5 \6 \7 \8 \9) :number (\- \_ \space \tab \newline \o013 \formfeed \return) :whitespace (\a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y \z) :lower (\A \B \C \D \E \F \G \H \I \J \K \L \M \N \O \P \Q \R \S \T \U \V \W \X \Y \Z) :upper :other)) (defn generic-split [ss] (let [cs (mapv classify-char ss) ss-length #?(:clj (.length ^String ss) :cljs (.-length ss))] (loop [result (transient []), start 0, current 0] (let [next (inc current) result+new (fn [end] (if (> end start) (conj! result (.substring ^String ss start end)) result))] (cond (>= current ss-length) (or (seq (persistent! (result+new current))) ;; Return this instead of an empty seq: [""]) (= (nth cs current) :whitespace) (recur (result+new current) next next) (let [[a b c] (subvec cs current)] ;; This expression is not pretty, ;; but it compiles down to sane JavaScript. (or (and (not= a :upper) (= b :upper)) (and (not= a :number) (= b :number)) (and (= a :upper) (= b :upper) (= c :lower)))) (recur (result+new next) next next) :else (recur result start next)))))) (def generic-separator (reify StringSeparator (split [_ s] (generic-split s)))) camel-snake-kebab-version-0.4.3/test/000077500000000000000000000000001424276774400174235ustar00rootroot00000000000000camel-snake-kebab-version-0.4.3/test/camel_snake_kebab/000077500000000000000000000000001424276774400230115ustar00rootroot00000000000000camel-snake-kebab-version-0.4.3/test/camel_snake_kebab/core_test.cljc000066400000000000000000000046271424276774400256460ustar00rootroot00000000000000(ns camel-snake-kebab.core-test (:require [camel-snake-kebab.core :as csk] #?(:clj [clojure.test :refer :all] :cljs [cljs.test :refer-macros [deftest testing is are]])) #?(:clj (:import (clojure.lang ExceptionInfo)))) (def zip (partial map vector)) (deftest format-case-test (testing "examples" (are [x y] (= x y) 'fluxCapacitor (csk/->camelCase 'flux-capacitor) "I_AM_CONSTANT" (csk/->SCREAMING_SNAKE_CASE "I am constant") :object-id (csk/->kebab-case :object_id) "X-SSL-Cipher" (csk/->HTTP-Header-Case "x-ssl-cipher") :object-id (csk/->kebab-case-keyword "object_id")) :s3_key (csk/->snake_case :s3-key :separator \-)) (testing "rejection of namespaced keywords and symbols" (is (thrown? ExceptionInfo (csk/->PascalCase (keyword "a" "b")))) (is (thrown? ExceptionInfo (csk/->PascalCase (symbol "a" "b"))))) (testing "all the type preserving functions" (let [inputs ["FooBar" "fooBar" "FOO_BAR" "foo_bar" "foo-bar" "Foo_Bar"] functions [csk/->PascalCase csk/->camelCase csk/->SCREAMING_SNAKE_CASE csk/->snake_case csk/->kebab-case csk/->Camel_Snake_Case] formats [identity keyword symbol]] (doseq [input inputs, format formats, [output function] (zip inputs functions)] (is (= (format output) (function (format input))))))) (testing "some of the type converting functions" (are [x y] (= x y) :FooBar (csk/->PascalCaseKeyword 'foo-bar) "FOO_BAR" (csk/->SCREAMING_SNAKE_CASE_STRING :foo-bar) 'foo-bar (csk/->kebab-case-symbol "foo bar"))) (testing "handling of blank input string" (is (= "" (csk/->kebab-case ""))) (is (= "" (csk/->kebab-case " ")))) (testing "handling of input consisting of only separator(s)" (is (= "" (csk/->kebab-case "a" :separator \a))) (is (= "" (csk/->kebab-case "aa" :separator \a))))) (deftest http-header-case-test (are [x y] (= x (csk/->HTTP-Header-Case y)) "User-Agent" "user-agent" "DNT" "dnt" "Remote-IP" "remote-ip" "TE" "te" "UA-CPU" "ua-cpu" "X-SSL-Cipher" "x-ssl-cipher" "X-WAP-Profile" "x-wap-profile" "X-XSS-Protection" "x-xss-protection")) camel-snake-kebab-version-0.4.3/test/camel_snake_kebab/extras_test.cljc000066400000000000000000000030671424276774400262210ustar00rootroot00000000000000(ns camel-snake-kebab.extras-test (:require [camel-snake-kebab.core :as csk] [camel-snake-kebab.extras :refer [transform-keys]] #?(:clj [clojure.test :refer :all] :cljs [cljs.test :refer-macros [deftest testing is are]]))) (deftest transform-keys-test (are [x y] (= x (transform-keys csk/->kebab-case-keyword y)) nil nil {} {} [] [] {:total-books 0 :all-books []} {'total_books 0 "allBooks" []} [{:the-author "Dr. Seuss" :the-title "Green Eggs and Ham"}] [{'the-Author "Dr. Seuss" "The_Title" "Green Eggs and Ham"}] {:total-books 1 :all-books [{:the-author "Dr. Seuss" :the-title "Green Eggs and Ham"}]} {'total_books 1 "allBooks" [{'THE_AUTHOR "Dr. Seuss" "the_Title" "Green Eggs and Ham"}]})) (deftest transform-keys-with-metadata-test (are [x y metadata] (let [y-with-metadata (with-meta y metadata) y-transformed (transform-keys csk/->kebab-case-keyword y-with-metadata)] (and (= x y-transformed) (= metadata (meta y-transformed)))) {} {} {:type-name :metadata-type} [] [] {:type-name :check} {:total-books 0 :all-books []} {'total_books 0 "allBooks" []} {:type-name :metadata-type} [{:the-author "Dr. Seuss" :the-title "Green Eggs and Ham"}] [{'the-Author "Dr. Seuss" "The_Title" "Green Eggs and Ham"}] {:type-name :metadata-type} {:total-books 1 :all-books [{:the-author "Dr. Seuss" :the-title "Green Eggs and Ham"}]} {'total_books 1 "allBooks" [{'THE_AUTHOR "Dr. Seuss" "the_Title" "Green Eggs and Ham"}]} {:type-name :metadata-type})) camel-snake-kebab-version-0.4.3/test/camel_snake_kebab/internals/000077500000000000000000000000001424276774400250105ustar00rootroot00000000000000camel-snake-kebab-version-0.4.3/test/camel_snake_kebab/internals/string_separator_test.cljc000066400000000000000000000023001424276774400322650ustar00rootroot00000000000000(ns camel-snake-kebab.internals.string-separator-test (:require [camel-snake-kebab.internals.string-separator :refer [split generic-separator]] #?(:clj [clojure.test :refer :all] :cljs [cljs.test :refer-macros [deftest testing is are]]))) (deftest split-test (testing "regex, string and character separators" (are [sep] (and (= ["foo" "bar"] (split sep "foo.bar")) (= [""] (split sep ""))) #"\." "." \.)) (testing "input consisting of separator(s)" (is (empty? (split "x" "x"))) (is (empty? (split "x" "xx")))) (testing "generic separator" (are [x y] (= x (split generic-separator y)) [""] "" [""] " " ["x"] " x " ["foo" "bar"] "foo bar" ["foo" "bar"] "foo\n\tbar" ["foo" "bar"] "foo-bar" ["foo" "Bar"] "fooBar" ["Foo" "Bar"] "FooBar" ["foo" "bar"] "foo_bar" ["FOO" "BAR"] "FOO_BAR" ["räksmörgås"] "räksmörgås" ["IP" "Address"] "IPAddress" ["Adler" "32"] "Adler32" ["Inet" "4" "Address"] "Inet4Address" ["Arc" "2" "D"] "Arc2D" ["a" "123b"] "a123b" ["A" "123" "B"] "A123B"))) camel-snake-kebab-version-0.4.3/test/camel_snake_kebab/test_runner.cljs000066400000000000000000000006561424276774400262450ustar00rootroot00000000000000(ns camel-snake-kebab.test-runner (:require [cljs.test :as test] [doo.runner :refer-macros [doo-all-tests doo-tests]] [camel-snake-kebab.core-test] [camel-snake-kebab.extras-test] [camel-snake-kebab.internals.string-separator-test])) (doo-tests 'camel-snake-kebab.core-test 'camel-snake-kebab.extras-test 'camel-snake-kebab.internals.string-separator-test)