summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFelipe Garcia <felipefegar@gmail.com>2020-10-10 14:28:31 -0300
committerDavid Peter <sharkdp@users.noreply.github.com>2020-10-11 09:48:06 +0200
commit46004001cb366a8a3f06df882eb1ce015148b1c6 (patch)
tree2d2ed789494d8d222766678af2f57e2d15900ecb /tests
parentf10c8ce25ea6ee40c587a4d0e1527f4846880058 (diff)
Add Clojure syntax test.
Diffstat (limited to 'tests')
-rw-r--r--tests/syntax-tests/highlighted/Clojure/test.clj58
-rw-r--r--tests/syntax-tests/source/Clojure/test.clj58
2 files changed, 116 insertions, 0 deletions
diff --git a/tests/syntax-tests/highlighted/Clojure/test.clj b/tests/syntax-tests/highlighted/Clojure/test.clj
new file mode 100644
index 00000000..32903fe7
--- /dev/null
+++ b/tests/syntax-tests/highlighted/Clojure/test.clj
@@ -0,0 +1,58 @@
+(ns clojure-sample.core
+ (:gen-class))
+ 
+ (require '[clj-time.core :as t])
+ (require '[clj-time.format :as f])
+ 
+ ;; Product record
+ (defrecord Product [id name available price])
+ 
+ ;; Positional constructor
+ (def product1 (->Product "1" "T-Shirt 1" true 15.00))
+ 
+ ;; Map constructor
+ (def product2 (map->Product
+ {:id "2"
+ :name "T-Shirt 2"
+ :available true
+ :price 20.00}))
+ 
+ ;; Nested
+ (def product3 {:id "1"
+ :name "Product 1"
+ :available true
+ :sellers [{:id "1"
+ :name "Seller 1"
+ :stock 3},
+ {:id 2
+ :name "Seller 2"
+ :stock 5}]})
+ 
+ ;; Set
+ (def categories #{"shirts" "shoes" "belts"})
+ 
+ ;; List
+ (def wishlist '(1 2))
+ 
+ ;; Recursion
+ (defn factorial [value] (cond
+ (<= value 1) 1
+ :else (* value (factorial (- value 1)))))
+ 
+ (def basic-formatter (f/formatter "YYYY-MM-dd hh:mm:ss"))
+ (defn now [] (f/unparse basic-formatter (t/now)))
+ (defn log
+ ([] (println (now) "No message"))
+ ([message] (println (now) message)))
+ 
+ (defn -main
+ [& args]
+ (println (:id product1))
+ (println (:name product2))
+ (println (:name (get (:sellers product3) 0)))
+ (println (first categories))
+ (println wishlist)
+ (println (factorial 5))
+ (log)
+ (log "Message"))
+ 
diff --git a/tests/syntax-tests/source/Clojure/test.clj b/tests/syntax-tests/source/Clojure/test.clj
new file mode 100644
index 00000000..ea24e822
--- /dev/null
+++ b/tests/syntax-tests/source/Clojure/test.clj
@@ -0,0 +1,58 @@
+(ns clojure-sample.core
+ (:gen-class))
+
+ (require '[clj-time.core :as t])
+ (require '[clj-time.format :as f])
+
+ ;; Product record
+ (defrecord Product [id name available price])
+
+ ;; Positional constructor
+ (def product1 (->Product "1" "T-Shirt 1" true 15.00))
+
+ ;; Map constructor
+ (def product2 (map->Product
+ {:id "2"
+ :name "T-Shirt 2"
+ :available true
+ :price 20.00}))
+
+ ;; Nested
+ (def product3 {:id "1"
+ :name "Product 1"
+ :available true
+ :sellers [{:id "1"
+ :name "Seller 1"
+ :stock 3},
+ {:id 2
+ :name "Seller 2"
+ :stock 5}]})
+
+ ;; Set
+ (def categories #{"shirts" "shoes" "belts"})
+
+ ;; List
+ (def wishlist '(1 2))
+
+ ;; Recursion
+ (defn factorial [value] (cond
+ (<= value 1) 1
+ :else (* value (factorial (- value 1)))))
+
+ (def basic-formatter (f/formatter "YYYY-MM-dd hh:mm:ss"))
+ (defn now [] (f/unparse basic-formatter (t/now)))
+ (defn log
+ ([] (println (now) "No message"))
+ ([message] (println (now) message)))
+
+ (defn -main
+ [& args]
+ (println (:id product1))
+ (println (:name product2))
+ (println (:name (get (:sellers product3) 0)))
+ (println (first categories))
+ (println wishlist)
+ (println (factorial 5))
+ (log)
+ (log "Message"))
+ \ No newline at end of file