├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── bb.edn ├── bb └── new_test.clj ├── deps.edn ├── flake.lock ├── flake.nix ├── package-lock.json ├── package.json ├── project.clj ├── shadow-cljs.edn ├── shell.nix ├── templates └── test-template.cljc └── test └── clojure ├── core_test ├── abs.cljc ├── aclone.cljc ├── add_watch.cljc ├── and.cljc ├── any_qmark.cljc ├── associative_qmark.cljc ├── bigdec.cljc ├── bigint.cljc ├── binding.cljc ├── bit_and.cljc ├── bit_and_not.cljc ├── bit_clear.cljc ├── bit_flip.cljc ├── bit_not.cljc ├── bit_or.cljc ├── bit_set.cljc ├── bit_shift_left.cljc ├── bit_shift_right.cljc ├── bit_test.cljc ├── bit_xor.cljc ├── boolean.cljc ├── bound_fn.cljc ├── bound_fn_star.cljc ├── butlast.cljc ├── byte.cljc ├── case.cljc ├── char.cljc ├── char_qmark.cljc ├── coll_qmark.cljc ├── compare.cljc ├── count.cljc ├── counted_qmark.cljc ├── dec.cljc ├── decimal_qmark.cljc ├── denominator.cljc ├── double.cljc ├── double_qmark.cljc ├── drop.cljc ├── drop_last.cljc ├── drop_while.cljc ├── eq.cljc ├── even_qmark.cljc ├── false_qmark.cljc ├── first.cljc ├── float.cljc ├── float_qmark.cljc ├── fnil.cljc ├── format.cljc ├── get.cljc ├── ident_qmark.cljc ├── identical_qmark.cljc ├── inc.cljc ├── int.cljc ├── int_qmark.cljc ├── integer_qmark.cljc ├── interleave.cljc ├── intern.cljc ├── interpose.cljc ├── keyword.cljc ├── keyword_qmark.cljc ├── list_qmark.cljc ├── long.cljc ├── map_qmark.cljc ├── max.cljc ├── min.cljc ├── minus.cljc ├── mod.cljc ├── name.cljc ├── namespace.cljc ├── nan_qmark.cljc ├── neg_int_qmark.cljc ├── neg_qmark.cljc ├── next.cljc ├── nil_qmark.cljc ├── not.cljc ├── not_eq.cljc ├── nth.cljc ├── nthnext.cljc ├── nthrest.cljc ├── num.cljc ├── number_qmark.cljc ├── number_range.cljc ├── numerator.cljc ├── odd_qmark.cljc ├── or.cljc ├── partial.cljc ├── plus.cljc ├── plus_squote.cljc ├── portability.cljc ├── pos_int_qmark.cljc ├── pos_qmark.cljc ├── pr_str.cljc ├── print_str.cljc ├── println_str.cljc ├── prn_str.cljc ├── qualified_ident_qmark.cljc ├── qualified_keyword_qmark.cljc ├── qualified_symbol_qmark.cljc ├── quot.cljc ├── rand.cljc ├── rand_int.cljc ├── ratio_qmark.cljc ├── rational_qmark.cljc ├── rationalize.cljc ├── reduce.cljc ├── rem.cljc ├── remove_watch.cljc ├── rest.cljc ├── reversible_qmark.cljc ├── second.cljc ├── seq.cljc ├── seq_qmark.cljc ├── seqable_qmark.cljc ├── sequential_qmark.cljc ├── set_qmark.cljc ├── short.cljc ├── shuffle.cljc ├── simple_ident_qmark.cljc ├── simple_keyword_qmark.cljc ├── simple_symbol_qmark.cljc ├── slash.cljc ├── some_qmark.cljc ├── sort.cljc ├── sorted_qmark.cljc ├── star.cljc ├── star_squote.cljc ├── str.cljc ├── string_qmark.cljc ├── subs.cljc ├── symbol.cljc ├── symbol_qmark.cljc ├── take.cljc ├── take_last.cljc ├── take_while.cljc ├── taps.cljc ├── true_qmark.cljc ├── unsigned_bit_shift_right.cljc ├── vector_qmark.cljc ├── with_out_str.cljc ├── with_precision.cljc ├── zero_qmark.cljc └── zipmap.cljc └── string_test ├── blank_qmark.cljc ├── capitalize.cljc ├── ends_with_qmark.cljc ├── escape.cljc ├── lower_case.cljc ├── reverse.cljc ├── starts_with_qmark.cljc └── upper_case.cljc /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: tests 2 | 3 | on: 4 | pull_request: 5 | branches: [main] 6 | push: 7 | branches: [main] 8 | workflow_dispatch: # Supports manual triggering 9 | 10 | env: 11 | # increment to "clear" the cache 12 | CACHE_VERSION: "v1" 13 | 14 | jobs: 15 | test: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - name: Prepare java 21 | uses: actions/setup-java@v4 22 | with: 23 | distribution: "temurin" 24 | java-version: "21" 25 | 26 | - name: Install clojure tools 27 | uses: DeLaGuardo/setup-clojure@13.2 28 | with: 29 | cli: 1.12.0.1530 30 | lein: 2.11.2 31 | 32 | - name: Cache clojure dependencies 33 | uses: actions/cache@v4 34 | with: 35 | path: | 36 | ~/.m2/repository 37 | ~/.gitlibs 38 | ~/.deps.clj 39 | # List all files containing dependencies: 40 | key: cljdeps-${{ env.CACHE_VERSION }}-${{ hashFiles('project.clj') }}-${{ hashFiles('deps.edn') }}-${{ hashFiles('bb.edn') }} 41 | restore-keys: cljdeps-${{ env.CACHE_VERSION }}- 42 | 43 | - name: Prepare node 44 | uses: actions/setup-node@v4 45 | with: 46 | node-version: "23.x" 47 | check-latest: true 48 | cache: 'npm' 49 | cache-dependency-path: "package-lock.json" 50 | 51 | - name: Install Node Dependencies 52 | run: npm ci 53 | 54 | - name: Compile ClojureScript Tests 55 | run: npm run build 56 | 57 | - name: Run ClojureScript Tests 58 | run: npm test 59 | 60 | - name: Run Clojure tests 61 | run: lein test 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | profiles.clj 5 | pom.xml 6 | pom.xml.asc 7 | *.jar 8 | *.class 9 | /.lein-* 10 | /.nrepl-port 11 | /.prepl-port 12 | .hgignore 13 | .hg/ 14 | /.clj-kondo 15 | /.lsp 16 | *~ 17 | .*.swp 18 | /node_modules 19 | /.shadow-cljs 20 | /.cpcache 21 | -------------------------------------------------------------------------------- /bb.edn: -------------------------------------------------------------------------------- 1 | {:min-bb-version "0.4.0" 2 | :paths ["bb"] 3 | :tasks 4 | {test-jvm {:doc "Runs JVM tests" 5 | :task (shell "lein test")} 6 | test-cljs {:doc "Runs CLJS tests" 7 | :task (shell "npx shadow-cljs compile test")} 8 | new-test {:doc "Creates new test for the Clojure symbols named by . Unqualified symbols assume clojure.core" 9 | :requires ([new-test]) 10 | :task (new-test/new-test *command-line-args*)} 11 | nrepl {:doc "Starts an nrepl server on port 1339 using an .nrepl-port file" 12 | :requires ([babashka.fs :as fs] 13 | [babashka.nrepl.server :as srv]) 14 | :task (do (srv/start-server! {:host "localhost" 15 | :port 1339}) 16 | (spit ".nrepl-port" "1339") 17 | (-> (Runtime/getRuntime) 18 | (.addShutdownHook 19 | (Thread. (fn [] (fs/delete ".nrepl-port"))))) 20 | (deref (promise)))}}} 21 | -------------------------------------------------------------------------------- /bb/new_test.clj: -------------------------------------------------------------------------------- 1 | (ns new-test 2 | "Creates a new test from a template" 3 | (:require [babashka.fs :as fs] 4 | [clojure.string :as str] 5 | [selmer.parser :as s] 6 | [selmer.util :as util])) 7 | 8 | ;;; *, +, !, -, _, ', ?, <, > and = 9 | (defn sym-name->ns-suffix 10 | "Replace special characters in symbol name to make the final component of the ns name." 11 | [sym] 12 | (let [n (name sym) 13 | ns-sym (-> (if (str/starts-with? n "-") 14 | (str/replace-first n "-" "minus") 15 | n) 16 | (str/replace "*" "-star") 17 | (str/replace "+" "-plus") 18 | (str/replace "!" "-bang") 19 | (str/replace "'" "-squote") 20 | (str/replace "?" "-qmark") 21 | (str/replace "<" "-lt") 22 | (str/replace ">" "-gt") 23 | (str/replace "=" "-eq") 24 | (str/replace "%" "-percent"))] 25 | (if (str/starts-with? ns-sym "-") 26 | (subs ns-sym 1) 27 | ns-sym))) 28 | 29 | (defn ns-suffix->file-name 30 | "Replace hyphens with underscores to create the file name." 31 | [ns-name] 32 | (str/replace ns-name "-" "_")) 33 | 34 | (defn ns->resource [nsym] 35 | (-> nsym namespace-munge (str/replace "." "/"))) 36 | 37 | (defn new-test 38 | "Create a new test file for the symbol which is the first command line argument." 39 | [args] 40 | (if (zero? (count args)) 41 | (println "Please supply one or more Clojure symbols corresponding to the new tests.") 42 | (loop [[sym & args] (map symbol args)] 43 | (when sym 44 | (let [sym-name (if (namespace sym) 45 | (-> sym name symbol) 46 | sym) 47 | base-ns (or (some-> sym namespace symbol) 48 | 'clojure.core) 49 | ns-suffix (sym-name->ns-suffix sym-name) 50 | file-name (namespace-munge ns-suffix) 51 | dest-dir (format "test/%s_test" (ns->resource base-ns)) 52 | dest-file-name (format "%s/%s.cljc" dest-dir file-name)] 53 | (if (fs/exists? dest-file-name) 54 | (println dest-file-name "already exists. No action taken.") 55 | (do (println "Creating" dest-file-name) 56 | (fs/create-dirs dest-dir) 57 | (let [template (slurp "templates/test-template.cljc")] 58 | (spit dest-file-name 59 | (util/without-escaping 60 | (s/render template {:base-ns base-ns 61 | :sym-name sym-name 62 | :ns-suffix ns-suffix 63 | :file-name file-name}))))))) 64 | (recur args))))) 65 | -------------------------------------------------------------------------------- /deps.edn: -------------------------------------------------------------------------------- 1 | {:paths ["test"]} 2 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1731533236, 9 | "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "nixpkgs": { 22 | "locked": { 23 | "lastModified": 1736012469, 24 | "narHash": "sha256-/qlNWm/IEVVH7GfgAIyP6EsVZI6zjAx1cV5zNyrs+rI=", 25 | "owner": "nixos", 26 | "repo": "nixpkgs", 27 | "rev": "8f3e1f807051e32d8c95cd12b9b421623850a34d", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "nixos", 32 | "ref": "nixos-unstable", 33 | "repo": "nixpkgs", 34 | "type": "github" 35 | } 36 | }, 37 | "root": { 38 | "inputs": { 39 | "flake-utils": "flake-utils", 40 | "nixpkgs": "nixpkgs" 41 | } 42 | }, 43 | "systems": { 44 | "locked": { 45 | "lastModified": 1681028828, 46 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 47 | "owner": "nix-systems", 48 | "repo": "default", 49 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 50 | "type": "github" 51 | }, 52 | "original": { 53 | "owner": "nix-systems", 54 | "repo": "default", 55 | "type": "github" 56 | } 57 | } 58 | }, 59 | "root": "root", 60 | "version": 7 61 | } 62 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "jank-lang/clojure.test"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; 6 | flake-utils.url = "github:numtide/flake-utils"; 7 | }; 8 | 9 | outputs = { self, flake-utils, nixpkgs }: flake-utils.lib.eachDefaultSystem (system: 10 | let 11 | pkgs = import nixpkgs { inherit system; }; 12 | in 13 | { 14 | devShell = pkgs.mkShell { 15 | buildInputs = [ 16 | pkgs.clj-kondo 17 | pkgs.clojure 18 | pkgs.clojure-lsp 19 | pkgs.leiningen 20 | pkgs.temurin-jre-bin-17 21 | pkgs.nodejs_23 22 | ]; 23 | }; 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "io.github.jank-lang/clojure-test-suite", 3 | "version": "1.0.0", 4 | "description": "Node config for compiling tests to js", 5 | "repository": "https://github.com/jank-lang/clojure-test-suite", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "build": "shadow-cljs release test", 11 | "test": "node target/js/node-tests.js" 12 | }, 13 | "author": "jeaye", 14 | "license": "MPL 2.0", 15 | "devDependencies": { 16 | "shadow-cljs": "^2.28.20" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject io.github.jank-lang/clojure-test-suite "0.1.0-SNAPSHOT" 2 | :description "Dialect-independent tests for clojure.core, focused on locking down how Clojure JVM behaves so that other dialects to reach parity." 3 | :url "https://github.com/jank-lang/clojure-test-suite" 4 | :license {:name "MPL 2.0" 5 | :url "https://www.mozilla.org/en-US/MPL/2.0/"} 6 | :dependencies [[org.clojure/clojure "1.12.0"]] 7 | :plugins [[com.jakemccrary/lein-test-refresh "0.25.0"]]) 8 | -------------------------------------------------------------------------------- /shadow-cljs.edn: -------------------------------------------------------------------------------- 1 | ;; shadow-cljs configuration 2 | {:source-paths 3 | ["test"] 4 | 5 | :dependencies 6 | [] 7 | 8 | :builds 9 | {:test {:target :node-test 10 | :output-to "target/js/node-tests.js" 11 | :ns-regexp "-test" 12 | :autorun true 13 | :compiler-options {:warnings {:invalid-arithmetic false}} 14 | :release {:autorun false 15 | :compiler-options {:optimizations :simple 16 | :elide-asserts false}}}}} 17 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}); 2 | mkShell 3 | { 4 | buildInputs = 5 | [ 6 | leiningen 7 | openjdk 8 | nodejs 9 | ]; 10 | shellHook = 11 | '' 12 | ''; 13 | } 14 | -------------------------------------------------------------------------------- /templates/test-template.cljc: -------------------------------------------------------------------------------- 1 | (ns {{base-ns}}-test.{{ns-suffix}} 2 | (:require {{base-ns}} 3 | [clojure.test :as t :refer [deftest testing is are]] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists {{base-ns}}/{{sym-name}} 7 | (deftest test-{{sym-name}} 8 | ;; `testing` sections are optional, depending on how you want to 9 | ;; structure your tests. If you have a lot of tests and they group 10 | ;; together in subgroups, then use `testing`. The `testing` form 11 | ;; can also be a nice way to group tests that only apply to a 12 | ;; subset of Clojure implementations. These can then be guarded by 13 | ;; reader conditionals. 14 | (testing "section name" 15 | (is (= 1 0))))) 16 | -------------------------------------------------------------------------------- /test/clojure/core_test/abs.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.abs 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/abs 7 | (deftest test-abs 8 | (testing "common" 9 | (are [in ex] (= ex (abs in)) 10 | -1 1 11 | 1 1 12 | (inc r/min-int) (- (inc r/min-int)) 13 | #?@(:clj [r/min-int r/min-int]) ; fixed int 2's complement oddity 14 | -1.0 1.0 15 | -0.0 0.0 16 | ##-Inf ##Inf 17 | ##Inf ##Inf 18 | -123.456M 123.456M 19 | -123N 123N 20 | #?@(:cljs [] 21 | :default 22 | [-1/5 1/5])) 23 | (is (NaN? (abs ##NaN))) 24 | #?(:cljs (is (zero? (abs nil))) 25 | :default (is (thrown? #?(:clj Exception) (abs nil))))) 26 | 27 | (testing "unboxed" 28 | (let [a 42 29 | b -42 30 | a' (abs a) 31 | b' (abs b)] 32 | (is (= 42 a')) 33 | (is (= 42 b')))))) 34 | -------------------------------------------------------------------------------- /test/clojure/core_test/aclone.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.aclone 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/aclone 6 | (defn clone-test 7 | [a b] 8 | (aset a 0 1) 9 | (aset a 1 2) 10 | (aset a 2 3) 11 | (let [a' (aclone a) 12 | b' (aclone b)] 13 | (is (= 3 (alength a'))) 14 | (is (every? identity (map #(= (aget a %) (aget a' %)) (range 3)))) 15 | (is (zero? (alength b'))) 16 | (is (not (identical? a a'))) 17 | (is (not (identical? b b'))) 18 | (aset a 1 11) 19 | (is (= 11 (aget a 1))) 20 | (is (= 2 (aget a' 1))) 21 | (aset a' 2 12) 22 | (is (= 3 (aget a 2))) 23 | (is (= 12 (aget a' 2))))) 24 | 25 | (deftest test-aclone 26 | (testing "integer-arrays" 27 | (clone-test (int-array 3) (int-array 0))) 28 | 29 | (testing "object-arrays" 30 | (clone-test (object-array 3) (object-array 0))))) 31 | -------------------------------------------------------------------------------- /test/clojure/core_test/and.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.and 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/and 6 | (deftest test-and 7 | (testing "common" 8 | (is (= true (and))) 9 | (are [x] (= x (and x)) 10 | true 11 | false 12 | nil 13 | :example) 14 | (are [ex a b] (= ex (and a b)) 15 | true true true 16 | false true false 17 | false false true 18 | false false false 19 | true true true 20 | nil true nil 21 | nil nil true 22 | nil nil nil) 23 | (testing "binds values before comparing" 24 | (let [counter (volatile! 0)] 25 | (is (= nil (and (vswap! counter inc) nil))) 26 | (is (= 1 @counter)))) 27 | (testing "early exits" 28 | (let [counter (volatile! 0)] 29 | (is (= nil (and nil (vswap! counter inc)))) 30 | (is (= 0 @counter)))) 31 | (testing "handles varargs" 32 | (is (= nil (and nil nil 3))) 33 | (is (= nil (and nil nil nil nil nil nil nil nil nil nil nil nil true))))) 34 | 35 | (testing "infinite-sequence" 36 | (is (some? (and (range))))))) 37 | -------------------------------------------------------------------------------- /test/clojure/core_test/any_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.any-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/any? 6 | (deftest test-any? 7 | (testing "common" 8 | (are [x] (= true (any? x)) 9 | nil 10 | true 11 | false 12 | "" 13 | 0 14 | 1)) 15 | 16 | (testing "infinite-sequence" 17 | (is (= true (any? (range))))))) 18 | -------------------------------------------------------------------------------- /test/clojure/core_test/associative_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.associative-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/associative? 6 | (deftest test-associative? 7 | (are [expected x] (= expected (associative? x)) 8 | ;; vectors and maps are associative 9 | true [] 10 | true [1 2 3] 11 | true {} 12 | true {:a 1 :b 2} 13 | 14 | ;; list, set, string, array, keywords, symbols, numbers, characters 15 | false nil 16 | false '() 17 | false (range 10) ; lazy seq 18 | false (range) ; infinite lazy seq 19 | false #{} 20 | false #{:a :b} 21 | false "ab" 22 | false (seq "ab") ; seq 23 | false (to-array [1 2 3]) 24 | false :a 25 | false 'a 26 | false 1 27 | false \a))) 28 | -------------------------------------------------------------------------------- /test/clojure/core_test/bigdec.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bigdec 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/bigdec 6 | (deftest test-bigdec 7 | (are [expected x] (= expected (bigdec x)) 8 | 1M 1 9 | 0M 0 10 | -1M -1 11 | 1M 1N 12 | 0M 0N 13 | -1M -1N 14 | 1M 1.0 15 | 0M 0.0 16 | -1M -1.0 17 | #?@(:cljs [] 18 | :default 19 | [0.5M 1/2 20 | 0M 0/2 21 | -0.5M -1/2])) 22 | 23 | ;; `bigdec` must produce objects that satisfy `decimal?` 24 | (is (decimal? (bigdec 1))) 25 | 26 | #?@(:cljs [] 27 | :default 28 | [(is (instance? java.math.BigDecimal (bigdec 1)))]))) 29 | -------------------------------------------------------------------------------- /test/clojure/core_test/bigint.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bigint 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/bigint 7 | (deftest test-bigint 8 | (are [expected x] (= expected (bigint x)) 9 | 1N 1 10 | 0N 0 11 | -1N -1 12 | #?@(:cljs [] 13 | :clj [179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000N r/max-double]) 14 | 1N 1.0 15 | 0N 0.0 16 | -1N -1.0 17 | #?@(:cljs [] 18 | :default 19 | [1N 12/12 20 | 0N 0/12 21 | -1N -12/12])) 22 | 23 | ;; Validate that we correctly promote from int to bigint with `inc'` and `dec'`. 24 | (is (= 9223372036854775808N (inc (bigint r/max-int)) (inc' r/max-int))) 25 | (is (= -9223372036854775809N (dec (bigint r/min-int)) (dec' r/min-int))) 26 | 27 | #?@(:cljs [] 28 | :default 29 | [(is (instance? clojure.lang.BigInt (bigint 0))) 30 | (is (instance? clojure.lang.BigInt (bigint 0.0))) 31 | (is (instance? clojure.lang.BigInt (inc' r/max-int))) 32 | (is (instance? clojure.lang.BigInt (dec' r/min-int)))]))) 33 | -------------------------------------------------------------------------------- /test/clojure/core_test/binding.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.binding 2 | (:require [clojure.test :as t] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/binding 6 | (def ^:dynamic *x* :unset) 7 | (def ^:dynamic *y* nil) 8 | (defn ^:dynamic *f* [x] (inc x)) 9 | 10 | (defn test-fn [] *x*) 11 | 12 | (t/deftest test-binding 13 | ;; base-case with no overrides 14 | (t/is (= *x* :unset) "Unset is :unset") 15 | (t/is (= (*f* 1) 2) "fn call") 16 | 17 | ;; common cases 18 | (t/is (binding [*x* :set] (= *x* :set)) "Can bind dynamic var.") 19 | (t/is (binding [*x* :set] (= (test-fn) :set)) "Binding for indirect reference.") 20 | (t/is (binding [*x* nil] (= (test-fn) nil)) "Dynamic vars are nullable.") 21 | (t/is (binding [*f* dec] (= (*f* 1) 0)) "Can bind functions.") 22 | 23 | ;; infinite seqs 24 | (binding [*x* (range)] 25 | (t/is (= '(0 1 2 3) (take 4 (test-fn))) "Infinite range") 26 | (t/is (= '(0 1 2 3) (take 4 (test-fn))) "Immutability")) 27 | 28 | ;; Nested cases 29 | (binding [*x* :first!] 30 | (let [layer-1 (fn [] (test-fn))] 31 | (binding [*x* :second!] 32 | (t/is (= :second! (layer-1) (test-fn)) "Value is determined at call-site")))) 33 | (binding [*y* *x*] 34 | (t/is (= *y* :unset) "Dynamic reference is by value at binding.") 35 | (binding [*x* :layer-2] 36 | (t/is (= *y* :unset) "Dynamic reference does not update.")) 37 | (binding [*y* *x* 38 | *x* :set-later] 39 | (t/is (= *y* :unset) "Bind vars are applied in sequence."))) 40 | (let [f (fn [] (binding [*x* :inside-f] (test-fn)))] 41 | (binding [*x* :outside-f] 42 | (t/is (= (test-fn) :outside-f)) 43 | (t/is (= (f) :inside-f) "Nested in func-call"))) 44 | (binding [*y* (binding [*x* :bad] (test-fn))] 45 | (t/is (= *y* :bad) "Binding in a binding vector")) 46 | 47 | ;; Threading/future/delay cases 48 | (let [f (delay (test-fn))] 49 | (binding [*x* :here] 50 | (t/is (= @f :here) "Delayed functions inherit there bindings when forced")) 51 | (t/is (= @f :here) "And value persists outside binding expression")) 52 | 53 | ;; CLJS doesn't have futures 54 | #?@(:cljs [] 55 | :default 56 | [(let [f (future (test-fn))] 57 | (binding [*x* :now-here] 58 | (t/is (= @f :unset) "Thread context is separate from joining thread"))) 59 | (binding [*x* :outer] 60 | (let [f (future (test-fn))] 61 | (binding [*x* :inner] 62 | (t/is (= @f :outer) "Thread context preserves binding context.")))) 63 | (binding [*x* :caller] 64 | (let [f (future 65 | (binding [*x* :callee] 66 | (future (test-fn))))] 67 | (binding [*x* :derefer] 68 | (let [derefed-f @f] 69 | (t/is (= :callee @derefed-f) "Binding in futures preserved.")))))]))) 70 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_and.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-and 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/bit-and 7 | (deftest test-bit-and 8 | #?(:cljs (is (= 0 (bit-and nil 1))) 9 | :default (is (thrown? #?(:clj Exception) (bit-and nil 1)))) 10 | #?(:cljs (is (= 0 (bit-and 1 nil))) 11 | :default (is (thrown? #?(:clj Exception) (bit-and 1 nil)))) 12 | 13 | (are [ex a b] (= ex (bit-and a b)) 14 | 8 12 9 15 | 8 8 0xff 16 | 0 r/all-ones-int 0 17 | 0 0 r/all-ones-int 18 | #?(:cljs -1 :default r/all-ones-int) r/all-ones-int r/all-ones-int 19 | 0 r/full-width-checker-pos 0 20 | r/full-width-checker-pos r/full-width-checker-pos r/full-width-checker-pos 21 | r/full-width-checker-pos r/full-width-checker-pos r/all-ones-int 22 | 0 r/full-width-checker-pos r/full-width-checker-neg))) 23 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_and_not.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-and-not 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/bit-and-not 7 | (deftest test-bit-and-not 8 | #?(:cljs (is (= 0 (bit-and-not nil 1))) 9 | :default (is (thrown? #?(:clj Exception) (bit-and-not nil 1)))) 10 | #?(:cljs (is (= 1 (bit-and-not 1 nil))) 11 | :default (is (thrown? #?(:clj Exception) (bit-and-not 1 nil)))) 12 | 13 | (are [ex a b] (= ex (bit-and-not a b)) 14 | 0 0 0 15 | 8 12 4 16 | 0xff 0xff 0 17 | 0x80 0xff 0x7f 18 | #?(:cljs -1 :default r/all-ones-int) r/all-ones-int 0 19 | 0 0 r/all-ones-int 20 | 0 r/all-ones-int r/all-ones-int 21 | r/full-width-checker-pos r/full-width-checker-pos 0 22 | 0 r/full-width-checker-pos r/full-width-checker-pos 23 | 0 r/full-width-checker-pos r/all-ones-int 24 | r/full-width-checker-pos r/full-width-checker-pos r/full-width-checker-neg))) 25 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_clear.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-clear 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/bit-clear 6 | (deftest test-bit-clear 7 | #?(:cljs (is (= 0 (bit-clear nil 1))) 8 | :default (is (thrown? #?(:clj Exception) (bit-clear nil 1)))) 9 | #?(:cljs (is (= 0 (bit-clear 1 nil))) 10 | :default (is (thrown? #?(:clj Exception) (bit-clear 1 nil)))) 11 | 12 | (are [ex a b] (= ex (bit-clear a b)) 13 | 3 11 3))) 14 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_flip.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-flip 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/bit-flip 6 | (deftest test-bit-flip 7 | #?(:cljs (is (= 2 (bit-flip nil 1))) 8 | :default (is (thrown? #?(:clj Exception) (bit-flip nil 1)))) 9 | #?(:cljs (is (= 0 (bit-flip 1 nil))) 10 | :default (is (thrown? #?(:clj Exception) (bit-flip 1 nil)))) 11 | 12 | (are [ex a b] (= ex (bit-flip a b)) 13 | 2r1111 2r1011 2 14 | 2r1011 2r1111 2))) 15 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_not.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-not 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/bit-not 6 | (deftest test-bit-not 7 | #?(:cljs (is (= -1 (bit-not nil))) 8 | :default (is (thrown? #?(:clj Exception) (bit-not nil)))) 9 | 10 | (are [ex a] (= ex (bit-not a)) 11 | -2r1000 2r0111 12 | 2r0111 -2r1000))) 13 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_or.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-or 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/bit-or 7 | (deftest test-bit-or 8 | #?(:cljs (is (bit-or nil 1)) 9 | :default (is (thrown? #?(:clj Exception) (bit-or nil 1)))) 10 | #?(:cljs (is (bit-or 1 nil)) 11 | :default (is (thrown? #?(:clj Exception) (bit-or 1 nil)))) 12 | 13 | (are [ex a b] (= ex (bit-or a b)) 14 | 2r1101 2r1100 2r1001 15 | 1 1 0 16 | #?(:cljs -1 :default r/all-ones-int) r/all-ones-int 0 17 | #?(:cljs -1 :default r/all-ones-int) 0 r/all-ones-int 18 | #?(:cljs -1 :default r/all-ones-int) r/all-ones-int r/all-ones-int 19 | r/full-width-checker-pos r/full-width-checker-pos 0 20 | r/full-width-checker-pos r/full-width-checker-pos r/full-width-checker-pos 21 | #?(:cljs -1 :default r/all-ones-int) r/full-width-checker-pos r/all-ones-int 22 | #?(:cljs -1 :default r/all-ones-int) r/full-width-checker-pos r/full-width-checker-neg))) 23 | 24 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_set.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-set 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/bit-set 6 | (deftest test-bit-set 7 | #?(:cljs (is (bit-set nil 1)) 8 | :default (is (thrown? #?(:clj Exception) (bit-set nil 1)))) 9 | #?(:cljs (is (bit-set 1 nil)) 10 | :default (is (thrown? #?(:clj Exception) (bit-set 1 nil)))) 11 | 12 | (are [ex a b] (= ex (bit-set a b)) 13 | 2r1111 2r1011 2 14 | #?@(:cljs [] :default [-9223372036854775808 0 63]) 15 | #?@(:cljs [] :default [4294967296 0 32]) 16 | 65536 0 16 17 | 256 0 8 18 | 16 0 4))) 19 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_shift_left.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-shift-left 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/bit-shift-left 6 | (deftest test-bit-shift-left 7 | #?(:cljs (is (= 0 (bit-shift-left nil 1))) 8 | :default (is (thrown? #?(:clj Exception) (bit-shift-left nil 1)))) 9 | #?(:cljs (is (= 1 (bit-shift-left 1 nil))) 10 | :default (is (thrown? #?(:clj Exception) (bit-shift-left 1 nil)))) 11 | 12 | (are [ex a b] (= ex (bit-shift-left a b)) 13 | 1024 1 10 14 | 2r110100 2r1101 2))) 15 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_shift_right.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-shift-right 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/bit-shift-right 6 | (deftest test-bit-shift-right 7 | #?(:cljs (is (bit-shift-right nil 1)) 8 | :default (is (thrown? #?(:clj Exception) (bit-shift-right nil 1)))) 9 | #?(:cljs (is (bit-shift-right 1 nil)) 10 | :default (is (thrown? #?(:clj Exception) (bit-shift-right 1 nil)))) 11 | 12 | (are [ex a b] (= ex (bit-shift-right a b)) 13 | 2r1101 2r1101 0 14 | 2r110 2r1101 1 15 | 2r11 2r1101 2 16 | 2r1 2r1101 3 17 | 2r0 2r1101 4 18 | 2r0 2r1101 63))) 19 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_test.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-test 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/bit-test 6 | (deftest test-bit-test 7 | #?(:cljs (is (= false (bit-test nil 1))) 8 | :default (is (thrown? #?(:clj Exception) (bit-test nil 1)))) 9 | #?(:cljs (is (= true (bit-test 1 nil))) 10 | :default (is (thrown? #?(:clj Exception) (bit-test 1 nil)))) 11 | 12 | (are [ex a b] (= ex (bit-test a b)) 13 | true 2r1001 0 14 | false 2r1001 1 15 | false 2r1001 2 16 | true 2r1001 3 17 | false 2r1001 4 18 | false 2r1001 63))) 19 | -------------------------------------------------------------------------------- /test/clojure/core_test/bit_xor.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bit-xor 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/bit-xor 7 | (deftest test-bit-xor 8 | #?(:cljs (is (bit-xor nil 1)) 9 | :default (is (thrown? #?(:clj Exception) (bit-xor nil 1)))) 10 | #?(:cljs (is (bit-xor 1 nil)) 11 | :default (is (thrown? #?(:clj Exception) (bit-xor 1 nil)))) 12 | 13 | (are [ex a b] (= ex (bit-xor a b)) 14 | 2r0101 2r1100 2r1001 15 | #?(:cljs -1 :default r/all-ones-int) r/all-ones-int 0 16 | #?(:cljs -1 :default r/all-ones-int) 0 r/all-ones-int 17 | 0 r/all-ones-int r/all-ones-int 18 | r/full-width-checker-pos r/full-width-checker-pos 0 19 | 0 r/full-width-checker-pos r/full-width-checker-pos 20 | #?(:cljs -1431655766 :default r/full-width-checker-neg) r/full-width-checker-pos r/all-ones-int 21 | #?(:cljs -1 :default r/all-ones-int) r/full-width-checker-pos r/full-width-checker-neg))) 22 | -------------------------------------------------------------------------------- /test/clojure/core_test/boolean.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.boolean 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/boolean 7 | (deftest test-boolean 8 | (are [expected x] (= expected (boolean x)) 9 | true 0 10 | true 1 11 | true -1 12 | true r/max-int 13 | true r/min-int 14 | true 0.0 15 | true 1.0 16 | true -1.0 17 | true (float 0.0) 18 | true (float 1.0) 19 | true (float -1.0) 20 | true (double 0.0) 21 | true (double 1.0) 22 | true (double -1.0) 23 | true r/max-double 24 | true r/min-double 25 | true ##Inf 26 | true ##-Inf 27 | true ##NaN 28 | true 0N 29 | true 1N 30 | true -1N 31 | #?@(:cljs [] 32 | :default 33 | [true 0/2 34 | true 1/2 35 | true -1/2]) 36 | true 0.0M 37 | true 1.0M 38 | true -1.0M 39 | false nil 40 | true true 41 | false false 42 | true "a string" 43 | true "0" 44 | true "1" 45 | true "-1" 46 | true "true" 47 | true "false" 48 | true {:a :map} 49 | true #{:a-set} 50 | true [:a :vector] 51 | true '(:a :list) 52 | true \0 53 | true \1 54 | true :a-keyword 55 | true :true 56 | true :false 57 | true :0 58 | true :1 59 | true :-1 60 | true 'a-sym))) 61 | -------------------------------------------------------------------------------- /test/clojure/core_test/bound_fn.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bound-fn 2 | (:require [clojure.test :as t] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (def ^:dynamic *x* :unset) 6 | 7 | (when-var-exists clojure.core/bound-fn 8 | (t/deftest test-bound-fn 9 | (t/testing "base case" 10 | (let [f (bound-fn [] *x*)] 11 | (t/is (= (f) :unset) "picks up dynamic vars") 12 | (binding [*x* :set] 13 | (t/is (= (f) :set) "And tracks their changes")))) 14 | 15 | (t/testing "Common cases" 16 | (binding [*x* :set] 17 | (let [f (bound-fn [] *x*)] 18 | (binding [*x* :set-again] 19 | (t/is (= (f) :set) "bound-fn stores values"))))) 20 | 21 | (t/testing "Infinite seqs" 22 | (binding [*x* (range)] 23 | (let [f (bound-fn [] *x*)] 24 | (binding [*x* (drop 50 (range))] 25 | (t/is (= (range 10) 26 | (take 10 (f)) 27 | (take 10 (f))) "infinite seqs work"))))) 28 | 29 | (t/testing "Nested cases" 30 | (binding [*x* :first!] 31 | (let [f (bound-fn [] *x*)] 32 | (binding [*x* :second!] 33 | (let [f (bound-fn [] [(f) *x*])] 34 | (t/is (= (f) [:first! :second!]) "Nested bound functions work as expected."))))) 35 | (let [f (fn [] (binding [*x* :inside-f] 36 | (bound-fn [] *x*)))] 37 | (binding [*x* :outside-f] 38 | (t/is (= ((f)) :inside-f) "bound-fn as result preserves initial bindings")))) 39 | 40 | (t/testing "Threaded/future cases" 41 | (let [f (bound-fn [] *x*)] 42 | (let [fut (future (f))] 43 | (binding [*x* :here] 44 | (t/is (= @fut :unset) "bound-fn stays bound even in other thread")))) 45 | (binding [*x* :caller] 46 | (let [f (future 47 | (binding [*x* :callee] 48 | (future (bound-fn [] *x*))))] 49 | (binding [*x* :derefer] 50 | (let [derefed-f @f] 51 | (t/is (= :callee (@derefed-f)) "Binding in futures preserved.")))))))) 52 | -------------------------------------------------------------------------------- /test/clojure/core_test/bound_fn_star.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.bound-fn-star 2 | (:require [clojure.test :as t] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (def ^:dynamic *x* :unset) 6 | 7 | (defn test-fn [] *x*) 8 | 9 | (when-var-exists clojure.core/bound-fn* 10 | (t/deftest test-bound-fn* 11 | (t/testing "base case" 12 | (let [f (bound-fn* test-fn)] 13 | (t/is (= (f) :unset) "picks up dynamic vars") 14 | (binding [*x* :set] 15 | (t/is (= (f) :set) "And tracks their changes")))) 16 | 17 | (t/testing "Common cases" 18 | (binding [*x* :set] 19 | (let [f (bound-fn* test-fn)] 20 | (binding [*x* :set-again] 21 | (t/is (= (f) :set) "bound-fn stores values"))))) 22 | 23 | (t/testing "Infinite seqs" 24 | (binding [*x* (range)] 25 | (let [f (bound-fn* test-fn)] 26 | (binding [*x* (drop 50 (range))] 27 | (t/is (= (range 10) 28 | (take 10 (f)) 29 | (take 10 (f))) "infinite seqs work"))))) 30 | 31 | (t/testing "Nested cases" 32 | (binding [*x* :first!] 33 | (let [f (bound-fn* test-fn)] 34 | (binding [*x* :second!] 35 | (let [f (fn [] [(f) ((bound-fn* test-fn))])] 36 | (t/is (= (f) [:first! :second!]) "Nested bound functions work as expected."))))) 37 | (let [f (fn [] (binding [*x* :inside-f] 38 | (bound-fn* test-fn)))] 39 | (binding [*x* :outside-f] 40 | (t/is (= ((f)) :inside-f) "bound-fn as result preserves initial bindings")))) 41 | 42 | (t/testing "Threaded/future cases" 43 | (let [f (bound-fn* test-fn)] 44 | (let [fut (future (f))] 45 | (binding [*x* :here] 46 | (t/is (= @fut :unset) "bound-fn stays bound even in other thread")))) 47 | (binding [*x* :caller] 48 | (let [f (future 49 | (binding [*x* :callee] 50 | (future (bound-fn* test-fn))))] 51 | (binding [*x* :derefer] 52 | (let [derefed-f @f] 53 | (t/is (= :callee (@derefed-f)) "Binding in futures preserved.")))))))) 54 | -------------------------------------------------------------------------------- /test/clojure/core_test/butlast.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.butlast 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/butlast 6 | (deftest test-butlast 7 | (are [expected x] (= expected (butlast x)) 8 | nil (range 1) 9 | (range 1) (range 2) 10 | (range 2) (range 3) 11 | (range 3) (range 4) 12 | nil '(0) 13 | nil [0] 14 | nil nil))) 15 | -------------------------------------------------------------------------------- /test/clojure/core_test/byte.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.byte 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/byte 6 | (deftest test-byte 7 | ;; There is no platform independent predicate to test for a 8 | ;; byte (e.g., `byte?`). In ClojureJVM, it's an instance of 9 | ;; `java.lang.Byte`, but there is no predicate for it. Here, we just 10 | ;; test whether it's a fixed-length integer of some sort. 11 | (is (int? (byte 0))) 12 | #?(:clj (is (instance? java.lang.Byte (byte 0)))) 13 | 14 | ;; Check conversions and rounding from other numeric types 15 | (are [expected x] (= expected (byte x)) 16 | -128 -128 17 | 0 0 18 | 127 127 19 | 1 1N 20 | 0 0N 21 | -1 -1N 22 | 1 1.0M 23 | 0 0.0M 24 | -1 -1.0M 25 | ;; Clojurescript `byte` is a "dummy cast" which doesn't do 26 | ;; anything (no-op). Thus, there is no conversion, no truncation 27 | ;; of decimal values, etc. 28 | #?@(:cljs 29 | [1.1 1.1 30 | -1.1 -1.1 31 | 1.9 1.9 32 | 1.1 1.1M 33 | -1.1 -1.1M] 34 | :default 35 | [1 1.1 36 | -1 -1.1 37 | 1 1.9 38 | 1 3/2 39 | -1 -3/2 40 | 0 1/10 41 | 0 -1/10 42 | 1 1.1M 43 | -1 -1.1M])) 44 | 45 | #?@(:cljs 46 | [ ;; ClojureScript `byte` just returns its argument 47 | (is (= -128.5 (byte -128.5))) 48 | (is (= -129 (byte -129))) 49 | (is (= 128(byte 128))) 50 | (is (= 127.5 (byte 127.5))) 51 | (is (= "0" (byte "0"))) 52 | (is (= :0 (byte :0))) 53 | (is (= [0] (byte [0]))) 54 | (is (= nil (byte nil)))] 55 | :default 56 | [ ;; `byte` throws outside the range of 127 ... -128. 57 | (is (thrown? #?(:clj Exception) (byte -128.000001))) 58 | (is (thrown? #?(:clj Exception) (byte -129))) 59 | (is (thrown? #?(:clj Exception) (byte 128))) 60 | (is (thrown? #?(:clj Exception) (byte 127.000001))) 61 | ;; Check handling of other types 62 | (is (thrown? #?(:clj Exception) (byte "0"))) 63 | (is (thrown? #?(:clj Exception) (byte :0))) 64 | (is (thrown? #?(:clj Exception) (byte [0]))) 65 | (is (thrown? #?(:clj Exception) (byte nil)))]))) 66 | -------------------------------------------------------------------------------- /test/clojure/core_test/char.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.char 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/char 6 | (deftest test-char 7 | (are [expected x] (= expected (char x)) 8 | ;; Assumes ASCII / Unicode 9 | \space 32 10 | \@ 64 11 | \A 65 12 | \A \A 13 | ;; TODO: Add Unicode tests 14 | ) 15 | 16 | #?(:cljs nil :default (is (thrown? #?(:clj Exception) (char -1)))) 17 | (is (thrown? #?(:cljs :default :clj Exception) (char nil))))) 18 | -------------------------------------------------------------------------------- /test/clojure/core_test/char_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.char-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/char? 7 | (deftest test-char? 8 | (are [expected x] (= expected (char? x)) 9 | false 0 10 | false 1 11 | false -1 12 | false r/max-int 13 | false r/min-int 14 | false 0.0 15 | false 1.0 16 | false -1.0 17 | false (float 0.0) 18 | false (float 1.0) 19 | false (float -1.0) 20 | false (double 0.0) 21 | false (double 1.0) 22 | false (double -1.0) 23 | false r/max-double 24 | false r/min-double 25 | false ##Inf 26 | false ##-Inf 27 | false ##NaN 28 | false 0N 29 | false 1N 30 | false -1N 31 | #?@(:cljs [] ; cljs doesn't have ratios 32 | :default 33 | [false 0/2 34 | false 1/2 35 | false -1/2]) 36 | false 0.0M 37 | false 1.0M 38 | false -1.0M 39 | false nil 40 | false true 41 | false false 42 | false "a string" 43 | #?@(:cljs ; In cljs, chars are single char strings 44 | [true "0" 45 | true "1"] 46 | :default 47 | [false "0" 48 | false "1"]) 49 | false "-1" 50 | false {:a :map} 51 | false #{:a-set} 52 | false [:a :vector] 53 | false '(:a :list) 54 | true \0 55 | true \1 56 | true \A 57 | true \space 58 | false :a-keyword 59 | false :0 60 | false :1 61 | false :-1 62 | false 'a-sym)) 63 | ) 64 | -------------------------------------------------------------------------------- /test/clojure/core_test/coll_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.coll-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/coll? 6 | (deftest test-coll? 7 | (are [expected x] (= expected (coll? x)) 8 | true [1 2 3] 9 | true (sorted-map :a 1) 10 | true (sorted-set :a) 11 | true '(1 2 3) 12 | true (hash-map :a 1) 13 | true (array-map :a 1) 14 | true (hash-set :a) 15 | true (seq [1 2 3]) 16 | true (seq (sorted-map :a 1)) 17 | true (seq (sorted-set :a)) 18 | true (range 0 10) 19 | true (range) 20 | false nil 21 | false 1 22 | false 1N 23 | false 1.0 24 | false 1.0M 25 | false :a-keyword 26 | false 'a-sym 27 | false "a string" 28 | false \a 29 | false (object-array 3)))) 30 | -------------------------------------------------------------------------------- /test/clojure/core_test/compare.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.compare 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/compare 6 | (deftest test-compare 7 | (testing "numeric-types" 8 | (are [pred args] (pred (compare (first args) (second args))) 9 | neg? [0 10] 10 | zero? [0 0] 11 | pos? [0 -100N] 12 | zero? [1 1.0] 13 | #?@(:cljs [] 14 | :default 15 | [neg? [1 100/3]]) 16 | neg? [0 0x01] 17 | neg? [0 2r01] 18 | pos? [1 nil]) 19 | 20 | (is (thrown? #?(:cljs :default :clj Exception) (compare 1 [])))) 21 | 22 | (testing "lexical-types" 23 | (are [pred args] (pred (compare (first args) (second args))) 24 | neg? [\a \b] 25 | zero? [\0 \0] 26 | pos? [\z \a] 27 | neg? ["cat" "dog"] 28 | neg? ['cat 'dog] 29 | neg? [:cat :dog] 30 | zero? [:dog :dog] 31 | neg? [:cat :animal/cat] 32 | pos? ['a nil]) 33 | 34 | (is (thrown? #?(:cljs :default :clj Exception) (compare "a" []))) 35 | (is (thrown? #?(:cljs :default :clj Exception) (compare "cat" '(\c \a \t))))) 36 | 37 | (testing "collection-types" 38 | (are [pred args] (pred (compare (first args) (second args))) 39 | zero? [[] []] 40 | pos? [[3] [1]] 41 | neg? [[] [1 2]] 42 | neg? [[] [[]]] 43 | ;; Sets, maps, and lists don't implement java.lang.Comparable, 44 | ;; so just comment these out for now. TODO: make decision as to 45 | ;; what we want to do with these tests. 46 | ;; zero? [#{} #{}] 47 | ;; zero? [{} {}] 48 | ;; zero? [(array-map) (array-map)] 49 | ;; zero? [(hash-map) (hash-map)] 50 | ;; zero? [{} (hash-map)] 51 | ;; zero? [{} (array-map)] 52 | ;; zero? ['() '()] 53 | pos? [[] nil]) 54 | 55 | (is (thrown? #?(:cljs :default :clj Exception) (compare [] '()))) 56 | (is (thrown? #?(:cljs :default :clj Exception) (compare [1] [[]]))) 57 | (is (thrown? #?(:cljs :default :clj Exception) (compare [] {}))) 58 | (is (thrown? #?(:cljs :default :clj Exception) (compare [] #{}))) 59 | (is (thrown? #?(:cljs :default :clj Exception) (compare #{} (sorted-set)))) 60 | (is (thrown? #?(:cljs :default :clj Exception) (compare #{1} #{1}))) 61 | (is (thrown? #?(:cljs :default :clj Exception) (compare {1 2} {1 2}))) 62 | (is (thrown? #?(:cljs :default :clj Exception) (compare (range 5) (range 5)))) 63 | ;; Clojurescript goes into an infinite loop of some sort when compiling this. 64 | #_(is (thrown? #?(:cljs :default :clj Exception) (compare (range 5) (range))))))) 65 | -------------------------------------------------------------------------------- /test/clojure/core_test/count.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.count 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/count 6 | (deftest test-count 7 | (are [expected x] (= expected (count x)) 8 | 0 nil 9 | 0 '() 10 | 0 [] 11 | 0 {} 12 | 0 #{} 13 | 0 "" 14 | 1 '(:a) 15 | 1 [:a] 16 | 1 {:a 1} 17 | 1 #{:a} 18 | 1 "a" 19 | 2 '(:a :b) 20 | 2 [:a :b] 21 | 2 {:a 1 :b 2} 22 | 2 #{:a :b} 23 | 2 "ab") 24 | 25 | ;; Negative tests 26 | (are [x] (thrown? #?(:cljs :default :clj Exception) (count x)) 27 | 1 28 | :a 29 | 'a 30 | #?@(:cljs [] :default [\a])))) 31 | -------------------------------------------------------------------------------- /test/clojure/core_test/counted_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.counted-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/counted? 6 | (deftest test-counted? 7 | (testing "positive tests" 8 | (are [x] (counted? x) 9 | [1 2 3] 10 | '(1 2 3) ; surprising for traditional Lispers 11 | #{1 2 3} 12 | #?@(:cljs [nil] :default []) ; CLJS nil is `counted?` 13 | (array-map :a 1 :b 2 :c 3) 14 | (hash-map :a 1 :b 2 :c 3) 15 | (sorted-map :a 1 :b 2 :c 3) 16 | (sorted-set 1 2 3))) 17 | (testing "negative tests" 18 | (are [x] (not (counted? x)) 19 | 1 20 | 1N 21 | 1.0 22 | 1.0M 23 | :a-keyword 24 | 'a-sym 25 | #?@(:cljs [] :default [nil]) ; surprising since `(count nil)` = 0 26 | ;; `count` works on strings, arrays, and other Java 27 | ;; collections, but they are not `counted?`. 28 | "a string" 29 | (object-array 3))))) 30 | -------------------------------------------------------------------------------- /test/clojure/core_test/dec.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.dec 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/dec 6 | (deftest test-dec 7 | (testing "common" 8 | (are [in ex] (= (dec in) ex) 9 | 1 0 10 | 0 -1 11 | 1N 0N 12 | 0N -1N 13 | 14412 14411 14 | -3 -4 15 | 7.4 6.4 ; risky 16 | #?@(:cljs [] 17 | :default 18 | [3/2 1/2 19 | 1/2 -1/2]) 20 | ##Inf ##Inf 21 | ##-Inf ##-Inf) 22 | 23 | (is (NaN? (dec ##NaN)))) 24 | 25 | (testing "underflow" 26 | #?(:clj (is (thrown? Exception (dec Long/MIN_VALUE))) 27 | :cljs (is (= (dec js/Number.MIN_SAFE_INTEGER) (- js/Number.MIN_SAFE_INTEGER 2))) 28 | :default (is false "TODO underflow"))) 29 | 30 | (testing "dec-nil" 31 | ;; ClojureScript says (= -1 (dec nil)) because JavaScript casts null to 0 32 | #?(:clj (is (thrown? Exception (dec #_:clj-kondo/ignore nil))) 33 | :cljs (is (= -1 (dec #_:clj-kondo/ignore nil))))))) 34 | -------------------------------------------------------------------------------- /test/clojure/core_test/decimal_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.decimal-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/decimal? 7 | (deftest test-decimal? 8 | (are [expected x] (= expected (decimal? x)) 9 | false 0 10 | false 1 11 | false -1 12 | false r/max-int 13 | false r/min-int 14 | false 0.0 15 | false 1.0 16 | false -1.0 17 | false r/max-double 18 | false r/min-double 19 | false ##Inf 20 | false ##-Inf 21 | false ##NaN 22 | false 0N 23 | false 1N 24 | false -1N 25 | #?@(:cljs [] 26 | :default 27 | [false 0/2 28 | false 1/2 29 | false -1/2]) 30 | true 0.0M 31 | true 1.0M 32 | true -1.0M 33 | false nil 34 | false true 35 | false false 36 | false "a string" 37 | false "0" 38 | false "1" 39 | false "-1" 40 | false {:a :map} 41 | false #{:a-set} 42 | false [:a :vector] 43 | false '(:a :list) 44 | false \0 45 | false \1 46 | false :a-keyword 47 | false :0 48 | false :1 49 | false :-1 50 | false 'a-sym))) 51 | -------------------------------------------------------------------------------- /test/clojure/core_test/denominator.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.denominator 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/denominator 6 | (deftest test-denominator 7 | (is (= 2 (denominator 1/2))) 8 | (is (= 3 (denominator 2/3))) 9 | (is (= 4 (denominator 3/4))) 10 | 11 | (is (thrown? #?(:cljs :default :clj Exception) (denominator 1))) 12 | (is (thrown? #?(:cljs :default :clj Exception) (denominator 1.0))) 13 | (is (thrown? #?(:cljs :default :clj Exception) (denominator 1N))) 14 | (is (thrown? #?(:cljs :default :clj Exception) (denominator 1.0M))) 15 | (is (thrown? #?(:cljs :default :clj Exception) (denominator ##Inf))) 16 | (is (thrown? #?(:cljs :default :clj Exception) (denominator ##NaN))) 17 | (is (thrown? #?(:cljs :default :clj Exception) (denominator nil))))) 18 | -------------------------------------------------------------------------------- /test/clojure/core_test/double.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.double 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/double 6 | (deftest test-double 7 | (are [expected x] (= expected (double x)) 8 | (double 1.0) 1 9 | (double 0.0) 0 10 | (double -1.0) -1 11 | (double 1.0) 1N 12 | (double 0.0) 0N 13 | (double -1.0) -1N 14 | (double 1.0) 12/12 15 | (double 0.0) 0/12 16 | (double -1.0) -12/12 17 | (double 1.0) 1.0M 18 | (double 0.0) 0.0M 19 | (double -1.0) -1.0M) 20 | (is (NaN? (double ##NaN))) 21 | 22 | #?@(:cljs 23 | ;; In cljs, `double` is just returns the argument unchanged (dummy fn) 24 | [(is (= "0" (double "0"))) 25 | (is (= :0 (double :0)))] 26 | :default 27 | [(is (thrown? #?(:clj Exception) (double "0"))) 28 | (is (thrown? #?(:clj Exception) (double :0)))]) 29 | 30 | #?@(:clj 31 | [(is (instance? java.lang.Double (double 0))) 32 | (is (instance? java.lang.Double (double 0.0))) 33 | (is (instance? java.lang.Double (double 0N))) 34 | (is (instance? java.lang.Double (double 0.0M)))]))) 35 | -------------------------------------------------------------------------------- /test/clojure/core_test/double_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.double-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/double? 7 | (deftest test-double? 8 | (are [expected x] (= expected (double? x)) 9 | #?@(:cljs ; In CLJS, all numbers satisfy `double?` 10 | [true 0 11 | true 1 12 | true -1 13 | true r/max-int 14 | true r/min-int 15 | true 0.0 16 | true 1.0 17 | true -1.0 18 | true (float 0.0) ; surprising since (float? (double 0.0)) = true 19 | true (float 1.0) ; surprising since (float? (double 1.0)) = true 20 | true (float -1.0) ; surprising since (float? (double -1.0)) = true 21 | true (double 0.0) 22 | true (double 1.0) 23 | true (double -1.0) 24 | true r/max-double 25 | true r/min-double 26 | true ##Inf 27 | true ##-Inf 28 | true ##NaN 29 | true 0N 30 | true 1N 31 | true -1N 32 | true 0.0M 33 | true 1.0M 34 | true -1.0M] 35 | :default 36 | [false 0 37 | false 1 38 | false -1 39 | false r/max-int 40 | false r/min-int 41 | true 0.0 42 | true 1.0 43 | true -1.0 44 | false (float 0.0) ; surprising since (float? (double 0.0)) = true 45 | false (float 1.0) ; surprising since (float? (double 1.0)) = true 46 | false (float -1.0) ; surprising since (float? (double -1.0)) = true 47 | true (double 0.0) 48 | true (double 1.0) 49 | true (double -1.0) 50 | true r/max-double 51 | true r/min-double 52 | true ##Inf 53 | true ##-Inf 54 | true ##NaN 55 | false 0N 56 | false 1N 57 | false -1N 58 | false 0.0M 59 | false 1.0M 60 | false -1.0M]) 61 | #?@(:cljs [] ; CLJS doesn't have ratios 62 | :default 63 | [false 0/2 64 | false 1/2 65 | false -1/2]) false nil 66 | false true 67 | false false 68 | false "a string" 69 | false "0" 70 | false "1" 71 | false "-1" 72 | false {:a :map} 73 | false #{:a-set} 74 | false [:a :vector] 75 | false '(:a :list) 76 | false \0 77 | false \1 78 | false :a-keyword 79 | false :0 80 | false :1 81 | false :-1 82 | false 'a-sym))) 83 | -------------------------------------------------------------------------------- /test/clojure/core_test/drop.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.drop 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/drop 6 | (deftest test-drop 7 | (is (= (range 1 10) (drop 1 (range 0 10)))) 8 | (is (= (range 5 10) (drop 5 (range 0 10)))) 9 | (is (= 5 (first (drop 5 (range))))) ; lazy version handles infinite `range` 10 | (is (= '() (drop 5 nil))) ; nil acts as empty list 11 | 12 | ;; Transducer version 13 | (is (= (vec (range 5 10)) (into [] (drop 5) (range 0 10)))) 14 | 15 | ;; Note that we can drop from other types of collections, but 16 | ;; because they are not sequential, we don't know exactly what the 17 | ;; result will be. This tests that something truthy remained after 18 | ;; dropping one item and that `drop` didn't throw when given maps 19 | ;; or sets. We need `doall` here to force the realization of the 20 | ;; lazy seq created by `drop`. 21 | (is (doall (drop 1 {:a 1 :b 2 :c 3}))) 22 | (is (doall (drop 1 #{:a :b :c}))) 23 | 24 | ;; Negative tests 25 | (is (thrown? #?(:cljs :default :clj Exception) 26 | (doall (drop nil (range 0 10))))) 27 | (is (thrown? #?(:cljs :default :clj Exception) 28 | (into [] (drop nil) (range 0 10)))))) 29 | -------------------------------------------------------------------------------- /test/clojure/core_test/drop_last.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.drop-last 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/drop-last 6 | (deftest test-drop-last 7 | ;; drop the last item 8 | (= (range 0 9) (drop-last (range 0 10))) 9 | (= '() (drop-last nil)) 10 | ;; drop the last n items 11 | (= (range 0 5) (drop-last 5 (range 0 10))) 12 | (= '() (drop-last 5 nil)) 13 | 14 | 15 | ;; Negative tests 16 | ;; Note: `doall` is required to realize the lazy sequence and 17 | ;; force it to throw 18 | (is (thrown? #?(:cljs :default :clj Exception) 19 | (doall (drop-last nil (range 5))))))) 20 | -------------------------------------------------------------------------------- /test/clojure/core_test/drop_while.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.drop-while 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/drop-while 6 | (deftest test-drop-while 7 | (is (= (range 5 10) (drop-while #(< % 5) (range 0 10)))) 8 | (is (= 5 (first (drop-while #(< % 5) (range))))) ; lazy infinite `range` 9 | (is (= '(1 2 3) (drop-while keyword? [:a :b :c 1 2 3]))) 10 | (is (= '() (drop-while #(< % 5) nil))) 11 | 12 | ;; Transducer 13 | (is (= (vec (range 5 10)) (into [] (drop-while #(< % 5)) (range 0 10)))) 14 | (is (= [1 2 3] (into [] (drop-while keyword?) [:a :b :c 1 2 3]))) 15 | (is (= [] (into [] (drop-while #(< % 5)) nil))) 16 | 17 | ;; Negative tests 18 | (is (thrown? #?(:cljs :default :clj Exception) 19 | (doall (drop-while nil (range 0 10))))) 20 | (is (thrown? #?(:cljs :default :clj Exception) 21 | (into [] (drop-while nil) (range 0 10)))))) 22 | -------------------------------------------------------------------------------- /test/clojure/core_test/eq.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.eq 2 | (:require [clojure.test :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | ;; Doesn't test (yet): 6 | ;; * Java collections for JVM Clojure 7 | ;; * clojure.lang.PersistentQueue 8 | ;; * ##Inf and some other special forms 9 | ;; * Records 10 | 11 | (defn tests [eq] 12 | (testing "two scalars" 13 | (are [in ex] (eq in ex) 14 | nil nil 15 | true true 16 | false false 17 | \a \a 18 | "green" "green" 19 | :eggs :eggs 20 | :and/ham :and/ham 21 | 'one-fish 'one-fish 22 | 'two/fish 'two/fish 23 | 42 42 24 | 3.14 3.14 25 | 3.141592M 3.141592M)) 26 | 27 | (testing "two scalars unequal" 28 | (are [in ex] (not (eq in ex)) 29 | nil false 30 | true false 31 | \a \b 32 | "yellow" "purple" 33 | :hello :goodbye 34 | :my/hello 'my/hello 35 | :my/hello :your/hello 36 | 'one-fish 'two-fish 37 | 'red/fish 'red/coral)) 38 | 39 | (testing "a string is not a list of chars" 40 | (is (not (eq "hello" '(\h \e \l \l \o))))) 41 | 42 | (testing "collections" 43 | (are [in ex] (eq in ex) 44 | [] '() 45 | '() [] 46 | [1 2 3] '(1 2 3) 47 | '(1 2 3) [1 2 3] 48 | [0 1 2] (range 3) 49 | '(0 1 2) (range 3) 50 | {:a 1 "b" :2 3 \c \d 4} {"b" :2 \d 4 3 \c :a 1} 51 | #{:a \b "c"} #{\b "c" :a})) 52 | 53 | (testing "collections unequal" 54 | (are [in ex] (not (eq in ex)) 55 | nil '() 56 | nil [] 57 | nil #{} 58 | '() #{} 59 | '() {} 60 | [] #{} 61 | [] {} 62 | #{} {} 63 | [1 2 3] #{1 2 3} 64 | '(1 2 3) #{1 2 3} 65 | {:a 1 "b" \c} {:a "1" "b" \c} 66 | #{:a \b "c"} #{\b "d" :a} 67 | [1 2 3] [3 2 1] 68 | '(1 2 3) '(3 2 1) 69 | [\a \b \c] {0 \a 1 \b 2 \c} 70 | [\a ##NaN] [\a ##NaN] 71 | #{1.0 2.0 ##NaN} #{1.0 2.0 ##NaN})) 72 | 73 | (testing "sorted collections" 74 | (are [in ex] (eq in ex) 75 | {:b 14 :c 15 :a 13} (sorted-map :a 13 :b 14 :c 15) 76 | (sorted-map-by < 13 :a 14 :b 15 :c) (sorted-map-by > 13 :a 14 :b 15 :c) 77 | #{6 4 2} (sorted-set 4 2 6) 78 | (sorted-set-by > 4 2 6) (sorted-set-by < 4 2 6))) 79 | 80 | (testing "nested collections" 81 | (are [in ex] (eq in ex) 82 | {#{} ['()]} {#{} ['()]} 83 | {:just '(:a {:plain [:simple #{:tailor}]})} {:just '(:a {:plain [:simple #{:tailor}]})} 84 | [1 '(2 3 [4])] (list 1 [2 3 '(4)]))) 85 | 86 | (testing "regex" 87 | ;; Value-equal regex are NOT eq, only identical? 88 | (is (not (eq #"my regex" #"my regex"))) 89 | (is (let [r #"my regex" 90 | r' r] 91 | (eq r r')))) 92 | 93 | (testing "functions" 94 | ;; identical? functions are eq, but no other functions 95 | (is (not (eq #(+ 2 %) #(+ 2 %)))) 96 | (is (let [f #(+ 2 %) 97 | f' f] 98 | (eq f f')))) 99 | 100 | (testing "variadic eq" 101 | (is (eq 2 2 2)) 102 | (is (eq "beep" "beep" "beep" "beep")) 103 | (is (let [my-inc #(+ 1 %)] 104 | (eq my-inc my-inc my-inc))) 105 | (is (not (eq '() [] [] (list) {}))) 106 | (is (not (eq 2 2 3 2 2 2 2))) 107 | (is (not (eq nil \a \a \a)))) 108 | 109 | ;; Platform differences 110 | #?(:clj (testing "jvm" 111 | (are [in ex eq?] (identical? eq? (eq in ex)) 112 | 2 2.0 false 113 | (float 0.1) (double 0.1) false 114 | (float 0.5) (double 0.5) true 115 | 1M 1 false 116 | ;; ratios do not read in CLJS 117 | 22/7 44/14 true 118 | ;; https://clojure.org/guides/equality notes that sometimes 119 | ;; collections with ##NaN are eq 120 | (list ##NaN) (list ##NaN) true)) 121 | 122 | :cljs (testing "cljs" 123 | (are [in ex eq?] (identical? eq? (eq in ex)) 124 | 2 2.0 true 125 | (float 0.1) (double 0.1) true 126 | (float 0.5) (double 0.5) true 127 | 1M 1 true 128 | (list ##NaN) (list ##NaN) false 129 | ##NaN ##NaN false)))) 130 | 131 | (when-var-exists clojure.core/= 132 | (deftest test-eq 133 | (tests =) 134 | ;; This is to accomodate a not= JVM bug. See not_eq.cljc 135 | (testing "If ##NaNs are =" 136 | (is (not (= ##NaN ##NaN)))))) 137 | -------------------------------------------------------------------------------- /test/clojure/core_test/even_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.even-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/even? 6 | (deftest test-even? 7 | (testing "common" 8 | (are [in ex] (= (even? in) ex) 9 | 0 true 10 | -0 true 11 | 12 true 12 | 17 false 13 | -118 true 14 | -119 false 15 | 123N false 16 | 122N true 17 | -121N false 18 | -120N true)) 19 | 20 | (testing "invalid" 21 | (are [x] (thrown? #?(:cljs :default :clj Exception) (even? x)) 22 | #_:clj-kondo/ignore nil 23 | ##Inf 24 | ##-Inf 25 | ##NaN 26 | 1.5 27 | #?@(:cljs [] 28 | :default 29 | [1/2]) 30 | 0.2M)))) 31 | -------------------------------------------------------------------------------- /test/clojure/core_test/false_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.false-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/false? 7 | (deftest test-false? 8 | (are [expected x] (= expected (false? x)) 9 | false 0 10 | false 1 11 | false -1 12 | false r/max-int 13 | false r/min-int 14 | false 0.0 15 | false 1.0 16 | false -1.0 17 | false (float 0.0) 18 | false (float 1.0) 19 | false (float -1.0) 20 | false (double 0.0) 21 | false (double 1.0) 22 | false (double -1.0) 23 | false r/max-double 24 | false r/min-double 25 | false ##Inf 26 | false ##-Inf 27 | false ##NaN 28 | false 0N 29 | false 1N 30 | false -1N 31 | #?@(:cljs [] 32 | :default [false 0/2 33 | false 1/2 34 | false -1/2]) 35 | false 0.0M 36 | false 1.0M 37 | false -1.0M 38 | false nil 39 | false true 40 | true false 41 | false "a string" 42 | false "0" 43 | false "1" 44 | false "-1" 45 | false "true" 46 | false "false" 47 | false {:a :map} 48 | false #{:a-set} 49 | false [:a :vector] 50 | false '(:a :list) 51 | false \0 52 | false \1 53 | false :a-keyword 54 | false :true 55 | false :false 56 | false :0 57 | false :1 58 | false :-1 59 | false 'a-sym))) 60 | -------------------------------------------------------------------------------- /test/clojure/core_test/first.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.first 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/first 6 | (deftest test-first 7 | (is (= 0 (first (range 0 10)))) 8 | (is (= 0 (first (range)))) ; infinite lazy seq 9 | (is (= :a (first [:a :b :c]))) 10 | (is (= :a (first '(:a :b :c)))) 11 | (is (nil? (first '()))) 12 | (is (nil? (first []))) 13 | (is (nil? (first nil))))) 14 | -------------------------------------------------------------------------------- /test/clojure/core_test/float.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.float 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/float 7 | (deftest test-float 8 | (are [expected x] (= expected (float x)) 9 | (float 1.0) 1 10 | (float 0.0) 0 11 | (float -1.0) -1 12 | (float 1.0) 1N 13 | (float 0.0) 0N 14 | (float -1.0) -1N 15 | ;; The CLJS reader will read these values and convert to 16 | ;; double. Since they are all clean conversions, they match 17 | (float 1.0) 12/12 18 | (float 0.0) 0/12 19 | (float -1.0) -12/12 20 | (float 1.0) 1.0M 21 | (float 0.0) 0.0M 22 | (float -1.0) -1.0M 23 | ;; Since CLJS numbers are all doubles, casting r/min-double to a 24 | ;; float doesn't do anything, whereas in Clojure JVM it rounds 25 | ;; down to zero. 26 | #?@(:cljs [r/min-double r/min-double] 27 | :default [(float 0.0) r/min-double])) 28 | (is (NaN? (float ##NaN))) 29 | 30 | #?@(:cljs 31 | [(is (= r/max-double (float r/max-double))) 32 | (is (= ##Inf (float ##Inf))) 33 | (is (= ##-Inf (float ##-Inf))) 34 | (is (= "0" (float "0"))) 35 | (is (= :0 (float :0)))] 36 | :default [(is (thrown? #?(:clj Exception) (float r/max-double))) 37 | (is (thrown? #?(:clj Exception) (float ##Inf))) 38 | (is (thrown? #?(:clj Exception) (float ##-Inf))) 39 | (is (thrown? #?(:clj Exception) (float "0"))) 40 | (is (thrown? #?(:clj Exception) (float :0)))]) 41 | 42 | #?@(:clj 43 | [(is (instance? java.lang.Float (float 0))) 44 | (is (instance? java.lang.Float (float 0.0))) 45 | (is (instance? java.lang.Float (float 0N))) 46 | (is (instance? java.lang.Float (float 0.0M)))]))) 47 | -------------------------------------------------------------------------------- /test/clojure/core_test/float_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.float-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/float? 7 | (deftest test-float? 8 | (are [expected x] (= expected (float? x)) 9 | #?@(:cljs ; In CLJS all numbers satisfy `float?` 10 | [true 0 11 | true 1 12 | true -1 13 | true r/max-int 14 | true r/min-int 15 | true 0.0 16 | true 1.0 17 | true -1.0 18 | true (float 0.0) 19 | true (float 1.0) 20 | true (float -1.0) 21 | true (double 0.0) 22 | true (double 1.0) 23 | true (double -1.0) 24 | true r/max-double 25 | true r/min-double 26 | true ##Inf 27 | true ##-Inf 28 | true ##NaN 29 | true 0N 30 | true 1N 31 | true -1N 32 | true 0.0M 33 | true 1.0M 34 | true -1.0M] 35 | :default 36 | [false 0 37 | false 1 38 | false -1 39 | false r/max-int 40 | false r/min-int 41 | true 0.0 42 | true 1.0 43 | true -1.0 44 | true (float 0.0) 45 | true (float 1.0) 46 | true (float -1.0) 47 | true (double 0.0) 48 | true (double 1.0) 49 | true (double -1.0) 50 | true r/max-double 51 | true r/min-double 52 | true ##Inf 53 | true ##-Inf 54 | true ##NaN 55 | false 0N 56 | false 1N 57 | false -1N 58 | false 0.0M 59 | false 1.0M 60 | false -1.0M]) 61 | #?@(:cljs [] ; CLJS doesn't have ratios 62 | :default 63 | [false 0/2 64 | false 1/2 65 | false -1/2]) 66 | false nil 67 | false true 68 | false false 69 | false "a string" 70 | false "0" 71 | false "1" 72 | false "-1" 73 | false {:a :map} 74 | false #{:a-set} 75 | false [:a :vector] 76 | false '(:a :list) 77 | false \0 78 | false \1 79 | false :a-keyword 80 | false :0 81 | false :1 82 | false :-1 83 | false 'a-sym))) 84 | -------------------------------------------------------------------------------- /test/clojure/core_test/fnil.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.fnil 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/fnil 6 | (defn test-fn [& x] 7 | (into [] x)) 8 | 9 | (def arg 'not-nil) 10 | 11 | (deftest fnil-test 12 | (let [arity-1 (fnil test-fn 100)] 13 | (is (= [100] (arity-1 nil))) 14 | (is (= [arg] (arity-1 arg)))) 15 | (let [arity-2 (fnil test-fn 100 200)] 16 | (is (= [100 200] (arity-2 nil nil))) 17 | (is (= [arg 200] (arity-2 arg nil))) 18 | (is (= [100 arg] (arity-2 nil arg))) 19 | (is (= [arg arg] (arity-2 arg arg)))) 20 | (let [arity-3 (fnil test-fn 100 200 300)] 21 | (is (= [100 200 300] (arity-3 nil nil nil))) 22 | (is (= [arg 200 300] (arity-3 arg nil nil))) 23 | (is (= [100 arg 300] (arity-3 nil arg nil))) 24 | (is (= [100 200 arg] (arity-3 nil nil arg))) 25 | (is (= [arg arg 300] (arity-3 arg arg nil))) 26 | (is (= [100 arg arg] (arity-3 nil arg arg))) 27 | (is (= [arg 200 arg] (arity-3 arg nil arg))) 28 | (is (= [arg arg arg] (arity-3 arg arg arg)))) 29 | (let [arity-+ (fnil test-fn 100 200 300)] 30 | (is (= [100 200 300 arg] (arity-+ nil nil nil arg))) 31 | (is (= [arg 200 300 arg] (arity-+ arg nil nil arg))) 32 | (is (= [100 arg 300 arg] (arity-+ nil arg nil arg))) 33 | (is (= [100 200 arg arg] (arity-+ nil nil arg arg)))))) 34 | -------------------------------------------------------------------------------- /test/clojure/core_test/format.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.format 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/format 6 | ;;; Note that `format` presents a bit of a conundrum for 7 | ;;; testing. Clojure JVM delegates the formatting task to 8 | ;;; Java. ClojureScript doesn't implement `format`. Other Clojure 9 | ;;; implementations may take different paths. Even when `format` is 10 | ;;; implemented, the full scope of Java's `java.util.Formatter` 11 | ;;; functionality may not be there. Thus, we take a very conservative 12 | ;;; approach here for the default case of just testing to verify that 13 | ;;; the function exists and that a simple format string with no escape 14 | ;;; characters passes through `format` unharmed. 15 | ;;; See: https://clojurians.slack.com/archives/C03SRH97FDK/p1733853098700809 16 | 17 | (deftest test-format 18 | #?@(:cljs [] ; CLJS doesn't have `format` 19 | :default 20 | [(is (= "test" (format "test")))]))) 21 | -------------------------------------------------------------------------------- /test/clojure/core_test/get.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.get 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/get 6 | (deftest test-get 7 | (let [arr (to-array [1 2])] 8 | ;; two-arg 9 | (are [expected m key] (= expected (get m key)) 10 | nil nil nil 11 | nil nil :a 12 | nil {} :a 13 | nil #{} :a 14 | nil [] 1 15 | nil "" 1 16 | 1 {:a 1 :b 2} :a 17 | nil {:a 1 :b 2} :z 18 | :a #{:a :b} :a 19 | nil #{:a :b} :z 20 | :a [:a :b] 0 21 | nil [:a :b] 10 22 | #?(:cljs "a", :default \a) "ab" 0 23 | nil "ab" 10 24 | 1 arr 0 25 | nil arr 10) 26 | 27 | ;; three-arg 28 | (are [expected m key not-found] (= expected (get m key not-found)) 29 | :not-found nil :a :not-found 30 | 31 | :not-found {} :a :not-found 32 | :not-found #{} :a :not-found 33 | :not-found [] 1 :not-found 34 | :not-found "" 1 :not-found 35 | 1 {:a 1 :b 2} :a :not-found 36 | :not-found {:a 1 :b 2} :z :not-found 37 | :a #{:a :b} :a :not-found 38 | :not-found #{:a :b} :z :not-found 39 | :a [:a :b] 0 :not-found 40 | :not-found [:a :b] 10 :not-found 41 | #?(:cljs "a", :default \a) "ab" 0 :not-found 42 | :not-found "ab" 10 :not-found 43 | 1 arr 0 :not-found 44 | :not-found arr 10 :not-found)))) 45 | -------------------------------------------------------------------------------- /test/clojure/core_test/ident_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.ident-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/ident? 6 | (deftest test-ident? 7 | (are [expected x] (= expected (ident? x)) 8 | true :a-keyword 9 | true 'a-symbol 10 | true :a-ns/a-keyword 11 | true 'a-ns/a-keyword 12 | false "a string" 13 | false 0 14 | false 0N 15 | false 0.0 16 | #?@(:cljs [] 17 | :default 18 | [false 1/2]) 19 | false 0.0M 20 | false false 21 | false true 22 | false nil))) 23 | -------------------------------------------------------------------------------- /test/clojure/core_test/identical_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.identical-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/identical? 6 | (deftest test-identical? 7 | ;; objects that are the same object are identical 8 | (let [x (hash-map) 9 | ;; this forces y to be a different object than x 10 | y (-> (hash-map :a-key :a-val) 11 | (dissoc :a-key))] 12 | ;; x and y are equal, but they are not identical 13 | (is (= x y)) 14 | (is (not (identical? x y))) 15 | ;; but each is identical with itself 16 | (is (identical? x x)) 17 | (is (identical? y y))))) 18 | -------------------------------------------------------------------------------- /test/clojure/core_test/inc.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.inc 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/inc 6 | (deftest test-inc 7 | (testing "common" 8 | (are [in ex] (= (inc in) ex) 9 | 0 1 10 | 1 2 11 | -1 0 12 | 0N 1N 13 | -1N 0N 14 | 14411 14412 15 | -4 -3 16 | 6.4 7.4 ; risky 17 | #?@(:cljs [] 18 | :default 19 | [1/2 3/2 20 | -1/2 1/2]) 21 | ##Inf ##Inf 22 | ##-Inf ##-Inf) 23 | 24 | (is (NaN? (inc ##NaN)))) 25 | 26 | (testing "overflow" 27 | #?(:clj (is (thrown? Exception (inc Long/MAX_VALUE))) 28 | :cljs (is (= (inc js/Number.MAX_SAFE_INTEGER) (+ 2 js/Number.MAX_SAFE_INTEGER))) 29 | :default (is false "overflow untested"))) 30 | 31 | (testing "inc-nil" 32 | ;; ClojureScript says (= 1 (inc nil)) because JavaScript casts null to 0 33 | ;; https://clojuredocs.org/clojure.core/inc#example-6156a59ee4b0b1e3652d754f 34 | #?(:cljs (is (= 1 (inc #_:clj-kondo/ignore nil))) 35 | :default (is (thrown? #?(:clj Exception) (inc #_:clj-kondo/ignore nil))))))) 36 | -------------------------------------------------------------------------------- /test/clojure/core_test/int.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.int 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/int 6 | (deftest test-int 7 | ;; There is no platform independent predicate to test specifically 8 | ;; for an int. While `int?` exists, it returns true for any 9 | ;; fixed-range integer type (e.g., byte, short, int, or long). In 10 | ;; ClojureJVM, it's an instance of `java.lang.Integer`, but there is no 11 | ;; predicate for it. Here, we just test whether it's a fixed-length 12 | ;; integer of some sort. 13 | (is (int? (int 0))) 14 | #?(:clj (is (instance? java.lang.Integer (int 0)))) 15 | 16 | ;; Check conversions and rounding from other numeric types 17 | (are [expected x] (= expected (int x)) 18 | -2147483648 -2147483648 19 | 0 0 20 | 2147483647 2147483647 21 | 1 1N 22 | 0 0N 23 | -1 -1N 24 | 1 1.0M 25 | 0 0.0M 26 | -1 -1.0M 27 | 1 1.1 28 | -1 -1.1 29 | 1 1.9 30 | 1 1.1M 31 | -1 -1.1M 32 | #?@(:cljs [] ; The CLSJ compiler barfs on 33 | ; these for some unknown 34 | ; reason. Interestingly, they 35 | ; work in a CLJS REPL. 36 | :default 37 | [1 3/2 38 | -1 -3/2 39 | 0 1/10 40 | 0 -1/10])) 41 | 42 | #?@(:cljs [] 43 | :default 44 | [ ;; `int` throws outside the range of 32767 ... -32768. 45 | (is (thrown? #?(:clj Exception) (int -2147483648.000001))) 46 | (is (thrown? #?(:clj Exception) (int -2147483649))) 47 | (is (thrown? #?(:clj Exception) (int 2147483648))) 48 | (is (thrown? #?(:clj Exception) (int 2147483647.000001))) 49 | 50 | ;; Check handling of other types 51 | (is (thrown? #?(:clj Exception) (int "0"))) 52 | (is (thrown? #?(:clj Exception) (int :0))) 53 | (is (thrown? #?(:clj Exception) (int [0]))) 54 | (is (thrown? #?(:clj Exception) (int nil)))]))) 55 | -------------------------------------------------------------------------------- /test/clojure/core_test/int_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.int-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/int? 7 | (deftest test-int? 8 | (are [expected x] (= expected (int? x)) 9 | true 0 10 | true 1 11 | true -1 12 | true r/max-int 13 | true r/min-int 14 | #?@(:cljs [true] :default [false]) 0.0 15 | #?@(:cljs [true] :default [false]) 1.0 16 | #?@(:cljs [true] :default [false]) -1.0 17 | false 0.1 18 | false 1.1 19 | false -1.1 20 | false r/max-double 21 | false r/min-double 22 | false ##Inf 23 | false ##-Inf 24 | false ##NaN 25 | #?@(:cljs [true] :default [false]) 0N 26 | #?@(:cljs [true] :default [false]) 1N 27 | #?@(:cljs [true] :default [false]) -1N 28 | #?@(:cljs [] 29 | :default 30 | [true 0/2 ; perhaps surprising 31 | false 1/2 32 | false -1/2]) 33 | #?@(:cljs [true] :default [false]) 0.0M 34 | #?@(:cljs [true] :default [false]) 1.0M 35 | #?@(:cljs [true] :default [false]) -1.0M 36 | false nil 37 | false true 38 | false false 39 | false "a string" 40 | false "0" 41 | false "1" 42 | false "-1" 43 | false {:a :map} 44 | false #{:a-set} 45 | false [:a :vector] 46 | false '(:a :list) 47 | false \0 48 | false \1 49 | false :a-keyword 50 | false :0 51 | false :1 52 | false :-1 53 | false 'a-sym))) 54 | -------------------------------------------------------------------------------- /test/clojure/core_test/integer_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.integer-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/integer? 7 | (deftest test-integer? 8 | (are [expected x] (= expected (integer? x)) 9 | true 0 10 | true 1 11 | true -1 12 | true r/max-int 13 | true r/min-int 14 | #?@(:cljs [true] :default [false]) 0.0 15 | #?@(:cljs [true] :default [false]) 1.0 16 | #?@(:cljs [true] :default [false]) -1.0 17 | false 0.1 18 | false 1.1 19 | false -1.1 20 | false r/max-double 21 | false r/min-double 22 | false ##Inf 23 | false ##-Inf 24 | false ##NaN 25 | true 0N 26 | true 1N 27 | true -1N 28 | #?@(:cljs [] 29 | :default 30 | [true 0/2 ; perhaps surprising 31 | false 1/2 32 | false -1/2]) 33 | #?@(:cljs [true] :default [false]) 0.0M 34 | #?@(:cljs [true] :default [false]) 1.0M 35 | #?@(:cljs [true] :default [false]) -1.0M 36 | false nil 37 | false true 38 | false false 39 | false "a string" 40 | false "0" 41 | false "1" 42 | false "-1" 43 | false {:a :map} 44 | false #{:a-set} 45 | false [:a :vector] 46 | false '(:a :list) 47 | false \0 48 | false \1 49 | false :a-keyword 50 | false :0 51 | false :1 52 | false :-1 53 | false 'a-sym))) 54 | -------------------------------------------------------------------------------- /test/clojure/core_test/interleave.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.interleave 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists 6 | clojure.core/interleave 7 | (deftest test-interleave 8 | (testing "common cases" 9 | (are [in ex] (= (apply interleave in) ex) 10 | [[1 2 3]] [1 2 3] 11 | [[1 2 3] ["a" "b" "c"]] [1 "a" 2 "b" 3 "c"] 12 | [[1 2 3] 13 | ["a" "b" "c"] 14 | [\a \b \c]] [1 "a" \a 2 "b" \b 3 "c" \c] 15 | [#{1} #{"a"}] [1 "a"] 16 | [(sorted-set 1 2 3) 17 | (sorted-set "a" "b" "c")] [1 "a" 2 "b" 3 "c"] 18 | [(sorted-map :a 1 :b 2) 19 | ["a" "b"]] [[:a 1] "a" [:b 2] "b"] 20 | ['(1 2 3) '("a" "b" "c")] [1 "a" 2 "b" 3 "c"] 21 | ["123" "abc"] [\1 \a \2 \b \3 \c] 22 | [[:a] [nil]] [:a nil] 23 | [[nil] [:a] [nil]] [nil :a nil]) 24 | (testing "Differing sequence sizes, nil inputs" 25 | (are [in ex] (= (apply interleave in) ex) 26 | [[1 2] 27 | ["a" "b" "c"] 28 | "1234567"] [1 "a" \1 2 "b" \2] 29 | [[1 2 3 4 5] 30 | ["a" "b" "c"] 31 | "12"] [1 "a" \1 2 "b" \2] 32 | ['(1 2 3) '("a" "b")] [1 "a" 2 "b"] 33 | [(range) '("a" "b")] [0 "a" 1 "b"] 34 | [(range) nil] [] 35 | [nil (range)] []))))) 36 | -------------------------------------------------------------------------------- /test/clojure/core_test/intern.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.intern 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/intern 6 | (deftest test-intern 7 | ;; Intern and bind 8 | (let [x-var (intern 'clojure.core-test.intern 'x 42)] 9 | (is (= 42 (var-get x-var)))) 10 | 11 | ;; Use intern to return the previously interned var 12 | (let [x-var (intern 'clojure.core-test.intern 'x)] 13 | (is (= 42 (var-get x-var)))) 14 | 15 | ;; Create new namespace and use that as argument to intern 16 | (let [n (create-ns 'avoid-a-clash) 17 | x-var (intern n 'x 42)] 18 | (is (= 42 (var-get x-var)))) 19 | 20 | (let [x-var (intern 'avoid-a-clash 'x)] 21 | (is (= 42 (var-get x-var)))) 22 | 23 | ;; Trying to intern to an unknown namespace should throw 24 | (is (thrown? #?(:cljs :default :clj Exception) (intern 'unknown-namespace 'x))) 25 | (is (thrown? #?(:cljs :default :clj Exception) (intern 'unknonw-namespace 'x 42))))) 26 | -------------------------------------------------------------------------------- /test/clojure/core_test/interpose.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.interpose 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists 6 | clojure.core/interpose 7 | (deftest test-interpose 8 | (testing "common cases" 9 | (is (fn? (interpose "a"))) 10 | (are [in ex] (= (apply interpose in) ex) 11 | ["a" [1 2 3]] [1 "a" 2 "a" 3] 12 | [#{1} #{"a"}] ["a"] 13 | [(sorted-set 1 2 3) 14 | (sorted-set "a" "b" "c")] ["a" (sorted-set 1 2 3) 15 | "b" (sorted-set 1 2 3) 16 | "c"] 17 | ["a" 18 | (sorted-map :a 1 :b 2)] [[:a 1] "a" [:b 2]] 19 | [1 '("a" "b" "c")] ["a" 1 "b" 1 "c"] 20 | ["1" "abc"] [\a "1" \b "1" \c] 21 | [[:a] [nil]] [nil]) 22 | (testing "nil inputs" 23 | (are [in ex] (= (apply interpose in) ex) 24 | [nil [1 2 3]] [1 nil 2 nil 3] 25 | [1 nil] '()))))) 26 | -------------------------------------------------------------------------------- /test/clojure/core_test/keyword.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.keyword 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/keyword 6 | (deftest test-keyword 7 | ;; "Symbols begin with a non-numeric character and can contain 8 | ;; alphanumeric characters and *, +, !, -, _, ', ?, <, > and = 9 | ;; (other characters may be allowed eventually)." 10 | ;; 11 | ;; "Keywords are like symbols, except: * They can and must begin with a colon, e.g. :fred." 12 | ;; 13 | ;; (see http://clojure.org/reader for details) 14 | ;; 15 | ;; From https://clojuredocs.org/clojure.core/keyword 16 | ;; keyword does not validate input strings for ns and name, and may 17 | ;; return improper keywords with undefined behavior for non-conformant 18 | ;; ns and name. 19 | 20 | (are [expected name] (= expected (keyword name)) 21 | :abc "abc" 22 | :abc 'abc 23 | :abc :abc 24 | :* "*" 25 | :* '* 26 | :* :* 27 | :+ "+" 28 | :+ '+ 29 | :+ :+ 30 | :! "!" 31 | :! '! 32 | :! :! 33 | :- "-" 34 | :- '- 35 | :- :- 36 | :_ "_" 37 | :_ '_ 38 | :_ :_ 39 | :? "?" 40 | :? '? 41 | :? :? 42 | :< "<" 43 | :< '< 44 | :< :< 45 | :> ">" 46 | :> '> 47 | :> :> 48 | := "=" 49 | := '= 50 | := := 51 | :abc*+!-_'?<>= "abc*+!-_'?<>=") 52 | 53 | (are [expected ns name] (= expected (keyword ns name)) 54 | :abc/abc "abc" "abc" 55 | :abc.def/abc "abc.def" "abc" 56 | 57 | :*/abc "*" "abc" 58 | :+/abc "+" "abc" 59 | :!/abc "!" "abc" 60 | :-/abc "-" "abc" 61 | :_/abc "_" "abc" 62 | :?/abc "?" "abc" 63 | :/abc ">" "abc" 65 | :=/abc "=" "abc" 66 | 67 | :abc.def/* "abc.def" "*" 68 | :abc.def/+ "abc.def" "+" 69 | :abc.def/! "abc.def" "!" 70 | :abc.def/- "abc.def" "-" 71 | :abc.def/_ "abc.def" "_" 72 | :abc.def/? "abc.def" "?" 73 | :abc.def/< "abc.def" "<" 74 | :abc.def/> "abc.def" ">" 75 | :abc.def/= "abc.def" "=" 76 | 77 | :abc*+!-_'?<>=/abc*+!-_'?<>= "abc*+!-_'?<>=" "abc*+!-_'?<>=") 78 | 79 | (is (nil? (keyword nil))) ; (keyword nil) => nil, surprisingly 80 | (is (= :abc (keyword nil "abc"))) ; If ns is nil, we just ignore it. 81 | ;; But if name is nil, then maybe we throw or maybe we don't 82 | #?(:cljs nil ; CLJS creates a keyword that isn't 83 | ; readable (symbol part is null string: ":abc/") 84 | :default 85 | (is (thrown? #?(:clj Exception) (keyword "abc" nil)))) 86 | 87 | #?@(:clj 88 | ;; In Clojure JVM, two arg version requires namespace and 89 | ;; symbol to be a string, not a symbol or keyword like the one 90 | ;; arg version. 91 | [(is (thrown? #?(:clj Exception) (keyword 'abc "abc"))) 92 | (is (thrown? #?(:clj Exception) (keyword "abc" 'abc))) 93 | (is (thrown? #?(:clj Exception) (keyword :abc "abc"))) 94 | (is (thrown? #?(:clj Exception) (keyword "abc" :abc)))] 95 | :default ; + :jank 96 | ;; IMO, CLJS gets this right 97 | [(is (= :abc/abc (keyword 'abc "abc"))) 98 | (is (= :abc/abc (keyword "abc" 'abc))) 99 | (is (= :abc/abc (keyword :abc "abc"))) 100 | (is (= :abc/abc (keyword "abc" :abc)))]))) 101 | -------------------------------------------------------------------------------- /test/clojure/core_test/keyword_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.keyword-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/keyword? 6 | (deftest test-keyword? 7 | (are [expected x] (= expected (keyword? x)) 8 | true :a-keyword 9 | false 'a-symbol 10 | true :a-ns/a-keyword 11 | false 'a-ns/a-keyword 12 | false "a string" 13 | false 0 14 | false 0N 15 | false 0.0 16 | #?@(:cljs [] 17 | :default 18 | [false 1/2]) 19 | false 0.0M 20 | false false 21 | false true 22 | false nil))) 23 | -------------------------------------------------------------------------------- /test/clojure/core_test/list_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.list-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/list? 6 | (deftest test-list? 7 | (are [expected x] (= expected (list? x)) 8 | false [1 2 3] 9 | false (sorted-map :a 1) 10 | false (sorted-set :a) 11 | true '(1 2 3) 12 | false (hash-map :a 1) 13 | false (array-map :a 1) 14 | false (hash-set :a) 15 | false (seq [1 2 3]) 16 | false (seq (sorted-map :a 1)) 17 | false (seq (sorted-set :a)) 18 | false (range 0 10) 19 | false (range) 20 | false nil 21 | false 1 22 | false 1N 23 | false 1.0 24 | false 1.0M 25 | false :a-keyword 26 | false 'a-sym 27 | false "a string" 28 | false \a 29 | false (object-array 3)))) 30 | -------------------------------------------------------------------------------- /test/clojure/core_test/long.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.long 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/long 6 | (deftest test-long 7 | ;; There is no platform independent predicate to test specifically 8 | ;; for a long. In ClojureJVM, it's an instance of `java.lang.Long`, 9 | ;; but there is no predicate for it. Here, we just test whether it's 10 | ;; a fixed-length integer of some sort. 11 | (is (int? (int 0))) 12 | #?(:clj (is (instance? java.lang.Long (long 0)))) 13 | 14 | ;; Check conversions and rounding from other numeric types 15 | (are [expected x] (= expected (long x)) 16 | -9223372036854775808 -9223372036854775808 17 | 0 0 18 | 9223372036854775807 9223372036854775807 19 | 1 1N 20 | 0 0N 21 | -1 -1N 22 | 1 1.0M 23 | 0 0.0M 24 | -1 -1.0M 25 | 1 1.1 26 | -1 -1.1 27 | 1 1.9 28 | #?@(:cljs [] 29 | :default 30 | [1 3/2 31 | -1 -3/2 32 | 0 1/10 33 | 0 -1/10]) 34 | 1 1.1M 35 | -1 -1.1M) 36 | 37 | #?@(:cljs [] ; In CLJS all numbers are really doubles 38 | :default 39 | ;; `long` throws outside the range of 9223372036854775807 ... -9223372036854775808 40 | [(is (thrown? #?(:cljs :default :clj Exception) (long -9223372036854775809))) 41 | (is (thrown? #?(:cljs :default :clj Exception) (long 9223372036854775808)))]) 42 | 43 | ;; Check handling of other types 44 | #?@(:cljs 45 | [(is (= 0 (long "0"))) ; JavaScript peeking through? 46 | (is (NaN? (long :0))) 47 | (is (NaN? (long [0]))) 48 | (is (= 0 (long nil)))] ; Hm. Interesting. 49 | :default 50 | [(is (thrown? Exception (long "0"))) 51 | (is (thrown? Exception (long :0))) 52 | (is (thrown? Exception (long [0]))) 53 | (is (thrown? Exception (long nil)))]))) 54 | -------------------------------------------------------------------------------- /test/clojure/core_test/map_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.map-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/map? 6 | (deftest test-map? 7 | (are [expected x] (= expected (map? x)) 8 | false [1 2 3] 9 | true (sorted-map :a 1) 10 | false(sorted-set :a) 11 | false '(1 2 3) 12 | true (hash-map :a 1) 13 | true (array-map :a 1) 14 | false (hash-set :a) 15 | false (seq [1 2 3]) 16 | false (seq (sorted-map :a 1)) 17 | false (seq (sorted-set :a)) 18 | false (range 0 10) 19 | false (range) 20 | false nil 21 | false 1 22 | false 1N 23 | false 1.0 24 | false 1.0M 25 | false :a-keyword 26 | false 'a-sym 27 | false "a string" 28 | false \a 29 | false (object-array 3)))) 30 | -------------------------------------------------------------------------------- /test/clojure/core_test/max.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.max 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/max 6 | (deftest test-max 7 | (are [expected x y] (= expected (max x y) (max y x)) 8 | 2 1 2 9 | 2N 1N 2N 10 | 2 1N 2 11 | 2N 1 2N 12 | 2.0 1.0 2.0 13 | 2.0 1 2.0 14 | 2 1.0 2 15 | #?@(:cljs [] 16 | :default 17 | [1 1/2 1]) 18 | ##Inf 1 ##Inf 19 | 1 1 ##-Inf 20 | ##Inf ##-Inf ##Inf) 21 | 22 | ;; Single arg just returns argument 23 | (is (= 1 (max 1))) 24 | (is (= 2 (max 2))) 25 | (is (= "x" (max "x"))) ; doesn't check single arg for Number 26 | 27 | ;; Multi-arg 28 | (is (= 5 (max 1 2 3 4 5))) 29 | (is (= 5 (max 5 4 3 2 1))) 30 | (is (= 5 (max 1 2 3 4 5 ##-Inf))) 31 | (is (= ##Inf (max 1 2 3 4 5 ##Inf))) 32 | 33 | #?@(:cljs 34 | ;; There are bugs here: 35 | ;; https://clojure.atlassian.net/browse/CLJS-3425 36 | [(is (= 1 (max ##NaN 1))) ; Bug 37 | (is (NaN? (max 1 ##NaN))) ; Works as in JVM 38 | (is (NaN? (max 1 2 3 4 ##NaN))) 39 | (is (= ##Inf (max ##-Inf ##NaN ##Inf))) ; Bug 40 | (is (NaN? (max ##NaN))) 41 | 42 | (is (= "y" (max "x" "y"))) ; In CLJS "x" and "y" are characters 43 | (is (= 1 (max nil 1))) 44 | (is (= 1 (max 1 nil)))] 45 | :default 46 | [(is (NaN? (max ##NaN 1))) 47 | (is (NaN? (max 1 ##NaN))) 48 | (is (NaN? (max 1 2 3 4 ##NaN))) 49 | (is (NaN? (max ##-Inf ##NaN ##Inf))) 50 | (is (NaN? (max ##NaN))) 51 | 52 | (is (thrown? Exception (max "x" "y"))) 53 | (is (thrown? Exception (max nil 1))) 54 | (is (thrown? Exception (max 1 nil)))]))) 55 | -------------------------------------------------------------------------------- /test/clojure/core_test/min.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.min 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/min 6 | (deftest test-min 7 | (are [expected x y] (= expected (min x y) (min y x)) 8 | 1 1 2 9 | 1N 1N 2N 10 | 1N 1N 2 11 | 1 1 2N 12 | 1.0 1.0 2.0 13 | 1 1 2.0 14 | 1.0 1.0 2 15 | #?@(:cljs [] 16 | :default 17 | [1/2 1/2 1]) 18 | 1 1 ##Inf 19 | ##-Inf 1 ##-Inf 20 | ##-Inf ##-Inf ##Inf) 21 | 22 | ;; Single arg just returns argument 23 | (is (= 1 (min 1))) 24 | (is (= 2 (min 2))) 25 | (is (= "x" (min "x"))) ; doesn't check single arg for Number 26 | 27 | ;; Multi-arg 28 | (is (= 1 (min 1 2 3 4 5))) 29 | (is (= 1 (min 5 4 3 2 1))) 30 | (is (= ##-Inf (min 1 2 3 4 5 ##-Inf))) 31 | (is (= 1 (min 1 2 3 4 5 ##Inf))) 32 | 33 | #?@(:cljs 34 | ;; There are bugs here: 35 | ;; https://clojure.atlassian.net/browse/CLJS-3425 36 | [(is (= 1 (min ##NaN 1))) ; Bug 37 | (is (NaN? (min 1 ##NaN))) 38 | (is (NaN? (min 1 2 3 4 ##NaN))) 39 | (is (= ##Inf (min ##-Inf ##NaN ##Inf))) ; Bug 40 | (is (NaN? (min ##NaN))) 41 | 42 | (is (= "x" (min "x" "y"))) 43 | (is (nil? (min nil 1))) ; nil acts like zero 44 | (is (nil? (min 1 nil)))] 45 | :default 46 | [(is (NaN? (min ##NaN 1))) 47 | (is (NaN? (min 1 ##NaN))) 48 | (is (NaN? (min 1 2 3 4 ##NaN))) 49 | (is (NaN? (min ##-Inf ##NaN ##Inf))) 50 | (is (NaN? (min ##NaN))) 51 | 52 | (is (thrown? #?(:cljs :default :clj Exception) (min "x" "y"))) 53 | (is (thrown? #?(:cljs :default :clj Exception) (min nil 1))) 54 | (is (thrown? #?(:cljs :default :clj Exception) (min 1 nil)))]))) 55 | -------------------------------------------------------------------------------- /test/clojure/core_test/mod.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.mod 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]] 4 | [clojure.core-test.portability :as p])) 5 | 6 | (when-var-exists clojure.core/mod 7 | (deftest test-mod 8 | (are [type-pred expected x y] (let [r (mod x y)] 9 | (and (type-pred r) 10 | (= expected r))) 11 | int? 1 10 3 12 | int? 2 -10 3 13 | int? -1 -10 -3 14 | int? -2 10 -3 15 | 16 | ;; Note that CLJS reads big integers as doubles with the 17 | ;; fractional part equal to zero (just like CLJS ints). The 18 | ;; big-int? function is conditionalized for CLJS. 19 | p/big-int? 1N 10 3N 20 | p/big-int? 2N -10 3N 21 | p/big-int? -1N -10 -3N 22 | p/big-int? -2N 10 -3N 23 | 24 | p/big-int? 1N 10N 3 25 | p/big-int? 2N -10N 3 26 | p/big-int? -1N -10N -3 27 | p/big-int? -2N 10N -3 28 | 29 | p/big-int? 1N 10N 3N 30 | p/big-int? 2N -10N 3N 31 | p/big-int? -1N -10N -3N 32 | p/big-int? -2N 10N -3N 33 | 34 | double? 1.0 10 3.0 35 | double? 2.0 -10 3.0 36 | double? -1.0 -10 -3.0 37 | double? -2.0 10 -3.0 38 | double? 1.0 10.0 3 39 | double? 2.0 -10.0 3 40 | double? -1.0 -10.0 -3 41 | double? -2.0 10.0 -3 42 | double? 1.0 10.0 3.0 43 | double? 2.0 -10.0 3.0 44 | double? -1.0 -10.0 -3.0 45 | double? -2.0 10.0 -3.0 46 | 47 | ;; CLJS can read big decimals at the reader, but just converts 48 | ;; them to doubles. 49 | #?@(:cljs 50 | [double? 1.0M 10 3.0M 51 | double? 2.0M -10 3.0M 52 | double? -1.0M -10 -3.0M 53 | double? -2.0M 10 -3.0M 54 | double? 1.0M 10.0M 3 55 | double? 2.0M -10.0M 3 56 | double? -1.0M -10.0M -3 57 | double? -2.0M 10.0M -3 58 | double? 1.0M 10.0M 3.0M 59 | double? 2.0M -10.0M 3.0M 60 | double? -1.0M -10.0M -3.0M 61 | double? -2.0M 10.0M -3.0M] 62 | :default 63 | [decimal? 1.0M 10 3.0M 64 | decimal? 2.0M -10 3.0M 65 | decimal? -1.0M -10 -3.0M 66 | decimal? -2.0M 10 -3.0M 67 | decimal? 1.0M 10.0M 3 68 | decimal? 2.0M -10.0M 3 69 | decimal? -1.0M -10.0M -3 70 | decimal? -2.0M 10.0M -3 71 | decimal? 1.0M 10.0M 3.0M 72 | decimal? 2.0M -10.0M 3.0M 73 | decimal? -1.0M -10.0M -3.0M 74 | decimal? -2.0M 10.0M -3.0M]) 75 | 76 | ;; Unexpectedly downconverts result to double, rather than BigDecimal 77 | double? 1.0 10.0M 3.0 78 | double? 2.0 -10.0M 3.0 79 | double? -1.0 -10.0M -3.0 80 | double? -2.0 10.0M -3.0 81 | double? 1.0 10.0 3.0M 82 | double? 2.0 -10.0 3.0M 83 | double? -1.0 -10.0 -3.0M 84 | double? -2.0 10.0 -3.0M 85 | 86 | #?@(:cljs [] 87 | :default [p/big-int? 0N 3 1/2 88 | p/big-int? 0N 3 -1/2 89 | p/big-int? -1N 3 -4/3 90 | p/big-int? 0N -3 1/2 91 | p/big-int? 1N -3 4/3 92 | p/big-int? 0N -3 -1/2 93 | ratio? 1/3 3 4/3 94 | ratio? 7/2 37/2 15 95 | ratio? -23/2 37/2 -15 96 | ratio? 23/2 -37/2 15 97 | ratio? -1/3 -3 -4/3 98 | ratio? -7/2 -37/2 -15])) 99 | 100 | #?@(:cljs 101 | [(is (NaN? (mod 10 0))) 102 | (is (NaN? (mod ##Inf 1))) 103 | (is (NaN? (mod 1 ##Inf))) 104 | (is (NaN? (mod ##-Inf 1))) 105 | (is (NaN? (mod 1 ##-Inf))) 106 | (is (NaN? (mod ##NaN 1))) 107 | (is (NaN? (mod 1 ##NaN))) 108 | (is (NaN? (mod ##NaN 1)))] 109 | :default 110 | [(is (thrown? Exception (mod 10 0))) 111 | (is (thrown? Exception (mod ##Inf 1))) 112 | (is (NaN? (mod 1 ##Inf))) 113 | (is (thrown? Exception (mod ##-Inf 1))) 114 | (is (NaN? (mod 1 ##-Inf))) 115 | (is (thrown? Exception (mod ##NaN 1))) 116 | (is (thrown? Exception (mod 1 ##NaN))) 117 | (is (thrown? Exception (mod ##NaN 1)))]))) 118 | -------------------------------------------------------------------------------- /test/clojure/core_test/name.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.name 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/name 6 | (deftest test-name 7 | (are [expected x] (= expected (name x)) 8 | "abc" "abc" 9 | "abc" :abc 10 | "abc" 'abc 11 | "def" :abc/def 12 | "def" 'abc/def 13 | "abc*+!-_'?<>=" :abc/abc*+!-_'?<>= 14 | "abc*+!-_'?<>=" 'abc/abc*+!-_'?<>=) 15 | 16 | (is (thrown? #?(:cljs :default :clj Exception) (name nil))))) 17 | -------------------------------------------------------------------------------- /test/clojure/core_test/namespace.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.namespace 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/namespace 6 | (deftest test-namespace 7 | (are [expected sym-or-kw] (= expected (namespace sym-or-kw)) 8 | "clojure.core" 'clojure.core/+ 9 | "abc" :abc/def 10 | "abc" 'abc/def 11 | nil :abc 12 | nil 'abc) 13 | 14 | (is (thrown? #?(:cljs :default :clj Exception) (namespace nil))))) 15 | -------------------------------------------------------------------------------- /test/clojure/core_test/nan_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.nan-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/NaN? 6 | (deftest test-NaN? 7 | #?@(:cljs 8 | [(is (not (NaN? nil))) 9 | (is (NaN? "##NaN"))] ; Surprising 10 | :default 11 | [(is (thrown? #?(:clj Exception) (NaN? nil))) 12 | (is (thrown? #?(:clj Exception) (NaN? "##NaN")))]) 13 | (is (double? ##NaN)) 14 | ;; NaN is not equal to anything, even itself. 15 | ;; See: https://clojure.org/guides/equality 16 | ;; Note that we use `(not (= ...))` rather than `(not= ...)` because 17 | ;; of a bug in clojure.core. 18 | (is (not (= ##NaN ##NaN))) 19 | (are [in ex] (= ex (NaN? in)) 20 | 0 false 21 | 1.0 false 22 | -1.0 false 23 | (double 1.0) false 24 | (double -1.0) false 25 | ##Inf false 26 | ##-Inf false 27 | ##NaN true))) 28 | -------------------------------------------------------------------------------- /test/clojure/core_test/neg_int_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.neg-int-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/neg-int? 7 | (deftest test-neg-int? 8 | (are [expected x] (= expected (neg-int? x)) 9 | false 0 10 | false 1 11 | true -1 12 | false r/max-int 13 | true r/min-int 14 | false 0.0 15 | false 1.0 16 | #?@(:cljs [true -1.0] 17 | :default [false -1.0]) 18 | false r/max-double 19 | false r/min-double 20 | false ##Inf 21 | false ##-Inf 22 | false ##NaN 23 | false 0N 24 | false 1N 25 | #?@(:cljs [true -1N] 26 | :default [false -1N]) 27 | #?@(:cljs [] 28 | :default 29 | [false 0/2 30 | false 1/2 31 | false -1/2]) 32 | false 0.0M 33 | false 1.0M 34 | #?@(:cljs [true -1.0M] 35 | :default [false -1.0M]) 36 | false nil 37 | false true 38 | false false 39 | false "a string" 40 | false "0" 41 | false "1" 42 | false "-1" 43 | false {:a :map} 44 | false #{:a-set} 45 | false [:a :vector] 46 | false '(:a :list) 47 | false \0 48 | false \1 49 | false :a-keyword 50 | false :0 51 | false :1 52 | false :-1 53 | false 'a-sym))) 54 | -------------------------------------------------------------------------------- /test/clojure/core_test/neg_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.neg-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/neg? 7 | (deftest test-neg? 8 | (are [expected x] (= expected (neg? x)) 9 | false 0 10 | false 1 11 | true -1 12 | true r/min-int 13 | false r/max-int 14 | false 0.0 15 | false 1.0 16 | true -1.0 17 | false r/min-double 18 | false r/max-double 19 | false ##Inf 20 | true ##-Inf 21 | false ##NaN 22 | false 0N 23 | false 1N 24 | true -1N 25 | #?@(:cljs [] 26 | :default 27 | [false 0/2 28 | false 1/2 29 | true -1/2]) 30 | false 0.0M 31 | false 1.0M 32 | true -1.0M) 33 | 34 | #?@(:cljs 35 | [(is (not (neg? nil))) 36 | (is (not (neg? false))) ; Prints warning 37 | (is (not (neg? true)))] ; Prints warning 38 | :default 39 | [(is (thrown? Exception (neg? nil))) 40 | (is (thrown? Exception (neg? false))) 41 | (is (thrown? Exception (neg? true)))]))) 42 | -------------------------------------------------------------------------------- /test/clojure/core_test/next.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.next 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/next 6 | (deftest test-next 7 | (is (= '(1 2 3 4 5 6 7 8 9) (next (range 0 10)))) 8 | (is (= '(2 3 4 5 6 7 8 9) (next (next (range 0 10))))) 9 | (is (= 1 (first (next (range))))) ; infinite lazy seq 10 | (is (= '(2 3) (next [1 2 3]))) 11 | (is (nil? (next nil))) 12 | (is (nil? (next '()))) 13 | (is (nil? (next []))))) 14 | -------------------------------------------------------------------------------- /test/clojure/core_test/nil_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.nil-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/nil? 6 | (deftest test-nil? 7 | (testing "common" 8 | (are [in ex] (= (nil? in) ex) 9 | nil true 10 | 0 false 11 | false false 12 | "" false 13 | "nil" false 14 | :nil false 15 | ##Inf false 16 | ##NaN false 17 | 0.0 false 18 | {} false 19 | '() false 20 | [] false)) 21 | 22 | (testing "infinite-sequence" 23 | (is (= false (nil? (range))))))) 24 | -------------------------------------------------------------------------------- /test/clojure/core_test/not.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.not 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/not 6 | (deftest test-not 7 | (testing "common" 8 | (are [given expected] (= expected (not given)) 9 | nil true 10 | true false 11 | false true 12 | #?(:clj (Object.) 13 | :cljs #js {} 14 | :default :anything) false)) 15 | 16 | (testing "infinite-sequence" 17 | (is (= false (not (range))))))) 18 | -------------------------------------------------------------------------------- /test/clojure/core_test/not_eq.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.not-eq 2 | (:require 3 | [clojure.core-test.eq :as eq] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]] 5 | [clojure.test :refer [deftest is testing]])) 6 | 7 | (when-var-exists clojure.core/not= 8 | (deftest test-not-eq 9 | (eq/tests (complement not=)) 10 | ;; There is some arguably buggy behavior in JVM Clojure with not= 11 | ;; https://ask.clojure.org/index.php/14298/incorrect-result-when-evaluating-not-on-nans 12 | (testing "If ##NaNs are =" 13 | #?(:clj (is (not (not= ##NaN ##NaN))) 14 | :cljs (is (not= ##NaN ##NaN)))))) 15 | -------------------------------------------------------------------------------- /test/clojure/core_test/nth.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.nth 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/nth 6 | (deftest test-nth 7 | (is (= 0 (nth (range 0 10) 0))) 8 | (is (= 5 (nth (range 0 10) 5))) 9 | (is (= 5 (nth [0 1 2 3 4 5 6 7 8 9] 5))) 10 | (is (= 5 (nth (range) 5))) ; infinite lazy range 11 | 12 | ; Unexpected. `nil` not treated like `(), which would throw 13 | (is (nil? (nth nil 10))) 14 | 15 | ;; `nth` throws if out of range 16 | (is (thrown? #?(:cljs :default, :clj Exception) (nth [0 1 2] -1))) 17 | (is (thrown? #?(:cljs :default, :clj Exception) (nth [0 1 2] 10))) 18 | (is (thrown? #?(:cljs :default, :clj Exception) (nth [0 1 2] nil))) 19 | (is (thrown? #?(:cljs :default, :clj Exception) (nth nil nil))) 20 | 21 | ;; `nth` accepts a default argument 22 | (is (= :default (nth nil 0 :default))) 23 | (is (= :default (nth [0] 1 :default))) 24 | (is (= :default (nth [0 1] 2 :default))) 25 | (is (= :default (nth [0 1] -1 :default))))) 26 | -------------------------------------------------------------------------------- /test/clojure/core_test/nthnext.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.nthnext 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/nthnext 6 | (deftest test-nthnext 7 | (is (= '(3 4 5 6 7 8 9) (nthnext (range 0 10) 3))) 8 | (is (= [3 4 5] (nthnext [0 1 2 3 4 5] 3))) 9 | (is (= (range 0 10) (nthnext (range 0 10) 0))) 10 | (is (= '(9) (nthnext (range 0 10) 9))) 11 | (is (nil? (nthnext (range 0 10) 10))) 12 | (is (nil? (nthnext (range 0 10) 100))) 13 | (is (nil? (nthnext [1 2 3] 100))) 14 | (is (nil? (nthnext nil 100))) 15 | (is (nil? (nthnext [] 100))) 16 | (is (= (range 3) (nthnext (range 3) -1))) 17 | 18 | (is (nil? (nthnext nil nil))) ; Surprising. Should perhaps throw. 19 | 20 | ;; Negative tests 21 | #?@(:cljs 22 | ;; CLJS does some nil punning to 0 23 | [(is (= (range 0 10) (nthnext (range 0 10) nil))) 24 | (is (= '(0 1 2) (nthnext [0 1 2] nil)))] 25 | :default 26 | [(is (thrown? #?(:cljs :default :clj Exception) (nthnext (range 0 10) nil))) 27 | (is (thrown? #?(:cljs :default :clj Exception) (nthnext [0 1 2] nil)))]))) 28 | -------------------------------------------------------------------------------- /test/clojure/core_test/nthrest.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.nthrest 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/nthrest 6 | (deftest test-nthrest 7 | (is (= '(3 4 5 6 7 8 9) (nthrest (range 0 10) 3))) 8 | (is (= [3 4 5] (nthrest [0 1 2 3 4 5] 3))) 9 | (is (= (range 0 10) (nthrest (range 0 10) 0))) 10 | (is (= '(9) (nthrest (range 0 10) 9))) 11 | (is (= '() (nthrest (range 0 10) 10))) 12 | (is (= '() (nthrest (range 0 10) 100))) 13 | (is (= '() (nthrest [1 2 3] 100))) 14 | (is (= '() (nthrest [] 100))) 15 | (is (= (range 3) (nthrest (range 3) -1))) ; if n < 1, returns collection unchanged 16 | 17 | (is (nil? (nthrest nil 0))) ; if n < 1 or (seq coll) = nil, returns collection unchanged 18 | #?(:cljs 19 | (is (nil? (nthrest nil 100))) 20 | :default 21 | (is (= '() (nthrest nil 100)))) 22 | 23 | ;; Negative tests 24 | #?@(:cljs 25 | ;; CLJS does some nil punning to 0 26 | [(is (= (range 0 10) (nthrest (range 0 10) nil))) 27 | (is (= '(0 1 2) (nthrest [0 1 2] nil))) 28 | (is (nil? (nthrest nil nil)))] 29 | :default 30 | [(is (thrown? #?(:cljs :default :clj Exception) (nthrest (range 0 10) nil))) 31 | (is (thrown? #?(:cljs :default :clj Exception) (nthrest [0 1 2] nil))) 32 | (is (thrown? #?(:cljs :default :clj Exception) (nthrest nil nil)))]))) 33 | -------------------------------------------------------------------------------- /test/clojure/core_test/num.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.num 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/num 6 | (deftest test-num 7 | #?@(:cljs [] 8 | :clj 9 | ;; The compiler should pass `x` as a primitive to `num`. 10 | [(let [x 1.0] 11 | (is (instance? java.lang.Double (num x)))) 12 | (let [x 1] 13 | (is (instance? java.lang.Long (num x)))) 14 | ;; `BigInt` and `BigDecimal` are always boxed and `num` just returns them as-is. 15 | (is (instance? clojure.lang.BigInt (num 1N))) 16 | (is (instance? java.math.BigDecimal (num 1.0M)))] 17 | :default (is false "TODO test num")))) 18 | -------------------------------------------------------------------------------- /test/clojure/core_test/number_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.number-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/number? 7 | (deftest test-number? 8 | (are [expected x] (= expected (number? x)) 9 | true 0 10 | true 1 11 | true -1 12 | true r/max-int 13 | true r/min-int 14 | true 0.0 15 | true 1.0 16 | true -1.0 17 | true r/max-double 18 | true r/min-double 19 | true ##Inf 20 | true ##-Inf 21 | true ##NaN 22 | true 0N 23 | true 1N 24 | true -1N 25 | #?@(:cljs [] 26 | :default 27 | [true 0/2 28 | true 1/2 29 | true -1/2]) 30 | true 0.0M 31 | true 1.0M 32 | true -1.0M 33 | false nil 34 | false true 35 | false false 36 | false "a string" 37 | false "0" 38 | false "1" 39 | false "-1" 40 | false {:a :map} 41 | false #{:a-set} 42 | false [:a :vector] 43 | false '(:a :list) 44 | false \0 45 | false \1 46 | false :a-keyword 47 | false :0 48 | false :1 49 | false :-1 50 | false 'a-sym))) 51 | -------------------------------------------------------------------------------- /test/clojure/core_test/number_range.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.number-range) 2 | 3 | ;; TODO jank support blocked on https://github.com/jank-lang/jank/issues/195 4 | 5 | (def ^:const max-int #?(:clj Long/MAX_VALUE 6 | :cljs js/Number.MAX_SAFE_INTEGER 7 | :default 0x7FFFFFFFFFFFFFFF)) 8 | 9 | (def ^:const min-int #?(:clj Long/MIN_VALUE 10 | :cljs js/Number.MIN_SAFE_INTEGER 11 | :default 0x8000000000000000)) 12 | 13 | (def ^:const all-ones-int #?(:cljs 0xFFFFFFFF 14 | :default -1)) 15 | 16 | (def ^:const all-zeros 0) 17 | 18 | (def ^:const full-width-checker-pos #?(:cljs 0x55555555 19 | :default 0x5555555555555555)) 20 | 21 | (def ^:const full-width-checker-neg #?(:cljs 0xAAAAAAAA 22 | :default -0x5555555555555556)) 23 | 24 | (def ^:const max-double #?(:clj Double/MAX_VALUE 25 | :cljs js/Number.MAX_VALUE 26 | :default 1.7976931348623157e+308)) 27 | 28 | (def ^:const min-double #?(:clj Double/MIN_VALUE 29 | :cljs js/Number.MIN_VALUE 30 | :default 4.9e-324)) 31 | 32 | -------------------------------------------------------------------------------- /test/clojure/core_test/numerator.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.numerator 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/numerator 6 | (deftest test-numerator 7 | #?@(:cljs [] 8 | :default 9 | [(is (= 1 (numerator 1/2))) 10 | (is (= 2 (numerator 2/3))) 11 | (is (= 3 (numerator 3/4)))]) 12 | 13 | (is (thrown? #?(:cljs :default :clj Exception) (numerator 1))) 14 | (is (thrown? #?(:cljs :default :clj Exception) (numerator 1.0))) 15 | (is (thrown? #?(:cljs :default :clj Exception) (numerator 1N))) 16 | (is (thrown? #?(:cljs :default :clj Exception) (numerator 1.0M))) 17 | (is (thrown? #?(:cljs :default :clj Exception) (numerator ##Inf))) 18 | (is (thrown? #?(:cljs :default :clj Exception) (numerator ##NaN))) 19 | (is (thrown? #?(:cljs :default :clj Exception) (numerator nil))))) 20 | -------------------------------------------------------------------------------- /test/clojure/core_test/odd_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.odd-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/odd? 6 | (deftest test-odd? 7 | (testing "common" 8 | (are [in ex] (= (odd? in) ex) 9 | 0 false 10 | -0 false 11 | 12 false 12 | 17 true 13 | -118 false 14 | -119 true 15 | 123N true 16 | 122N false 17 | -121N true 18 | -120N false)) 19 | 20 | (testing "invalid" 21 | (are [x] (thrown? #?(:clj Exception :cljs js/Error) (odd? x)) 22 | #_:clj-kondo/ignore nil 23 | ##Inf 24 | ##-Inf 25 | ##NaN 26 | 1.5 27 | #?@(:cljs [] 28 | :default 29 | [1/2]) 30 | 0.2M)))) 31 | -------------------------------------------------------------------------------- /test/clojure/core_test/or.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.or 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/or 6 | (deftest test-or 7 | (testing "common" 8 | (is (= nil (or))) 9 | (are [x] (= x (or x)) 10 | true 11 | false 12 | nil 13 | :example) 14 | (are [ex a b] (= ex (or a b)) 15 | true true true 16 | true true false 17 | true false true 18 | false false false 19 | true true true 20 | true true nil 21 | true nil true 22 | nil nil nil) 23 | (testing "binds values before comparing" 24 | (let [counter (volatile! 0)] 25 | (is (= 1 (or nil (vswap! counter inc)))) 26 | (is (= 1 @counter)))) 27 | (testing "early exits" 28 | (let [counter (volatile! 0)] 29 | (is (= true (or true (vswap! counter inc)))) 30 | (is (= 0 @counter)))) 31 | (testing "handles varargs" 32 | (is (= 3 (or nil nil 3))) 33 | (is (= true (or nil nil nil nil nil nil nil nil nil nil nil nil true))))) 34 | 35 | (testing "infinite-sequence" 36 | (is (some? (or (range))))))) 37 | -------------------------------------------------------------------------------- /test/clojure/core_test/partial.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.partial 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (defn test-fn [& args] 6 | (into [] args)) 7 | 8 | (when-var-exists clojure.core/partial 9 | (deftest test-partial 10 | (let [simple-use (partial inc 2)] 11 | (is (= 3 (simple-use)))) 12 | (let [lazily-evaluated (partial inc 1 17)] 13 | ;; CLJS ignores extra parameters given to apply. E.g., (apply inc 1 17) => 2 14 | #?(:cljs (is (= 2 (lazily-evaluated))) 15 | :default (is (thrown? #?(:cljs :default :clj Exception) (lazily-evaluated))))) 16 | (let [variadic (partial test-fn 1 2 3)] 17 | (is (= [1 2 3 4] (variadic 4))) 18 | (is (= [1 2 3 4 5] (variadic 4 5)))) 19 | (let [infinite-sequence (partial #(take %2 %1) (range))] 20 | (is (= '(0 1 2 3 4) (infinite-sequence 5))) 21 | (is (= '(0 1 2) (infinite-sequence 3)))) 22 | (let [partial-partial ((partial partial) test-fn) 23 | pppartial (partial partial-partial :inner)] 24 | (is (= [:inner :outer] (partial-partial :inner :outer))) 25 | (is (= [:inner :outer] (pppartial :outer)))) 26 | (let [seq-of-partials (map #(partial * %1 %2) (range) (range))] 27 | (is (= (map #(* % % %) (range 5)) 28 | (map #(%1 %2) seq-of-partials (range 5))))))) 29 | -------------------------------------------------------------------------------- /test/clojure/core_test/plus_squote.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.plus-squote 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/+' 7 | (deftest test-+' 8 | (are [sum addend summand] (= sum (+' addend summand)) 9 | 0 0 0 10 | 1 1 0 11 | 1 0 1 12 | 2 1 1 13 | 6 1 5 14 | 6 5 1 15 | 10 5 5 16 | 0 1 -1 17 | 0 -1 1 18 | -2 -1 -1 19 | -1 -1 0 20 | -1 0 -1 21 | (+ 1N r/max-int) r/max-int 1 22 | (- r/min-int 1N) -1 r/min-int 23 | 24 | 0.0 0.0 0.0 25 | 1.0 1.0 0.0 26 | 1.0 0.0 1.0 27 | 2.0 1.0 1.0 28 | 6.0 1.0 5.0 29 | 6.0 5.0 1.0 30 | 10.0 5.0 5.0 31 | 0.0 1.0 -1.0 32 | 0.0 -1.0 1.0 33 | -2.0 -1.0 -1.0 34 | -1.0 -1.0 0.0 35 | -1.0 0.0 -1.0 36 | 37 | 0.0 0.0 0 38 | 1.0 1.0 0 39 | 1.0 0.0 1 40 | 2.0 1.0 1 41 | 6.0 1.0 5 42 | 6.0 5.0 1 43 | 10.0 5.0 5 44 | 0.0 1.0 -1 45 | 0.0 -1.0 1 46 | -2.0 -1.0 -1 47 | -1.0 -1.0 0 48 | -1.0 0.0 -1 49 | 50 | 0.0 0 0.0 51 | 1.0 1 0.0 52 | 1.0 0 1.0 53 | 2.0 1 1.0 54 | 6.0 1 5.0 55 | 6.0 5 1.0 56 | 10.0 5 5.0 57 | 0.0 1 -1.0 58 | 0.0 -1 1.0 59 | -2.0 -1 -1.0 60 | -1.0 -1 0.0 61 | -1.0 0 -1.0 62 | 63 | 1N 0 1N 64 | 1N 0N 1 65 | 1N 0N 1N 66 | 2N 1N 1 67 | 2N 1 1N 68 | 2N 1N 1N 69 | 6N 1 5N 70 | 6N 1N 5 71 | 6N 1N 5N) 72 | 73 | (is (thrown? #?(:cljs :default :clj Exception) (+' 1 nil))) 74 | (is (thrown? #?(:cljs :default :clj Exception) (+' nil 1))) 75 | 76 | (is (instance? clojure.lang.BigInt (+' 0 1N))) 77 | (is (instance? clojure.lang.BigInt (+' 0N 1))) 78 | (is (instance? clojure.lang.BigInt (+' 0N 1N))) 79 | (is (instance? clojure.lang.BigInt (+' 1N 1))) 80 | (is (instance? clojure.lang.BigInt (+' 1 1N))) 81 | (is (instance? clojure.lang.BigInt (+' 1N 1N))) 82 | (is (instance? clojure.lang.BigInt (+' 1 5N))) 83 | (is (instance? clojure.lang.BigInt (+' 1N 5))) 84 | (is (instance? clojure.lang.BigInt (+' 1N 5N))) 85 | 86 | (is (instance? clojure.lang.BigInt (+' -1 r/min-int))) 87 | (is (instance? clojure.lang.BigInt (+' r/min-int -1))))) 88 | -------------------------------------------------------------------------------- /test/clojure/core_test/portability.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.portability) 2 | 3 | (defmacro when-var-exists [var-sym & body] 4 | (let [cljs? (some? (:ns &env)) 5 | exists? (boolean (if cljs? 6 | ((resolve 'cljs.analyzer.api/resolve) &env var-sym) 7 | (resolve var-sym)))] 8 | (if exists? 9 | `(do 10 | ~@body) 11 | `(println "SKIP -" '~var-sym)))) 12 | 13 | (defn big-int? [n] 14 | ;; In CLJS, all numbers are really doubles and integer? and int? 15 | ;; return true if the fractional part of the double is zero 16 | #?(:cljs (integer? n) 17 | :default 18 | (and (integer? n) 19 | (not (int? n))))) 20 | -------------------------------------------------------------------------------- /test/clojure/core_test/pos_int_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.pos-int-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/pos-int? 7 | (deftest test-pos-int? 8 | (are [expected x] (= expected (pos-int? x)) 9 | false 0 10 | true 1 11 | false -1 12 | true r/max-int 13 | false r/min-int 14 | false 0.0 15 | #?@(:cljs [true 1.0] 16 | :default [false 1.0]) 17 | false -1.0 18 | false r/max-double 19 | false r/min-double 20 | false ##Inf 21 | false ##-Inf 22 | false ##NaN 23 | false 0N 24 | #?@(:cljs [true 1.0] 25 | :default [false 1N]) 26 | false -1N 27 | #?@(:cljs [] 28 | :default 29 | [false 0/2 30 | false 1/2 31 | false -1/2]) 32 | false 0.0M 33 | #?@(:cljs [true 1.0M] 34 | :default [false 1.0M]) 35 | false -1.0M 36 | false nil 37 | false true 38 | false false 39 | false "a string" 40 | false "0" 41 | false "1" 42 | false "-1" 43 | false {:a :map} 44 | false #{:a-set} 45 | false [:a :vector] 46 | false '(:a :list) 47 | false \0 48 | false \1 49 | false :a-keyword 50 | false :0 51 | false :1 52 | false :-1 53 | false 'a-sym))) 54 | -------------------------------------------------------------------------------- /test/clojure/core_test/pos_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.pos-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/pos? 7 | (deftest test-pos? 8 | (are [expected x] (= expected (pos? x)) 9 | false 0 10 | true 1 11 | false -1 12 | false r/min-int 13 | true r/max-int 14 | false 0.0 15 | true 1.0 16 | false -1.0 17 | true r/min-double 18 | true r/max-double 19 | true ##Inf 20 | false ##-Inf 21 | false ##NaN 22 | false 0N 23 | true 1N 24 | false -1N 25 | #?@(:cljs [] 26 | :default 27 | [false 0/2 28 | true 1/2 29 | false -1/2]) 30 | false 0.0M 31 | true 1.0M 32 | false -1.0M) 33 | 34 | #?@(:cljs 35 | [(is (not (pos? nil))) 36 | (is (not (pos? false))) ; Prints warning 37 | (is (pos? true))] ; Prints warning 38 | :default 39 | [(is (thrown? #?(:clj Exception) (pos? nil))) 40 | (is (thrown? #?(:clj Exception) (pos? false))) 41 | (is (thrown? #?(:clj Exception) (pos? true)))]))) 42 | -------------------------------------------------------------------------------- /test/clojure/core_test/pr_str.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.pr-str 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/pr-str 6 | (deftest test-pr-str 7 | (is (= "\"a\" \"string\"" (pr-str "a" "string"))) 8 | ;; Slight differences in the way that CLJS handles characters and 9 | ;; numbers with no fractional part. 10 | (is (= #?(:cljs "nil \"a\" \"string\" \"A\" \" \" 1 17 [:a :b] {:c :d} #{:e}" 11 | :default "nil \"a\" \"string\" \\A \\space 1 17.0 [:a :b] {:c :d} #{:e}") 12 | (pr-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e}))))) 13 | -------------------------------------------------------------------------------- /test/clojure/core_test/print_str.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.print-str 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/print-str 6 | (deftest test-print-str 7 | (is (= "a string" (print-str "a" "string"))) 8 | (is (= #?(:cljs "nil a string A 1 17 [:a :b] {:c :d} #{:e}" 9 | :default "nil a string A 1 17.0 [:a :b] {:c :d} #{:e}") 10 | (print-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e}))))) 11 | -------------------------------------------------------------------------------- /test/clojure/core_test/println_str.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.println-str 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/println-str 6 | (deftest test-println-str 7 | (let [nl (println-str)] 8 | ;; `nl` grabs the platform specific newline without calling out to 9 | ;; platform-specific code (e.g., Java) since we want this to run 10 | ;; in all environments. Note that we're not actually testing 11 | ;; whether the newline sequence itself is correct, only that 12 | ;; `println-str` adds it to the end of the string. 13 | (is (= (str "a string" nl) (println-str "a" "string"))) 14 | (is (= #?(:cljs (str "nil a string A 1 17 [:a :b] {:c :d} #{:e}" nl) 15 | :default (str "nil a string A 1 17.0 [:a :b] {:c :d} #{:e}" nl)) 16 | (println-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e})))))) 17 | -------------------------------------------------------------------------------- /test/clojure/core_test/prn_str.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.prn-str 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/prn-str 6 | (deftest test-prn-str 7 | (let [nl (prn-str)] 8 | ;; `nl` grabs the platform specific newline without calling out to 9 | ;; platform-specific code (e.g., Java) since we want this to run 10 | ;; in all environments. Note that we're not actually testing 11 | ;; whether the newline sequence itself is correct, only that 12 | ;; `prn-str` adds it to the end of the string. 13 | (is (= (str "\"a\" \"string\"" nl) (prn-str "a" "string"))) 14 | (is (= #?(:cljs (str "nil \"a\" \"string\" \"A\" \" \" 1 17 [:a :b] {:c :d} #{:e}" nl) 15 | :default (str "nil \"a\" \"string\" \\A \\space 1 17.0 [:a :b] {:c :d} #{:e}" nl)) 16 | (prn-str nil "a" "string" \A \space 1 17.0 [:a :b] {:c :d} #{:e})))))) 17 | -------------------------------------------------------------------------------- /test/clojure/core_test/qualified_ident_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.qualified-ident-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/qualified-ident? 6 | (deftest test-qualified-ident? 7 | (are [expected x] (= expected (qualified-ident? x)) 8 | false :a-keyword 9 | false 'a-symbol 10 | true :a-ns/a-keyword 11 | true 'a-ns/a-keyword 12 | false "a string" 13 | false 0 14 | false 0N 15 | false 0.0 16 | #?@(:cljs [] 17 | :default 18 | [false 1/2]) 19 | false 0.0M 20 | false false 21 | false true 22 | false nil))) 23 | -------------------------------------------------------------------------------- /test/clojure/core_test/qualified_keyword_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.qualified-keyword-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/qualified-keyword? 6 | (deftest test-qualified-keyword? 7 | (are [expected x] (= expected (qualified-keyword? x)) 8 | false :a-keyword 9 | false 'a-symbol 10 | true :a-ns/a-keyword 11 | false 'a-ns/a-keyword 12 | false "a string" 13 | false 0 14 | false 0N 15 | false 0.0 16 | #?@(:cljs [] 17 | :default 18 | [false 1/2]) 19 | false 0.0M 20 | false false 21 | false true 22 | false nil))) 23 | -------------------------------------------------------------------------------- /test/clojure/core_test/qualified_symbol_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.qualified-symbol-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/qualified-symbol? 6 | (deftest test-qualified-symbol? 7 | (are [expected x] (= expected (qualified-symbol? x)) 8 | false :a-keyword 9 | false 'a-symbol 10 | false :a-ns/a-keyword 11 | true 'a-ns/a-keyword 12 | false "a string" 13 | false 0 14 | false 0N 15 | false 0.0 16 | #?@(:cljs [] 17 | :default 18 | [false 1/2]) 19 | false 0.0M 20 | false false 21 | false true 22 | false nil))) 23 | -------------------------------------------------------------------------------- /test/clojure/core_test/quot.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.quot 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability :as p #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/quot 6 | (deftest test-quot 7 | (are [type-pred expected x y] (let [r (quot x y)] 8 | (and (type-pred r) 9 | (= expected r))) 10 | int? 3 10 3 11 | int? -3 -10 3 12 | int? 3 -10 -3 13 | int? -3 10 -3 14 | 15 | p/big-int? 3N 10 3N 16 | p/big-int? -3N -10 3N 17 | p/big-int? 3N -10 -3N 18 | p/big-int? -3N 10 -3N 19 | p/big-int? 3N 10N 3 20 | p/big-int? -3N -10N 3 21 | p/big-int? 3N -10N -3 22 | p/big-int? -3N 10N -3 23 | p/big-int? 3N 10N 3N 24 | p/big-int? -3N -10N 3N 25 | p/big-int? 3N -10N -3N 26 | p/big-int? -3N 10N -3N 27 | 28 | double? 3.0 10 3.0 29 | double? -3.0 -10 3.0 30 | double? 3.0 -10 -3.0 31 | double? -3.0 10 -3.0 32 | double? 3.0 10.0 3 33 | double? -3.0 -10.0 3 34 | double? 3.0 -10.0 -3 35 | double? -3.0 10.0 -3 36 | double? 3.0 10.0 3.0 37 | double? -3.0 -10.0 3.0 38 | double? 3.0 -10.0 -3.0 39 | double? -3.0 10.0 -3.0 40 | 41 | #?@(:cljs 42 | [double? 3.0M 10 3.0M 43 | double? -3.0M -10 3.0M 44 | double? 3.0M -10 -3.0M 45 | double? -3.0M 10 -3.0M 46 | double? 3.0M 10.0M 3 47 | double? -3.0M -10.0M 3 48 | double? 3.0M -10.0M -3 49 | double? -3.0M 10.0M -3 50 | double? 3.0M 10.0M 3.0M 51 | double? -3.0M -10.0M 3.0M 52 | double? 3.0M -10.0M -3.0M 53 | double? -3.0M 10.0M -3.0M] 54 | :default 55 | [decimal? 3.0M 10 3.0M 56 | decimal? -3.0M -10 3.0M 57 | decimal? 3.0M -10 -3.0M 58 | decimal? -3.0M 10 -3.0M 59 | decimal? 3.0M 10.0M 3 60 | decimal? -3.0M -10.0M 3 61 | decimal? 3.0M -10.0M -3 62 | decimal? -3.0M 10.0M -3 63 | decimal? 3.0M 10.0M 3.0M 64 | decimal? -3.0M -10.0M 3.0M 65 | decimal? 3.0M -10.0M -3.0M 66 | decimal? -3.0M 10.0M -3.0M]) 67 | 68 | ;; Unexpectedly downconverts result to double, rather than BigDecimal 69 | double? 3.0 10.0M 3.0 70 | double? -3.0 -10.0M 3.0 71 | double? 3.0 -10.0M -3.0 72 | double? -3.0 10.0M -3.0 73 | double? 3.0 10.0 3.0M 74 | double? -3.0 -10.0 3.0M 75 | double? 3.0 -10.0 -3.0M 76 | double? -3.0 10.0 -3.0M 77 | 78 | ;; Anything with a ratio seems to convert to BigInt 79 | #?@(:cljs [] 80 | :default [p/big-int? 6N 3 1/2 81 | p/big-int? 2N 3 4/3 82 | p/big-int? 1N 37/2 15 83 | p/big-int? -6N 3 -1/2 84 | p/big-int? -2N 3 -4/3 85 | p/big-int? -1N 37/2 -15 86 | p/big-int? -6N -3 1/2 87 | p/big-int? -2N -3 4/3 88 | p/big-int? -1N -37/2 15 89 | p/big-int? 6N -3 -1/2 90 | p/big-int? 2N -3 -4/3 91 | p/big-int? 1N -37/2 -15]) 92 | 93 | double? 0.0 1 ##Inf 94 | double? 0.0 1 ##-Inf) 95 | 96 | #?@(:cljs 97 | [(is (NaN? (quot 10 0))) 98 | (is (NaN? (quot ##Inf 1))) 99 | (is (NaN? (quot ##-Inf 1))) 100 | (is (NaN? (quot ##NaN 1))) 101 | (is (NaN? (quot 1 ##NaN))) 102 | (is (NaN? (quot ##NaN 1)))] 103 | :default 104 | [(is (thrown? #?(:cljs :default :clj Exception) (quot 10 0))) 105 | (is (thrown? #?(:cljs :default :clj Exception) (quot ##Inf 1))) 106 | (is (thrown? #?(:cljs :default :clj Exception) (quot ##-Inf 1))) 107 | (is (thrown? #?(:cljs :default :clj Exception) (quot ##NaN 1))) 108 | (is (thrown? #?(:cljs :default :clj Exception) (quot 1 ##NaN))) 109 | (is (thrown? #?(:cljs :default :clj Exception) (quot ##NaN 1)))]))) 110 | -------------------------------------------------------------------------------- /test/clojure/core_test/rand.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.rand 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability :as p])) 4 | 5 | (p/when-var-exists clojure.core/rand 6 | (deftest test-rand 7 | ;; Generally, we test that the numbers returned pass `double?` and 8 | ;; that they are not constant. 9 | (let [length 100] 10 | (testing "zero-arg case" 11 | (let [x (repeatedly length rand)] 12 | (is (every? double? x)) 13 | (is (every? pos? x)) 14 | (is (> (count (set x)) 1)))) ; shouldn't be constant 15 | (testing "one-arg case" 16 | (let [limit 0.01 ; Choose something < 1 to constrain it further 17 | x (repeatedly length #(rand limit))] 18 | (is (every? double? x)) 19 | (is (every? pos? x)) 20 | (is (> (count (set x)) 1)) ; shouldn't be constant 21 | (is (every? #(< % limit) x))))))) 22 | -------------------------------------------------------------------------------- /test/clojure/core_test/rand_int.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.rand-int 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability :as p])) 4 | 5 | (p/when-var-exists clojure.core/rand-int 6 | (deftest test-rand-int 7 | ;; Generally, we test that the numbers returned pass `int?` and 8 | ;; that they are not constant. 9 | (let [length 100 10 | limit 2000000000 ; 2 billion 11 | x (repeatedly length #(rand-int limit))] 12 | (is (every? int? x)) 13 | (is (every? pos? x)) 14 | (is (> (count (set x)) 1)) ; Shouldn't be constant 15 | (is (every? #(< % limit) x))))) 16 | -------------------------------------------------------------------------------- /test/clojure/core_test/ratio_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.ratio-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/ratio? 7 | (deftest test-ratio? 8 | (are [expected x] (= expected (ratio? x)) 9 | false 0 10 | false 1 11 | false -1 12 | false r/max-int 13 | false r/min-int 14 | false 0.0 15 | false 1.0 16 | false -1.0 17 | false r/max-double 18 | false r/min-double 19 | false ##Inf 20 | false ##-Inf 21 | false ##NaN 22 | false 0N 23 | false 1N 24 | false -1N 25 | #?@(:cljs [] 26 | :default 27 | [false 0/2 ; perhaps surprising 28 | true 1/2 29 | true -1/2]) 30 | false 0.0M 31 | false 1.0M 32 | false -1.0M 33 | false nil 34 | false true 35 | false false 36 | false "a string" 37 | false "0" 38 | false "1" 39 | false "-1" 40 | false {:a :map} 41 | false #{:a-set} 42 | false [:a :vector] 43 | false '(:a :list) 44 | false \0 45 | false \1 46 | false :a-keyword 47 | false :0 48 | false :1 49 | false :-1 50 | false 'a-sym))) 51 | -------------------------------------------------------------------------------- /test/clojure/core_test/rational_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.rational-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/rational? 7 | (deftest test-rational? 8 | (are [expected x] (= expected (rational? x)) 9 | true 0 10 | true 1 11 | true -1 12 | true r/max-int 13 | true r/min-int 14 | false 0.0 15 | false 1.0 16 | false -1.0 17 | false r/max-double 18 | false r/min-double 19 | false ##Inf 20 | false ##-Inf 21 | false ##NaN 22 | true 0N 23 | true 1N 24 | true -1N 25 | #?@(:cljs [] 26 | :default 27 | [true 0/2 ; perhaps surprising 28 | true 1/2 29 | true -1/2]) 30 | true 0.0M ; perhaps surprising 31 | true 1.0M ; perhaps surprising 32 | true -1.0M ; perhaps surprising 33 | false nil 34 | false true 35 | false false 36 | false "a string" 37 | false "0" 38 | false "1" 39 | false "-1" 40 | false {:a :map} 41 | false #{:a-set} 42 | false [:a :vector] 43 | false '(:a :list) 44 | false \0 45 | false \1 46 | false :a-keyword 47 | false :0 48 | false :1 49 | false :-1 50 | false 'a-sym))) 51 | -------------------------------------------------------------------------------- /test/clojure/core_test/rationalize.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.rationalize 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/rationalize 6 | (deftest test-rationalize 7 | (are [expected x] (let [x' (rationalize x)] 8 | (and (= expected x') 9 | (or (integer? x') 10 | (ratio? x')))) 11 | 1 1 12 | 0 0 13 | -1 -1 14 | 1N 1N 15 | 0N 0N 16 | -1N -1N 17 | 1 1.0 18 | 0 0.0 19 | -1 -1.0 20 | 1 1.0M 21 | 0 0.0M 22 | #?@(:cljs [] 23 | :default 24 | [3/2 1.5 25 | 11/10 1.1 26 | 3333333333333333/10000000000000000 (/ 1.0 3.0) 27 | 3/2 1.5M 28 | 11/10 1.1M])))) 29 | -------------------------------------------------------------------------------- /test/clojure/core_test/reduce.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.reduce 2 | (:require 3 | [clojure.test :as t :refer [deftest testing is are]] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]) 5 | #?(:clj (:import (clojure.lang IReduce)))) 6 | 7 | (def interop 8 | {:int-new (fn [x] 9 | (#?(:clj Integer. 10 | :cljs js/Number.) x)) 11 | 12 | :Integer #?(:clj Integer/TYPE 13 | :cljs js/Number) 14 | 15 | :Long #?(:clj Long/TYPE 16 | :cljs js/Number) 17 | 18 | :Float #?(:clj Long/TYPE 19 | :cljs js/Number) 20 | 21 | :Double #?(:clj Double/TYPE 22 | :cljs js/Number) 23 | 24 | :Boolean #?(:clj Boolean/TYPE 25 | :cljs js/Boolean)}) 26 | 27 | 28 | (when-var-exists clojure.core/reduce 29 | (deftest test-reduce 30 | (testing "common" 31 | (is (nil? (reduce nil nil nil))) 32 | (is (thrown? #?(:clj Exception 33 | :cljs js/Error) (reduce nil nil))) 34 | (is (= 6 (reduce + 0 [1 2 3])))) 35 | 36 | (testing "val is not supplied" 37 | (is (= 3 (reduce (fn [a b] 38 | (+ a b)) 39 | [1 2]))) 40 | 41 | (testing "empty coll" 42 | (is (= 1 (reduce (fn [] 1) [])))) 43 | 44 | (testing "coll with 1 item" 45 | (is (= 1 (reduce (fn [] 46 | (is false) 47 | (throw (ex-info "should not get here" {}))) 48 | [1]))))) 49 | 50 | (testing "val is supplied, empty coll" 51 | (is (= 1 (reduce (fn [] 52 | (is false) 53 | (throw (ex-info "should not get here" {}))) 54 | 1 55 | [])))) 56 | 57 | (testing "reduction by type" 58 | (let [int-new (interop :int-new) 59 | char-new (interop :char-new) 60 | byte-new (interop :byte-new) 61 | arange (range 1 100) ;; enough to cross nodes 62 | avec (into [] arange) 63 | alist (into () arange) 64 | obj-array (into-array arange) 65 | int-array (into-array (:Integer interop) (map #(int-new (int %)) arange)) 66 | long-array (into-array (:Long interop) arange) 67 | float-array (into-array (:Float interop) arange) 68 | double-array (into-array (:Double interop) arange) 69 | all-true (into-array (:Boolean interop) (repeat 10 true))] 70 | 71 | (testing "val is not supplied" 72 | (is (== 4950 73 | (reduce + arange) 74 | (reduce + avec) 75 | #?(:clj (.reduce ^IReduce avec +)) 76 | (reduce + alist) 77 | (reduce + obj-array) 78 | (reduce + int-array) 79 | (reduce + long-array) 80 | (reduce + float-array) 81 | (reduce + double-array)))) 82 | 83 | (testing "val is supplied" 84 | (is (== 4951 85 | (reduce + 1 arange) 86 | (reduce + 1 avec) 87 | #?(:clj (.reduce ^IReduce avec + 1)) 88 | (reduce + 1 alist) 89 | (reduce + 1 obj-array) 90 | (reduce + 1 int-array) 91 | (reduce + 1 long-array) 92 | (reduce + 1 float-array) 93 | (reduce + 1 double-array)))) 94 | 95 | (is (= true 96 | (reduce #(and %1 %2) all-true) 97 | (reduce #(and %1 %2) true all-true))))))) 98 | -------------------------------------------------------------------------------- /test/clojure/core_test/rem.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.rem 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability :as p #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/rem 6 | (deftest test-rem 7 | (are [type-pred expected x y] (let [r (rem x y)] 8 | (and (type-pred r) 9 | (= expected r))) 10 | int? 1 10 3 11 | int? -1 -10 3 12 | int? -1 -10 -3 13 | int? 1 10 -3 14 | 15 | p/big-int? 1N 10 3N 16 | p/big-int? -1N -10 3N 17 | p/big-int? -1N -10 -3N 18 | p/big-int? 1N 10 -3N 19 | p/big-int? 1N 10N 3 20 | p/big-int? -1N -10N 3 21 | p/big-int? -1N -10N -3 22 | p/big-int? 1N 10N -3 23 | p/big-int? 1N 10N 3N 24 | p/big-int? -1N -10N 3N 25 | p/big-int? -1N -10N -3N 26 | p/big-int? 1N 10N -3N 27 | 28 | double? 1.0 10 3.0 29 | double? -1.0 -10 3.0 30 | double? -1.0 -10 -3.0 31 | double? 1.0 10 -3.0 32 | double? 1.0 10.0 3 33 | double? -1.0 -10.0 3 34 | double? -1.0 -10.0 -3 35 | double? 1.0 10.0 -3 36 | double? 1.0 10.0 3.0 37 | double? -1.0 -10.0 3.0 38 | double? -1.0 -10.0 -3.0 39 | double? 1.0 10.0 -3.0 40 | 41 | #?@(:cljs 42 | [double? 1.0M 10 3.0M 43 | double? -1.0M -10 3.0M 44 | double? -1.0M -10 -3.0M 45 | double? 1.0M 10 -3.0M 46 | double? 1.0M 10.0M 3 47 | double? -1.0M -10.0M 3 48 | double? -1.0M -10.0M -3 49 | double? 1.0M 10.0M -3 50 | double? 1.0M 10.0M 3.0M 51 | double? -1.0M -10.0M 3.0M 52 | double? -1.0M -10.0M -3.0M 53 | double? 1.0M 10.0M -3.0M] 54 | :default 55 | [decimal? 1.0M 10 3.0M 56 | decimal? -1.0M -10 3.0M 57 | decimal? -1.0M -10 -3.0M 58 | decimal? 1.0M 10 -3.0M 59 | decimal? 1.0M 10.0M 3 60 | decimal? -1.0M -10.0M 3 61 | decimal? -1.0M -10.0M -3 62 | decimal? 1.0M 10.0M -3 63 | decimal? 1.0M 10.0M 3.0M 64 | decimal? -1.0M -10.0M 3.0M 65 | decimal? -1.0M -10.0M -3.0M 66 | decimal? 1.0M 10.0M -3.0M]) 67 | 68 | ;; Unexpectedly downconverts result to double, rather than BigDecimal 69 | double? 1.0 10.0M 3.0 70 | double? -1.0 -10.0M 3.0 71 | double? -1.0 -10.0M -3.0 72 | double? 1.0 10.0M -3.0 73 | double? 1.0 10.0 3.0M 74 | double? -1.0 -10.0 3.0M 75 | double? -1.0 -10.0 -3.0M 76 | double? 1.0 10.0 -3.0M 77 | 78 | #?@(:cljs [] 79 | :default 80 | [p/big-int? 0N 3 1/2 81 | ratio? 1/3 3 4/3 82 | ratio? 7/2 37/2 15 83 | p/big-int? 0N 3 -1/2 84 | ratio? 1/3 3 -4/3 85 | ratio? 7/2 37/2 -15 86 | p/big-int? 0N -3 1/2 87 | ratio? -1/3 -3 4/3 88 | ratio? -7/2 -37/2 15 89 | p/big-int? 0N -3 -1/2 90 | ratio? -1/3 -3 -4/3 91 | ratio? -7/2 -37/2 -15])) 92 | 93 | #?@(:cljs 94 | [(is (NaN? (rem 10 0))) 95 | (is (NaN? (rem ##Inf 1))) 96 | (is (NaN? (rem 1 ##Inf))) 97 | (is (NaN? (rem ##-Inf 1))) 98 | (is (NaN? (rem 1 ##-Inf))) 99 | (is (NaN? (rem ##NaN 1))) 100 | (is (NaN? (rem 1 ##NaN))) 101 | (is (NaN? (rem ##NaN 1)))] 102 | :default 103 | [(is (thrown? #?(:cljs :default :clj Exception) (rem 10 0))) 104 | (is (thrown? #?(:cljs :default :clj Exception) (rem ##Inf 1))) 105 | (is (NaN? (rem 1 ##Inf))) 106 | (is (thrown? #?(:cljs :default :clj Exception) (rem ##-Inf 1))) 107 | (is (NaN? (rem 1 ##-Inf))) 108 | (is (thrown? #?(:cljs :default :clj Exception) (rem ##NaN 1))) 109 | (is (thrown? #?(:cljs :default :clj Exception) (rem 1 ##NaN))) 110 | (is (thrown? #?(:cljs :default :clj Exception) (rem ##NaN 1)))]))) 111 | -------------------------------------------------------------------------------- /test/clojure/core_test/rest.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.rest 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/rest 6 | (deftest test-rest 7 | (is (= '(1 2 3 4 5 6 7 8 9) (rest (range 0 10)))) 8 | (is (= '(2 3 4 5 6 7 8 9) (rest (rest (range 0 10))))) 9 | (is (= 1 (first (rest (range))))) ; Infinite lazy seq 10 | (is (= '(2 3) (rest [1 2 3]))) 11 | (is (= '() (rest nil))) 12 | (is (= '() (rest '()))) 13 | (is (= '() (rest []))))) 14 | -------------------------------------------------------------------------------- /test/clojure/core_test/reversible_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.reversible-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/reversible? 6 | (deftest test-reversible? 7 | (are [expected x] (= expected (reversible? x)) 8 | true [1 2 3] 9 | true (sorted-map :a 1) 10 | true (sorted-set :a) 11 | false '(1 2 3) 12 | false (hash-map :a 1) 13 | false (array-map :a 1) 14 | false (hash-set :a) 15 | #?(:cljs true :default false) (seq [1 2 3]) 16 | false (seq (sorted-map :a 1)) 17 | false (seq (sorted-set :a)) 18 | false (range 0 10) 19 | false (range) 20 | false nil 21 | false 1 22 | false 1N 23 | false 1.0 24 | false 1.0M 25 | false :a-keyword 26 | false 'a-sym 27 | false "a string" 28 | false \a 29 | false (object-array 3)))) 30 | -------------------------------------------------------------------------------- /test/clojure/core_test/second.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.second 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/second 6 | (deftest test-second 7 | (is (= 1 (second (range 0 10)))) 8 | (is (= 1 (second (range)))) ; infinite lazy seq 9 | (is (= :b (second [:a :b :c]))) 10 | (is (= :b (second '(:a :b :c)))) 11 | (is (nil? (second '()))) 12 | (is (nil? (second []))) 13 | (is (nil? (second nil))))) 14 | -------------------------------------------------------------------------------- /test/clojure/core_test/seq.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.seq 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/seq 6 | (deftest test-seq 7 | ;; Sourced via canSeq https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L581 8 | (are [in expected] (= expected (seq in)) 9 | "test" '(\t \e \s \t) 10 | [1 2 3 4] '(1 2 3 4) 11 | '(:a :b :c :d) '(:a :b :c :d) 12 | '() nil 13 | nil nil 14 | (sorted-set 3.0 1.0 -2.5 4.0) '(-2.5 1.0 3.0 4.0) 15 | (range 5 10) '(5 6 7 8 9) 16 | #?@(:cljs [(int-array 3) '(nil nil nil)] 17 | :default [(int-array 3) '(0 0 0)])) 18 | (testing "sets and maps" 19 | (let [input #{440M 55000M 80000} 20 | input-hash (into (hash-set) input) 21 | input-map {:a {:b "4"} 22 | :c 800 23 | nil 40} 24 | input-sorted-map (into (sorted-map) input-map) 25 | input-hash-map (into (hash-map) input-map)] 26 | (is (= input (into #{} (seq input)))) 27 | (is (= input-hash (into (hash-set) (seq input)))) 28 | (is (= input-sorted-map (into (sorted-map) (seq input-sorted-map)))) 29 | (is (= input-hash-map (into (hash-map) (seq input-hash-map)))) 30 | (is (= input-map (into {} (seq input-map)))))) 31 | (testing "nonseqables" 32 | (is (thrown? #?(:cljs :default :clj Exception) (seq 1))) 33 | (is (thrown? #?(:cljs :default :clj Exception) (seq (fn []))))) 34 | (testing "infinite sequences are produced by seq" 35 | (let [infinite-seq (seq (range))] 36 | (is (seq? infinite-seq)) 37 | (is (= (range 10000) (take 10000 infinite-seq))))))) 38 | -------------------------------------------------------------------------------- /test/clojure/core_test/seq_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.seq-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/seq? 6 | (deftest test-seq? 7 | (are [expected x] (= expected (seq? x)) 8 | false [1 2 3] 9 | false (sorted-map :a 1) 10 | false (sorted-set :a) 11 | true '(1 2 3) ; lists are naturally seqs 12 | false (hash-map :a 1) 13 | false (array-map :a 1) 14 | false (hash-set :a) 15 | true (seq [1 2 3]) 16 | true (seq (sorted-map :a 1)) 17 | true (seq (sorted-set :a)) 18 | true (range 0 10) 19 | true (range) 20 | false nil 21 | false 1 22 | false 1N 23 | false 1.0 24 | false 1.0M 25 | false :a-keyword 26 | false 'a-sym 27 | false "a string" 28 | false \a 29 | false (object-array 3)))) 30 | -------------------------------------------------------------------------------- /test/clojure/core_test/seqable_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.seqable-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/seqable? 6 | (deftest test-seqable? 7 | (are [expected x] (= expected (seqable? x)) 8 | true [1 2 3] 9 | true (sorted-map :a 1) 10 | true (sorted-set :a) 11 | true '(1 2 3) 12 | true (hash-map :a 1) 13 | true (array-map :a 1) 14 | true (hash-set :a) 15 | true (seq [1 2 3]) 16 | true (seq (sorted-map :a 1)) 17 | true (seq (sorted-set :a)) 18 | true (range 0 10) 19 | true (range) 20 | true nil 21 | false 1 22 | false 1N 23 | false 1.0 24 | false 1.0M 25 | false :a-keyword 26 | false 'a-sym 27 | true "a string" 28 | #?(:cljs true :default false) \a 29 | true (object-array 3)))) 30 | -------------------------------------------------------------------------------- /test/clojure/core_test/sequential_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.sequential-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/sequential? 6 | (deftest test-sequential? 7 | (are [expected x] (= expected (sequential? x)) 8 | ;; lists, vectors, and seqs are sequential 9 | true '() 10 | true '(1 2 3) 11 | true [] 12 | true [1 2 3] 13 | true (range 10) 14 | true (range) ; Infinite lazy seq 15 | true (seq "abc") ; seqs are sequential even if strings aren't 16 | true (seq (to-array [1 2 3])) ; arrays aren't 17 | 18 | ;; other things are not sequential 19 | false nil ; perhaps surprising 20 | false {:a 1 :b 2} 21 | false #{:a :b} 22 | false "abc" 23 | false (to-array [1 2 3]) 24 | false :a 25 | false 'a 26 | false 1 27 | false \a))) 28 | -------------------------------------------------------------------------------- /test/clojure/core_test/set_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.set-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/set? 6 | (deftest test-set? 7 | (are [expected x] (= expected (set? x)) 8 | false [1 2 3] 9 | false (sorted-map :a 1) 10 | true (sorted-set :a) 11 | false '(1 2 3) 12 | false (hash-map :a 1) 13 | false (array-map :a 1) 14 | true (hash-set :a) 15 | false (seq [1 2 3]) 16 | false (seq (sorted-map :a 1)) 17 | false (seq (sorted-set :a)) 18 | false (range 0 10) 19 | false (range) 20 | false nil 21 | false 1 22 | false 1N 23 | false 1.0 24 | false 1.0M 25 | false :a-keyword 26 | false 'a-sym 27 | false "a string" 28 | false \a 29 | false (object-array 3)))) 30 | -------------------------------------------------------------------------------- /test/clojure/core_test/short.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.short 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/short 6 | (deftest test-short 7 | ;; There is no platform independent predicate to test for a 8 | ;; short (e.g., `short?`). In ClojureJVM, it's an instance of 9 | ;; `java.lang.Short`, but there is no predicate for it. Here, we just 10 | ;; test whether it's a fixed-length integer of some sort. 11 | (is (int? (short 0))) 12 | #?@(:cljs [] 13 | :default 14 | [(is (instance? java.lang.Short (short 0)))]) 15 | 16 | ;; Check conversions and rounding from other numeric types 17 | (are [expected x] (= expected (short x)) 18 | -32768 -32768 19 | 0 0 20 | 32767 32767 21 | 1 1N 22 | 0 0N 23 | -1 -1N 24 | 1 1.0M 25 | 0 0.0M 26 | -1 -1.0M 27 | #?@(:cljs ; short is a dummy cast in CLJS 28 | [1.1 1.1 29 | -1.1 -1.1 30 | 1.9 1.9] 31 | :default 32 | [1 1.1 33 | -1 -1.1 34 | 1 1.9]) 35 | #?@(:cljs [] 36 | :default 37 | [1 3/2 38 | -1 -3/2 39 | 0 1/10 40 | 0 -1/10]) 41 | #?@(:cljs 42 | [1.1 1.1M 43 | -1.1 -1.1M] 44 | :default 45 | [1 1.1M 46 | -1 -1.1M])) 47 | 48 | #?@(:cljs 49 | [;; CLJS short is just a dummy cast 50 | (is (= -32768.1 (short -32768.1))) 51 | (is (= -32769 (short -32769))) 52 | (is (= 32768 (short 32768))) 53 | (is (= 32767.1 (short 32767.1))) 54 | (is (= "0" (short "0"))) 55 | (is (= :0 (short :0))) 56 | (is (= [0] (short [0]))) 57 | (is (= nil (short nil)))] 58 | :default 59 | [;; `short` throws outside the range of 32767 ... -32768. 60 | (is (thrown? Exception (short -32768.000001))) 61 | (is (thrown? Exception (short -32769))) 62 | (is (thrown? Exception (short 32768))) 63 | (is (thrown? Exception (short 32767.000001))) 64 | 65 | ;; Check handling of other types 66 | (is (thrown? Exception (short "0"))) 67 | (is (thrown? Exception (short :0))) 68 | (is (thrown? Exception (short [0]))) 69 | (is (thrown? Exception (short nil)))]))) 70 | -------------------------------------------------------------------------------- /test/clojure/core_test/shuffle.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.shuffle 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/shuffle 6 | (deftest test-shuffle 7 | (testing "different collection types" 8 | (let [x [1 2 3] 9 | actual (shuffle x)] 10 | (is (vector? actual)) 11 | (is (= (count x) (count actual)))) 12 | (let [x #{1 2 3} 13 | actual (shuffle x)] 14 | (is (vector? actual)) 15 | (is (= (count x) (count actual)))) 16 | (let [x '(1 2 3) 17 | actual (shuffle x)] 18 | (is (vector? actual)) 19 | (is (= (count x) (count actual)))) 20 | #?(:cljs 21 | (let [x "abc" 22 | actual (shuffle x)] 23 | (is (vector? actual)) 24 | (is (= (count x) (count actual)))))) 25 | (testing "negative cases" 26 | (is (thrown? #?(:cljs :default, :default Exception) (shuffle 1))) 27 | #?@(:cljs 28 | [(is (= [] (shuffle nil))) 29 | (is [] (shuffle {}))] 30 | :default 31 | [(is (thrown? #?(:cljs :default, :default Exception) (shuffle nil))) 32 | (is (thrown? #?(:cljs :default, :default Exception) (shuffle "abc"))) 33 | (is (thrown? #?(:cljs :default, :default Exception) (shuffle {})))])))) 34 | -------------------------------------------------------------------------------- /test/clojure/core_test/simple_ident_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.simple-ident-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/simple-ident? 6 | (deftest test-simple-ident? 7 | (are [expected x] (= expected (simple-ident? x)) 8 | true :a-keyword 9 | true 'a-symbol 10 | false :a-ns/a-keyword 11 | false 'a-ns/a-keyword 12 | false "a string" 13 | false 0 14 | false 0N 15 | false 0.0 16 | #?@(:cljs [] 17 | :default 18 | [false 1/2]) 19 | false 0.0M 20 | false false 21 | false true 22 | false nil))) 23 | -------------------------------------------------------------------------------- /test/clojure/core_test/simple_keyword_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.simple-keyword-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/simple-keyword? 6 | (deftest test-simple-keyword? 7 | (are [expected x] (= expected (simple-keyword? x)) 8 | true :a-keyword 9 | false 'a-symbol 10 | false :a-ns/a-keyword 11 | false 'a-ns/a-keyword 12 | false "a string" 13 | false 0 14 | false 0N 15 | false 0.0 16 | #?@(:cljs [] 17 | :default 18 | [false 1/2]) 19 | false 0.0M 20 | false false 21 | false true 22 | false nil))) 23 | -------------------------------------------------------------------------------- /test/clojure/core_test/simple_symbol_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.simple-symbol-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/simple-symbol? 6 | (deftest test-simple-symbol? 7 | (are [expected x] (= expected (simple-symbol? x)) 8 | false :a-keyword 9 | true 'a-symbol 10 | false :a-ns/a-keyword 11 | false 'a-ns/a-keyword 12 | false "a string" 13 | false 0 14 | false 0N 15 | false 0.0 16 | #?@(:cljs [] 17 | :default 18 | [false 1/2]) 19 | false 0.0M 20 | false false 21 | false true 22 | false nil))) 23 | -------------------------------------------------------------------------------- /test/clojure/core_test/some_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.some-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/some? 6 | (deftest test-some? 7 | (testing "common" 8 | (are [given expected] (= expected (some? given)) 9 | nil false 10 | true true 11 | false true 12 | #?(:clj (Object.) 13 | :cljs #js {} 14 | :default :anything) true)) 15 | 16 | (testing "infinite-sequence" 17 | (is (= true (some? (range))))))) 18 | -------------------------------------------------------------------------------- /test/clojure/core_test/sort.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.sort 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/sort 6 | (deftest test-sort 7 | (testing "common cases -- unary" 8 | (are [expected x] (= expected (sort x)) 9 | '() nil 10 | '(1 2 3 4) [3 1 2 4] 11 | '(nil 2 3 4) [3 nil 2 4] 12 | '(1 2 3 4) '(3 1 2 4) 13 | '(1 2 3 4) #{3 1 2 4} 14 | '([:a 1] [:b 2] [:c 3]) {:c 3 :b 2 :a 1} 15 | '([1] [2] [3] [4]) [[3] [1] [2] [4]] 16 | '("a" "b" "c" "d") ["b" "a" "c" "d"] 17 | '(\c \e \j \l \o \r \u) "clojure")) 18 | (testing "common cases -- binary" 19 | (is (= '(4 3 2 1) (sort #(- (compare %1 %2)) [1 2 3 4])))) 20 | (testing "negative cases" 21 | (is (thrown? #?(:cljs :default, :default Exception) (sort 1))) 22 | (is (thrown? #?(:cljs :default, :default Exception) (sort [1 []])))) 23 | (testing "stable sort" 24 | (is (= '([1 :a] [1 :e] [2 :b] [2 :d] [3 :c]) 25 | (sort (fn [[a _] [b _]] (compare a b)) 26 | [[1 :a] [2 :b] [3 :c] [2 :d] [1 :e]])))))) 27 | -------------------------------------------------------------------------------- /test/clojure/core_test/sorted_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.sorted-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/sorted? 6 | (deftest test-sorted? 7 | ;; Note that `sorted?` tests whether the collection is a sorted 8 | ;; collection, not whether the elements of any arbitrary 9 | ;; collection may or may not be sorted. 10 | (testing "positive cases" 11 | ;; Sorted maps and sorted sets are `sorted?` 12 | (is (sorted? (sorted-map))) 13 | (is (sorted? (sorted-set))) 14 | (is (sorted? (sorted-map-by <))) 15 | (is (sorted? (sorted-set-by <)))) 16 | 17 | (testing "negative cases" 18 | ;; Most everyting else is not `sorted?` 19 | (are [coll] (not (sorted? coll)) 20 | (hash-map) 21 | (array-map) 22 | (hash-set) 23 | (vector) 24 | (list) 25 | (sort (range 10 0 -1)) ; the items are sorted, but it's not a sorted collection 26 | (seq (sorted-map)) ; seqs, even over sorted collections are not sorted 27 | (seq (sorted-set)) 28 | 1 ; primitives are not sorted 29 | 1N 30 | 1.0 31 | 1.0M 32 | :a-keyword 33 | 'a-sym 34 | "a string" 35 | true 36 | false 37 | (object-array 3) 38 | nil)))) 39 | -------------------------------------------------------------------------------- /test/clojure/core_test/star_squote.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.star-squote 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/*' 7 | (deftest test-*' 8 | (are [prod cand er] (= prod (*' cand er)) 9 | 0 0 0 10 | 0 1 0 11 | 0 0 1 12 | 1 1 1 13 | 5 1 5 14 | 5 5 1 15 | 25 5 5 16 | -1 1 -1 17 | -1 -1 1 18 | 1 -1 -1 19 | 0 -1 0 20 | 0 0 -1 21 | (inc r/min-int) r/max-int -1 22 | (inc r/min-int) -1 r/max-int 23 | 24 | 0.0 0.0 0.0 25 | 0.0 1.0 0.0 26 | 0.0 0.0 1.0 27 | 1.0 1.0 1.0 28 | 5.0 1.0 5.0 29 | 5.0 5.0 1.0 30 | 25.0 5.0 5.0 31 | -1.0 1.0 -1.0 32 | -1.0 -1.0 1.0 33 | 1.0 -1.0 -1.0 34 | 0.0 -1.0 0.0 35 | 0.0 0.0 -1.0 36 | 37 | 0.0 0.0 0 38 | 0.0 1.0 0 39 | 0.0 0.0 1 40 | 1.0 1.0 1 41 | 5.0 1.0 5 42 | 5.0 5.0 1 43 | 25.0 5.0 5 44 | -1.0 1.0 -1 45 | -1.0 -1.0 1 46 | 1.0 -1.0 -1 47 | 0.0 -1.0 0 48 | 0.0 0.0 -1 49 | 50 | 0.0 0 0.0 51 | 0.0 1 0.0 52 | 0.0 0 1.0 53 | 1.0 1 1.0 54 | 5.0 1 5.0 55 | 5.0 5 1.0 56 | 25.0 5 5.0 57 | -1.0 1 -1.0 58 | -1.0 -1 1.0 59 | 1.0 -1 -1.0 60 | 0.0 -1 0.0 61 | 0.0 0 -1.0 62 | 63 | 0 0 1N 64 | 0 0N 1 65 | 0 0N 1N 66 | 1 1N 1 67 | 1 1 1N 68 | 1 1N 1N 69 | 5 1 5N 70 | 5 1N 5 71 | 5 1N 5N) 72 | 73 | (is (thrown? #?(:cljs :default :clj Exception) (*' 1 nil))) 74 | (is (thrown? #?(:cljs :default :clj Exception) (*' nil 1))) 75 | 76 | (is (instance? clojure.lang.BigInt (*' 0 1N))) 77 | (is (instance? clojure.lang.BigInt (*' 0N 1))) 78 | (is (instance? clojure.lang.BigInt (*' 0N 1N))) 79 | (is (instance? clojure.lang.BigInt (*' 1N 1))) 80 | (is (instance? clojure.lang.BigInt (*' 1 1N))) 81 | (is (instance? clojure.lang.BigInt (*' 1N 1N))) 82 | (is (instance? clojure.lang.BigInt (*' 1 5N))) 83 | (is (instance? clojure.lang.BigInt (*' 1N 5))) 84 | (is (instance? clojure.lang.BigInt (*' 1N 5N))) 85 | 86 | (is (instance? clojure.lang.BigInt (*' -1 r/min-int))) 87 | (is (instance? clojure.lang.BigInt (*' r/min-int -1))) 88 | (is (instance? clojure.lang.BigInt (*' (long (/ r/min-int 2)) 3))) 89 | (is (instance? clojure.lang.BigInt (*' 3 (long (/ r/min-int 2))))))) 90 | -------------------------------------------------------------------------------- /test/clojure/core_test/str.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.str 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/str 6 | (deftest test-str 7 | (are [expected x] (= expected (str x)) 8 | "0" 0 9 | "1" 1 10 | "-1" -1 11 | #?@(:cljs 12 | ["0" 0.0 13 | "1" 1.0 14 | "-1" -1.0 15 | "0" 0.00000 16 | "0" (float 0.0) 17 | "1" (float 1.0) 18 | "-1" (float -1.0) 19 | "0" (double 0.0) 20 | "1" (double 1.0) 21 | "-1" (double -1.0)] 22 | :default 23 | ["0.0" 0.0 24 | "1.0" 1.0 25 | "-1.0" -1.0 26 | "0.0" 0.00000 27 | "0.0" (float 0.0) 28 | "1.0" (float 1.0) 29 | "-1.0" (float -1.0) 30 | "0.0" (double 0.0) 31 | "1.0" (double 1.0) 32 | "-1.0" (double -1.0)]) 33 | "Infinity" ##Inf 34 | "-Infinity" ##-Inf 35 | "NaN" ##NaN 36 | "0" 0N 37 | "1" 1N 38 | "-1" -1N 39 | #?@(:cljs 40 | ["0" 0.0M 41 | "1" 1.0M 42 | "-1" -1.0M] 43 | :default 44 | ["0" 0/2 45 | "1/2" 1/2 46 | "-1/2" -1/2 47 | "0.0" 0.0M 48 | "1.0" 1.0M 49 | "-1.0" -1.0M]) 50 | 51 | "" nil 52 | "true" true 53 | "false" false 54 | "a string" "a string" 55 | "0" "0" 56 | "1" "1" 57 | "-1" "-1" 58 | "{:a :map}" {:a :map} ; keep this one item because it's unordered 59 | "#{:a-set}" #{:a-set} ; keep this one item because it's unordered 60 | "[:a :vector]" [:a :vector] 61 | "(:a :list)" '(:a :list) 62 | "0" \0 63 | "1" \1 64 | "A" \A 65 | " " \space 66 | ":a-keyword" :a-keyword 67 | ":0" :0 68 | ":1" :1 69 | ":-1" :-1 70 | "a-sym" 'a-sym) 71 | 72 | ;; No arg and var arg versions 73 | (is (= "" (str))) 74 | (is (= "astringwithnospaces" (str "a" "string" "with" "no" "spaces"))))) 75 | -------------------------------------------------------------------------------- /test/clojure/core_test/string_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.string-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/string? 7 | (deftest test-string? 8 | (are [expected x] (= expected (string? x)) 9 | false 0 10 | false 1 11 | false -1 12 | false r/max-int 13 | false r/min-int 14 | false 0.0 15 | false 1.0 16 | false -1.0 17 | false (float 0.0) 18 | false (float 1.0) 19 | false (float -1.0) 20 | false (double 0.0) 21 | false (double 1.0) 22 | false (double -1.0) 23 | false r/max-double 24 | false r/min-double 25 | false ##Inf 26 | false ##-Inf 27 | false ##NaN 28 | false 0N 29 | false 1N 30 | false -1N 31 | #?@(:cljs [] 32 | :default 33 | [false 0/2 34 | false 1/2 35 | false -1/2]) 36 | false 0.0M 37 | false 1.0M 38 | false -1.0M 39 | false nil 40 | false true 41 | false false 42 | true "a string" 43 | true "0" 44 | true "1" 45 | true "-1" 46 | false {:a :map} 47 | false #{:a-set} 48 | false [:a :vector] 49 | false '(:a :list) 50 | #?@(:cljs 51 | [true \0 52 | true \1 53 | true \A 54 | true \space] 55 | :default 56 | [false \0 57 | false \1 58 | false \A 59 | false \space]) 60 | false :a-keyword 61 | false :0 62 | false :1 63 | false :-1 64 | false 'a-sym))) 65 | -------------------------------------------------------------------------------- /test/clojure/core_test/subs.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.subs 2 | (:require [clojure.test :as t :refer [deftest is]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/subs 6 | (deftest test-subs 7 | (is (= "abcde" (subs "abcde" 0))) 8 | (is (= "abcde" (subs "abcde" 0 5))) 9 | (is (= "ab֎de" (subs "ab֎de" 0))) 10 | (is (= "ab֎de" (subs "ab֎de" 0 5))) 11 | (is (= "bcde" (subs "abcde" 1))) 12 | (is (= "bcde" (subs "֎bcde" 1))) 13 | (is (= "bcd" (subs "abcde" 1 4))) 14 | (is (= "bcd" (subs "֎bcde" 1 4))) 15 | (is (= "abc" (subs "abcde" 0 3))) 16 | (is (= "ab֎" (subs "ab֎de" 0 3))) 17 | (is (= "" (subs "" 0 0))) 18 | (is (= "" (subs "" 0))) 19 | (is (= "" (subs "abcde" 0 0))) 20 | (is (= "" (subs "֎bcde" 0 0))) 21 | (is (= "" (subs "abcde" 5))) 22 | (is (= "" (subs "abcd֎" 5))) 23 | (is (= "" (subs "abcde" 5 5))) 24 | (is (= "" (subs "abcd֎" 5 5))) 25 | (is (= "" (subs "abcde" 4 4))) 26 | (is (= "" (subs "abc֎e" 4 4))) 27 | #?@(:cljs 28 | [(is (= "b" (subs "abcde" 2 1))) 29 | (is (= "bcde" (subs "abcde" 1 6))) 30 | (is (= "bcde" (subs "abcde" 1 200))) 31 | (is (= "abcde" (subs "abcde" -1))) 32 | (is (= "abc" (subs "abcde" -1 3))) 33 | (is (= "" (subs "abcde" -1 -3))) 34 | (is (thrown? :default (subs nil 1 2))) 35 | (is (= "ab" (subs "abcde" nil 2))) 36 | (is (= "a" (subs "abcde" 1 nil)))] 37 | :default 38 | [(is (thrown? #?(:clj Exception) (subs "abcde" 2 1))) 39 | (is (thrown? #?(:clj Exception) (subs "abcde" 1 6))) 40 | (is (thrown? #?(:clj Exception) (subs "abcde" 1 200))) 41 | (is (thrown? #?(:clj Exception) (subs "abcde" -1))) 42 | (is (thrown? #?(:clj Exception) (subs "abcde" -1 3))) 43 | (is (thrown? #?(:clj Exception) (subs "abcde" -1 -3))) 44 | (is (thrown? #?(:clj Exception) (subs nil 1 2))) 45 | (is (thrown? #?(:clj Exception) (subs "abcde" nil 2))) 46 | (is (thrown? #?(:clj Exception) (subs "abcde" 1 nil)))]))) 47 | -------------------------------------------------------------------------------- /test/clojure/core_test/symbol.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.symbol 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/symbol 6 | (deftest test-symbol 7 | ;; "Symbols begin with a non-numeric character and can contain 8 | ;; alphanumeric characters and *, +, !, -, _, ', ?, <, > and = 9 | ;; (other characters may be allowed eventually)." 10 | ;; (see http://clojure.org/reader for details) 11 | ;; 12 | ;; From https://clojuredocs.org/clojure.core/keyword 13 | ;; keyword does not validate input strings for ns and name, and may 14 | ;; return improper keywords with undefined behavior for non-conformant 15 | ;; ns and name. 16 | 17 | (are [expected name] (= expected (symbol name)) 18 | 'abc "abc" 19 | 'abc 'abc 20 | 'abc :abc 21 | '* "*" 22 | '* '* 23 | '* :* 24 | '+ "+" 25 | '+ '+ 26 | '+ :+ 27 | '! "!" 28 | '! '! 29 | '! :! 30 | '- "-" 31 | '- '- 32 | '- :- 33 | '_ "_" 34 | '_ '_ 35 | '_ :_ 36 | '? "?" 37 | '? '? 38 | '? :? 39 | '< "<" 40 | '< '< 41 | '< :< 42 | '> ">" 43 | '> '> 44 | '> :> 45 | '= "=" 46 | '= '= 47 | '= := 48 | 'abc*+!-_'?<>= "abc*+!-_'?<>=" 49 | #?(:cljs 'cljs.core/+ 50 | :default 'clojure.core/+) #'+) 51 | 52 | (are [expected ns name] (= expected (symbol ns name)) 53 | 'abc/abc "abc" "abc" 54 | 'abc.def/abc "abc.def" "abc" 55 | 56 | '*/abc "*" "abc" 57 | '+/abc "+" "abc" 58 | '!/abc "!" "abc" 59 | '-/abc "-" "abc" 60 | '_/abc "_" "abc" 61 | '?/abc "?" "abc" 62 | '/abc ">" "abc" 64 | '=/abc "=" "abc" 65 | 66 | 'abc.def/* "abc.def" "*" 67 | 'abc.def/+ "abc.def" "+" 68 | 'abc.def/! "abc.def" "!" 69 | 'abc.def/- "abc.def" "-" 70 | 'abc.def/_ "abc.def" "_" 71 | 'abc.def/? "abc.def" "?" 72 | 'abc.def/< "abc.def" "<" 73 | 'abc.def/> "abc.def" ">" 74 | 'abc.def/= "abc.def" "=" 75 | 76 | 'abc*+!-_'?<>=/abc*+!-_'?<>= "abc*+!-_'?<>=" "abc*+!-_'?<>=") 77 | 78 | (is (thrown? #?(:cljs :default :clj Exception) (symbol nil))) 79 | (is (= 'abc (symbol nil "abc"))) ; if ns is nil, it just ignores it. 80 | 81 | ;; prints as 'abc/null but the null is really a nil. Since this is 82 | ;; not readable via the standard Clojure reader, I'm not even sure 83 | ;; how to test this case here. That's why it's commented out. 84 | ;; Note that `keyword` throws for this case. 85 | ;; (is (= 'abc/null (symbol "abc" nil))) 86 | 87 | ;; Two arg version requires namespace and symbol to be a string, not 88 | ;; a symbol or keyword like the one arg version. 89 | #?@(:cljs 90 | [(is (= 'abc/abc (symbol 'abc "abc"))) 91 | (is (= 'abc/abc (symbol "abc" 'abc))) 92 | ;; (is (= :abc/abc (symbol :abc "abc"))) results in unreadable value 93 | (is (= 'abc/:abc (symbol "abc" :abc)))] 94 | :default 95 | [(is (thrown? #?(:clj Exception) (symbol 'abc "abc"))) 96 | (is (thrown? #?(:clj Exception) (symbol "abc" 'abc))) 97 | (is (thrown? #?(:clj Exception) (symbol :abc "abc"))) 98 | (is (thrown? #?(:clj Exception) (symbol "abc" :abc)))]))) 99 | -------------------------------------------------------------------------------- /test/clojure/core_test/symbol_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.symbol-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/symbol? 6 | (deftest test-symbol? 7 | (are [expected x] (= expected (symbol? x)) 8 | false :a-keyword 9 | true 'a-symbol 10 | false :a-ns/a-keyword 11 | true 'a-ns/a-keyword 12 | false "a string" 13 | false 0 14 | false 0N 15 | false 0.0 16 | #?@(:cljs [] 17 | :default 18 | [false 1/2]) 19 | false 0.0M 20 | false false 21 | false true 22 | false nil))) 23 | -------------------------------------------------------------------------------- /test/clojure/core_test/take.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.take 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/take 6 | (deftest test-take 7 | (is (= (range 0 5) (take 5 (range 0 10)))) 8 | (is (= (range 0 5) (take 5 (range)))) ; Infinite `range` lazy seq 9 | (is (= '() (take 5 nil))) 10 | 11 | ;; transducer versions 12 | (is (= (vec (range 0 5)) (into [] (take 5) (range 0 10)))) 13 | (is (= (vec (range 0 5)) (into [] (take 5) (range)))) 14 | (is (= [] (into [] (take 5) nil))) 15 | 16 | ;; negative tests 17 | (is (thrown? #?(:cljs :default :clj Exception) 18 | (doall (take nil (range 0 10))))) 19 | (is (thrown? #?(:cljs :default :clj Exception) 20 | (into [] (take nil) (range 0 10)))))) 21 | -------------------------------------------------------------------------------- /test/clojure/core_test/take_last.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.take-last 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/take-last 6 | (deftest test-take-last 7 | (is (= (range 8 10) (take-last 2 (range 0 10)))) 8 | (is (nil? (take-last 2 nil))) ; Returns `nil`, not `()` 9 | 10 | ;; Note that there is no transducer version of `take-last` in 11 | ;; `clojure.core`. 12 | 13 | ;; Negative testing 14 | (is (thrown? #?(:cljs :default :clj Exception) 15 | (doall (take-last nil (range 0 10))))))) 16 | -------------------------------------------------------------------------------- /test/clojure/core_test/take_while.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.take-while 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/take-while 6 | (deftest test-take-while 7 | (is (= (range 0 5) (take-while #(< % 5) (range 0 10)))) 8 | (is (= '(0 1 2 3 4) (take-while #(< % 5) (range)))) ; Infinite lazy `range` 9 | (is (= '(:a :b :c) (take-while keyword? [:a :b :c 1 2 3]))) 10 | (is (= '() (take-while #(< % 5) nil))) 11 | 12 | ;; transducer versions 13 | (is (= (vec (range 0 5)) (into [] (take-while #(< % 5)) (range 0 10)))) 14 | (is (= [:a :b :c] (into [] (take-while keyword?) [:a :b :c 1 2 3]))) 15 | (is (= [] (into [] (take-while #(< % 5)) nil))) 16 | 17 | ;; Negative tests 18 | (is (thrown? #?(:cljs :default :clj Exception) 19 | (doall (take-while nil (range 0 10))))) 20 | (is (thrown? #?(:cljs :default :clj Exception) 21 | (into [] (take-while nil) (range 0 10)))))) 22 | -------------------------------------------------------------------------------- /test/clojure/core_test/taps.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.taps 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | #?(:cljs [cljs.test :refer-macros [async]]) 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/add-tap 7 | #?(:cljs 8 | (do 9 | (defn tap-tester 10 | [atom-ref] 11 | (fn [x] 12 | (if (fn? x) 13 | (x nil) 14 | (swap! atom-ref conj x)))) 15 | 16 | (defn await-tap 17 | [] 18 | (let [promise-obj (js/Promise.withResolvers) 19 | promise (.-promise promise-obj) 20 | resolve (.-resolve promise-obj)] 21 | (tap> resolve) 22 | promise)) 23 | 24 | (defn p-delay 25 | "This is safer in JS given tap> uses setTimeout 0 instead of a thread" 26 | [ms] 27 | (let [{:keys [promise resolve]} (js->clj (js/Promise.withResolvers) 28 | :keywordize-keys true)] 29 | (js/setTimeout resolve ms) 30 | promise)) 31 | 32 | (deftest tapping 33 | (async 34 | done 35 | (let [data-ref-1 (atom []) 36 | data-ref-2 (atom []) 37 | tester-1 (tap-tester data-ref-1) 38 | tester-2 (tap-tester data-ref-2)] 39 | 40 | (-> (js/Promise.resolve) 41 | (.then (fn [] 42 | (tap> 0) 43 | (p-delay 2))) 44 | (.then (fn [] (is (nil? (add-tap tester-1))))) 45 | (.then (fn [] 46 | (tap> 0) 47 | (tap> 1) 48 | (await-tap))) 49 | (.then (fn [] 50 | (is (nil? (add-tap tester-2))))) 51 | (.then (fn [] 52 | (tap> 2) 53 | (await-tap))) 54 | (.then (fn [] 55 | (remove-tap tester-1))) 56 | (.then (fn [] 57 | (tap> 3) 58 | (await-tap))) 59 | (.then (fn [] 60 | (is (= [0 1 2] @data-ref-1)) 61 | (is (= [2 3] @data-ref-2)))) 62 | (.then done done)))))) 63 | 64 | :default 65 | (do 66 | (defn tap-tester 67 | [atom-ref] 68 | (fn [x] 69 | (if (instance? clojure.lang.IPending x) 70 | (deliver x nil) 71 | (swap! atom-ref conj x)))) 72 | 73 | (defn await-tap 74 | [] 75 | (let [p (promise)] 76 | (tap> p) 77 | @p)) 78 | 79 | (deftest tapping 80 | (let [data-ref-1 (atom []) 81 | data-ref-2 (atom []) 82 | tester-1 (tap-tester data-ref-1) 83 | tester-2 (tap-tester data-ref-2)] 84 | 85 | (tap> 0) 86 | (is (nil? (add-tap tester-1))) 87 | (tap> 0) 88 | (tap> 1) 89 | (await-tap) 90 | (is (nil? (add-tap tester-2))) 91 | (tap> 2) 92 | (await-tap) 93 | (remove-tap tester-1) 94 | (tap> 3) 95 | (await-tap) 96 | (is (= [0 1 2] @data-ref-1)) 97 | (is (= [2 3] @data-ref-2))))))) 98 | 99 | ;; can test in the next iteration of the event loop, but this won't show up in the testing results 100 | -------------------------------------------------------------------------------- /test/clojure/core_test/true_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.true-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/true? 7 | (deftest test-true? 8 | (are [expected x] (= expected (true? x)) 9 | false 0 10 | false 1 11 | false -1 12 | false r/max-int 13 | false r/min-int 14 | false 0.0 15 | false 1.0 16 | false -1.0 17 | false (float 0.0) 18 | false (float 1.0) 19 | false (float -1.0) 20 | false (double 0.0) 21 | false (double 1.0) 22 | false (double -1.0) 23 | false r/max-double 24 | false r/min-double 25 | false ##Inf 26 | false ##-Inf 27 | false ##NaN 28 | false 0N 29 | false 1N 30 | false -1N 31 | #?@(:cljs [] 32 | :default 33 | [false 0/2 34 | false 1/2 35 | false -1/2]) 36 | false 0.0M 37 | false 1.0M 38 | false -1.0M 39 | false nil 40 | true true 41 | false false 42 | false "a string" 43 | false "0" 44 | false "1" 45 | false "-1" 46 | false "true" 47 | false "false" 48 | false {:a :map} 49 | false #{:a-set} 50 | false [:a :vector] 51 | false '(:a :list) 52 | false \0 53 | false \1 54 | false :a-keyword 55 | false :true 56 | false :false 57 | false :0 58 | false :1 59 | false :-1 60 | false 'a-sym))) 61 | -------------------------------------------------------------------------------- /test/clojure/core_test/unsigned_bit_shift_right.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.unsigned-bit-shift-right 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/unsigned-bit-shift-right 6 | (deftest test-unsigned-bit-shift-right 7 | #?(:cljs (is (= 0 (unsigned-bit-shift-right nil 1))) 8 | :default (is (thrown? #?(:clj Exception) (unsigned-bit-shift-right nil 1)))) 9 | #?(:cljs (is (= 1 (unsigned-bit-shift-right 1 nil))) 10 | :default (is (thrown? #?(:clj Exception) (unsigned-bit-shift-right 1 nil)))) 11 | 12 | (are [ex a b] (= ex (unsigned-bit-shift-right a b)) 13 | ;; Clojure JVM starts with a 64-bit -1 and ClojureScript starts 14 | ;; with a 32-bit -1 15 | #?@(:cljs 16 | [4194303 -1 10] 17 | :default 18 | [18014398509481983 -1 10])))) 19 | -------------------------------------------------------------------------------- /test/clojure/core_test/vector_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.vector-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/vector? 6 | (deftest test-vector? 7 | (are [expected x] (= expected (vector? x)) 8 | true [1 2 3] 9 | true (first {:a 1}) ; map entries are also vectors 10 | false (sorted-map :a 1) 11 | false (sorted-set :a) 12 | false '(1 2 3) 13 | false (hash-map :a 1) 14 | false (array-map :a 1) 15 | false (hash-set :a) 16 | false (seq [1 2 3]) 17 | false (seq (sorted-map :a 1)) 18 | false (seq (sorted-set :a)) 19 | false (range 0 10) 20 | false (range) 21 | false nil 22 | false 1 23 | false 1N 24 | false 1.0 25 | false 1.0M 26 | false :a-keyword 27 | false 'a-sym 28 | false "a string" 29 | false \a 30 | false (object-array 3)))) 31 | -------------------------------------------------------------------------------- /test/clojure/core_test/with_out_str.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.with-out-str 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/with-out-str 6 | (deftest test-with-out-str 7 | (is (= (str "some sample :text here" (println-str) 8 | "[:a :b] {:c :d} #{:e} (:f)" (prn-str)) 9 | (with-out-str 10 | (println "some" "sample" :text 'here) 11 | (prn [:a :b] {:c :d} #{:e} '(:f))))))) 12 | -------------------------------------------------------------------------------- /test/clojure/core_test/with_precision.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.with-precision 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists clojure.core/with-precision 6 | (deftest test-with-precision 7 | ;; tests copied from https://clojuredocs.org/clojure.core/with-precision 8 | (is (= 2M (with-precision 1 :rounding UP (* 1.1M 1M)))) 9 | (is (= 2M (with-precision 1 :rounding CEILING (* 1.1M 1M)))) 10 | (is (= -2M (with-precision 1 :rounding UP (* -1.1M 1M)))) 11 | (is (= -1M (with-precision 1 :rounding CEILING (* -1.1M 1M)))) 12 | 13 | (is (= 1M (with-precision 1 :rounding DOWN (* 1.9M 1M)))) 14 | (is (= 1M (with-precision 1 :rounding FLOOR (* 1.9M 1M)))) 15 | (is (= -1M (with-precision 1 :rounding DOWN (* -1.9M 1M)))) 16 | (is (= -2M (with-precision 1 :rounding FLOOR (* -1.9M 1M)))) 17 | 18 | (is (= 2M (with-precision 1 :rounding HALF_EVEN (* 1.5M 1M)))) 19 | (is (= 2M (with-precision 1 :rounding HALF_EVEN (* 2.5M 1M)))) 20 | (is (= -2M (with-precision 1 :rounding HALF_EVEN (* -1.5M 1M)))) 21 | (is (= -2M (with-precision 1 :rounding HALF_EVEN (* -2.5M 1M)))) 22 | 23 | (is (= 2M (with-precision 1 :rounding HALF_UP (* 1.5M 1M)))) 24 | (is (= 1M (with-precision 1 :rounding HALF_DOWN (* 1.5M 1M)))) 25 | (is (= -2M (with-precision 1 :rounding HALF_UP (* -1.5M 1M)))) 26 | (is (= -1M (with-precision 1 :rounding HALF_DOWN (* -1.5M 1M)))) 27 | 28 | (is (thrown? Exception (with-precision 1 :rounding UNNECESSARY (* 1.5M 1M)))) ;; => Execution error (ArithmeticException) at... Rounding necessary 29 | (is (= 2M (with-precision 1 :rounding UNNECESSARY (* 2M 1M)))))) 30 | -------------------------------------------------------------------------------- /test/clojure/core_test/zero_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.zero-qmark 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.number-range :as r] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists clojure.core/zero? 7 | (deftest test-zero? 8 | (are [expected x] (= expected (zero? x)) 9 | true 0 10 | false 1 11 | false -1 12 | false r/min-int 13 | false r/max-int 14 | true 0.0 15 | false 1.0 16 | false -1.0 17 | false r/min-double 18 | false r/max-double 19 | false ##Inf 20 | false ##-Inf 21 | false ##NaN 22 | true 0N 23 | false 1N 24 | false -1N 25 | #?@(:cljs [] 26 | :default 27 | [true 0/2 28 | false 1/2 29 | false -1/2]) 30 | true 0.0M 31 | false 1.0M 32 | false -1.0M) 33 | 34 | (is #?@(:cljs [(= false (zero? nil))] 35 | :default [(thrown? Exception (zero? nil))])) 36 | (is #?@(:cljs [(= false (zero? false))] 37 | :default [(thrown? Exception (zero? false))])) 38 | (is #?@(:cljs [(= false (zero? true))] 39 | :default [(thrown? Exception (zero? true))])))) 40 | -------------------------------------------------------------------------------- /test/clojure/core_test/zipmap.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core-test.zipmap 2 | (:require [clojure.test :as t :refer [deftest testing is are]] 3 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 4 | 5 | (when-var-exists 6 | clojure.core/zipmap 7 | (deftest test-zipmap 8 | (testing "Common cases" 9 | (are [in ex] (= (apply zipmap in) ex) 10 | [[1 2 3] ["a" "b" "c"]] {1 "a" 2 "b" 3 "c"} 11 | [#{1} #{"a"}] {1 "a"} 12 | [(sorted-set 1 2 3) 13 | (sorted-set "a" "b" "c")] {1 "a" 2 "b" 3 "c"} 14 | [(sorted-map :a 1 :b 2) 15 | ["a" "b"]] {[:a 1] "a" [:b 2] "b"} 16 | ['(1 2 3) '("a" "b" "c")] {1 "a" 2 "b" 3 "c"} 17 | ["123" "abc"] {\1 \a \2 \b \3 \c} 18 | [[:a] [nil]] {:a nil} 19 | [[nil] [:a]] {nil :a})) 20 | (testing "Differing sequence sizes" 21 | (are [in ex] (= (apply zipmap in) ex) 22 | [[1 2] ["a" "b" "c"]] {1 "a" 2 "b"} 23 | ['(1 2 3) '("a" "b")] {1 "a" 2 "b"} 24 | [(range) '("a" "b")] {0 "a" 1 "b"} 25 | [(range) nil] {} 26 | [nil (range)] {})) 27 | (testing "Esoteric cases" 28 | (are [in ex] (= (apply zipmap in) ex) 29 | [(range) '("a" "b")] {0 "a" 1 "b"})) 30 | (testing "Bad inputs" 31 | #?(:clj (is (thrown? Exception (zipmap :not-seqable [1 2 3])))) 32 | #?(:clj (is (thrown? Exception (zipmap 123 [1 2 3]))))))) 33 | -------------------------------------------------------------------------------- /test/clojure/string_test/blank_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.string-test.blank-qmark 2 | (:require [clojure.string :as str] 3 | [clojure.test :as t :refer [deftest testing is are]] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists str/blank? 7 | (deftest test-blank? 8 | (is (true? (str/blank? ""))) 9 | (is (true? (str/blank? nil))) 10 | (is (false? (str/blank? "֎"))) 11 | (testing "U+2007" 12 | (is (#?(:cljs true? :default false?) (str/blank? " "))) 13 | (is (#?(:cljs true? :default false?) (str/blank? "\u2007")))) 14 | (is (true? (str/blank? " "))) 15 | (is (true? (str/blank? " \t "))) 16 | #?(:cljs (do (is (true? (str/blank? (symbol "")))) 17 | (is (false? (str/blank? 'a)))) 18 | :default (is (thrown? #?(:clj Exception) (str/blank? (symbol ""))))) 19 | #?(:cljs (do (is (false? (str/blank? (keyword "")))) 20 | (is (false? (str/blank? :a)))) 21 | :default (is (thrown? #?(:clj Exception) (str/blank? (keyword ""))))) 22 | #?(:cljs (is (false? (str/blank? 1))) 23 | :default (is (thrown? #?(:clj Exception) (str/blank? 1)))) 24 | #?(:cljs (do (is (true? (str/blank? \space))) 25 | (is (false? (str/blank? \a)))) 26 | :default (is (thrown? #?(:clj Exception) (str/blank? \space)))) 27 | (is (false? (str/blank? "nil"))) 28 | (is (false? (str/blank? " as df "))))) 29 | -------------------------------------------------------------------------------- /test/clojure/string_test/capitalize.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.string-test.capitalize 2 | (:require [clojure.string :as str] 3 | [clojure.test :as t :refer [deftest testing is are]] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists str/capitalize 7 | (deftest test-capitalize 8 | (is (thrown? #?(:cljs :default :clj Exception) (str/capitalize nil))) 9 | #?(:cljs (do (is (thrown? :default (str/capitalize 1))) 10 | (is (thrown? :default (str/capitalize 'a))) 11 | (is (thrown? :default (str/capitalize 'a/a))) 12 | (is (thrown? :default (str/capitalize :a))) 13 | (is (thrown? :default (str/capitalize :a/a)))) 14 | :default (do (is (= "1" (str/capitalize 1))) 15 | (is (= "Asdf" (str/capitalize 'Asdf))) 16 | (is (= "Asdf/asdf" (str/capitalize 'asDf/aSdf))) 17 | (is (= ":asdf/asdf" (str/capitalize :asDf/aSdf))))) 18 | (is (= "" (str/capitalize ""))) 19 | (is (= "A" (str/capitalize "a"))) 20 | (is (= "֎" (str/capitalize "֎"))) 21 | (is (= "A thing" (str/capitalize "a Thing"))) 22 | (is (= "A thing" (str/capitalize "A THING"))) 23 | (is (= "A thing" (str/capitalize "A thing"))))) 24 | -------------------------------------------------------------------------------- /test/clojure/string_test/ends_with_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.string-test.ends-with-qmark 2 | (:require [clojure.string :as str] 3 | [clojure.test :as t :refer [deftest testing is are]] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists str/ends-with? 7 | (deftest test-ends-with? 8 | (is (true? (str/ends-with? "" ""))) 9 | (is (thrown? #?(:cljs :default :clj Exception) (str/ends-with? "" nil))) 10 | (is (thrown? #?(:cljs :default :clj Exception) (str/ends-with? nil ""))) 11 | #?(:cljs (do (is (false? (str/ends-with? "ab" :b))) 12 | (is (false? (str/ends-with? "ab" :a)))) 13 | :default (is (thrown? #?(:clj Exception) (str/ends-with? "ab" :b)))) 14 | #?(:cljs (is (false? (str/ends-with? "ab" 'b))) 15 | :default (is (thrown? #?(:clj Exception) (str/ends-with? "ab" 'b)))) 16 | (is (#?(:cljs false? :default true?) (str/ends-with? 'ab "b"))) 17 | (is (false? (str/ends-with? 'ab "a"))) 18 | (is (#?(:cljs false? :default true?) (str/ends-with? :ab "b"))) 19 | (is (false? (str/ends-with? :ab "a"))) 20 | (is (false? (str/ends-with? "" "a"))) 21 | (is (true? (str/ends-with? "a-test" ""))) 22 | (is (true? (str/ends-with? "a-test֎" "֎"))) 23 | (is (true? (str/ends-with? "a-test" "t"))) 24 | (is (true? (str/ends-with? "a-test" "a-test"))) 25 | (is (false? (str/ends-with? "a-test" "s"))) 26 | (is (false? (str/ends-with? "a-test" "a"))))) 27 | -------------------------------------------------------------------------------- /test/clojure/string_test/escape.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.string-test.escape 2 | (:require [clojure.string :as str] 3 | [clojure.test :as t :refer [deftest testing is are]] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists str/escape 7 | (deftest test-escape 8 | (is (= "" (str/escape "" {}))) 9 | (is (= "" (str/escape "" {\c "C_C"}))) 10 | (is (= "A_Abc" (str/escape "abc" {\a "A_A"}))) 11 | (is (= "A_AbC_C" (str/escape "abc" {\a "A_A" \c "C_C"}))) 12 | (is (= "A_AbC_C" (str/escape "abc" {\a "A_A" \c "C_C" (int \a) 1 nil 'junk :garbage 42.42}))) 13 | (is (= "A_AbC_C" (str/escape "abc" {\a "A_A" \c "C_C"}))) 14 | (is (thrown? #?(:cljs :default :clj Exception) (str/escape nil {\a "A_A" \c "C_C"}))) 15 | (is (thrown? #?(:cljs :default :clj Exception) (str/escape 1 {\a "A_A" \c "C_C"}))) 16 | (is (thrown? #?(:cljs :default :clj Exception) (str/escape 'a {\a "A_A" \c "C_C"}))) 17 | (is (thrown? #?(:cljs :default :clj Exception) (str/escape :a {\a "A_A" \c "C_C"}))))) 18 | -------------------------------------------------------------------------------- /test/clojure/string_test/lower_case.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.string-test.lower-case 2 | (:require [clojure.string :as str] 3 | [clojure.test :as t :refer [deftest testing is are]] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists str/lower-case 7 | (deftest test-lower-case 8 | (is (thrown? #?(:cljs :default :clj Exception) (str/lower-case nil))) 9 | (is (= "" (str/lower-case ""))) 10 | (is (= "֎" (str/lower-case "֎"))) 11 | (is (= "asdf" (str/lower-case "AsdF"))) 12 | (is (= "asdf" (str/lower-case "asdf"))) 13 | (let [s "ASDF"] 14 | (is (= "asdf" (str/lower-case "ASDF"))) 15 | (is (= "ASDF" s) "original string mutated")) 16 | #?(:cljs (is (thrown? :default (str/lower-case :ASDF))) 17 | :default (is (= ":asdf" (str/lower-case :ASDF)))) 18 | #?(:cljs (is (thrown? :default (str/lower-case :ASDF/ASDF))) 19 | :default (is (= ":asdf/asdf" (str/lower-case :ASDF/ASDF)))) 20 | #?(:cljs (is (thrown? :default (str/lower-case 'ASDF))) 21 | :default (is (= "asdf" (str/lower-case 'ASDF)))))) 22 | -------------------------------------------------------------------------------- /test/clojure/string_test/reverse.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.string-test.reverse 2 | (:require [clojure.string :as str] 3 | [clojure.test :as t :refer [deftest testing is are]] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists str/reverse 7 | (deftest test-reverse 8 | (is (= "" (str/reverse ""))) 9 | (is (= "֎" (str/reverse "֎"))) 10 | (is (= "a֎" (str/reverse "֎a"))) 11 | (is (= "tset-a" (str/reverse "a-test"))) 12 | (is (thrown? #?(:cljs :default :clj Exception) (str/reverse nil))) 13 | (is (thrown? #?(:cljs :default :clj Exception) (str/reverse 1))) 14 | (is (thrown? #?(:cljs :default :clj Exception) (str/reverse 'a-test))) 15 | (is (thrown? #?(:cljs :default :clj Exception) (str/reverse :a-test))))) 16 | -------------------------------------------------------------------------------- /test/clojure/string_test/starts_with_qmark.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.string-test.starts-with-qmark 2 | (:require [clojure.string :as str] 3 | [clojure.test :as t :refer [deftest testing is are]] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists str/starts-with? 7 | (deftest test-starts-with? 8 | (is (true? (str/starts-with? "" ""))) 9 | #?(:cljs (is (false? (str/starts-with? "" nil))) 10 | :default (is (thrown? #?(:clj Exception) (str/starts-with? "" nil)))) 11 | (is (thrown? #?(:cljs :default :clj Exception) (str/starts-with? nil ""))) 12 | #?(:cljs (do (is (false? (str/starts-with? "ab" :a))) 13 | (is (true? (str/starts-with? ":ab" :a))) 14 | (is (false? (str/starts-with? "ab" :b)))) 15 | :default (is (thrown? #?(:clj Exception) (str/starts-with? "ab" :a)))) 16 | #?(:cljs (is (true? (str/starts-with? "ab" 'a))) 17 | :default (is (thrown? #?(:clj Exception) (str/starts-with? "a" 'a)))) 18 | (is (false? (str/starts-with? "" "a"))) 19 | (is (true? (str/starts-with? "a-test" ""))) 20 | (is (true? (str/starts-with? "֎a-test" "֎"))) 21 | (is (true? (str/starts-with? "a-test" "a"))) 22 | (is (true? (str/starts-with? "a-test" "a-test"))) 23 | (is (false? (str/starts-with? "a-test" "-"))) 24 | (is (false? (str/starts-with? "a-test" "t"))) 25 | #?(:cljs (is (thrown? :default (str/starts-with? 'ab ":a"))) 26 | :default (do (is (false? (str/starts-with? 'ab "b"))) 27 | (is (true? (str/starts-with? 'ab "a"))))) 28 | #?(:cljs (is (thrown? :default (str/starts-with? :ab ":a"))) 29 | :default (do (is (false? (str/starts-with? :ab "b"))) 30 | (is (false? (str/starts-with? :ab "a"))) 31 | (is (true? (str/starts-with? :ab ":a"))))) 32 | #?(:cljs (is (thrown? :default (str/starts-with? 'a/b ":a"))) 33 | :default (do (is (false? (str/starts-with? 'a/b "b"))) 34 | (is (true? (str/starts-with? 'a/b "a"))))) 35 | #?(:cljs (is (thrown? :default (str/starts-with? :a/b ":a"))) 36 | :default (do (is (false? (str/starts-with? :a/b "b"))) 37 | (is (false? (str/starts-with? :a/b "a"))) 38 | (is (true? (str/starts-with? :a/b ":a"))))))) 39 | -------------------------------------------------------------------------------- /test/clojure/string_test/upper_case.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.string-test.upper-case 2 | (:require [clojure.string :as str] 3 | [clojure.test :as t :refer [deftest testing is are]] 4 | [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) 5 | 6 | (when-var-exists str/upper-case 7 | (deftest test-upper-case 8 | (is (thrown? #?(:cljs :default :clj Exception) (str/upper-case nil))) 9 | (is (= "" (str/upper-case ""))) 10 | (is (= "֎" (str/upper-case "֎"))) 11 | (is (= "ASDF" (str/upper-case "aSDf"))) 12 | (is (= "ASDF" (str/upper-case "ASDF"))) 13 | (let [s "asdf"] 14 | (is (= "ASDF" (str/upper-case "asdf"))) 15 | (is (= "asdf" s) "original string mutated")) 16 | #?(:cljs (is (thrown? :default (str/upper-case :asdf))) 17 | :default (is (= ":ASDF" (str/upper-case :asdf)))) 18 | #?(:cljs (is (thrown? :default (str/upper-case :asdf/asdf))) 19 | :default (is (= ":ASDF/ASDF" (str/upper-case :asdf/asdf)))) 20 | #?(:cljs (is (thrown? :default (str/upper-case 'asdf))) 21 | :default (is (= "ASDF" (str/upper-case 'asdf)))) 22 | #?(:cljs (is (thrown? :default (str/upper-case 'asdf/asdf))) 23 | :default (is (= "ASDF/ASDF" (str/upper-case 'asdf/asdf)))))) 24 | --------------------------------------------------------------------------------