on master help sign in
Add Clojure syntax test.
commit46004001cb366a8a3f06df882eb1ce015148b1c6 authorFelipe Garcia <felipefegar@gmail.com> dateSat 10 Oct 2020, 14:28 (6 years ago) parentf10c8ce
2 files changed+116
tests/syntax-tests/highlighted/Clojure/test.clj+58 tests/syntax-tests/source/Clojure/test.clj+58
tests/syntax-tests/highlighted/Clojure/test.cljnew file+58
@@ -0,0 +1,58 @@
1+(ns clojure-sample.core
2+ (:gen-class))
3+ 
4+ (require '[clj-time.core :as t])
5+ (require '[clj-time.format :as f])
6+ 
7+ ;; Product record
8+ (defrecord Product [id name available price])
9+ 
10+ ;; Positional constructor
11+ (def product1 (->Product "1" "T-Shirt 1" true 15.00))
12+ 
13+ ;; Map constructor
14+ (def product2 (map->Product
15+ {:id "2"
16+ :name "T-Shirt 2"
17+ :available true
18+ :price 20.00}))
19+ 
20+ ;; Nested
21+ (def product3 {:id "1"
22+ :name "Product 1"
23+ :available true
24+ :sellers [{:id "1"
25+ :name "Seller 1"
26+ :stock 3},
27+ {:id 2
28+ :name "Seller 2"
29+ :stock 5}]})
30+ 
31+ ;; Set
32+ (def categories #{"shirts" "shoes" "belts"})
33+ 
34+ ;; List
35+ (def wishlist '(1 2))
36+ 
37+ ;; Recursion
38+ (defn factorial [value] (cond
39+ (<= value 1) 1
40+ :else (* value (factorial (- value 1)))))
41+ 
42+ (def basic-formatter (f/formatter "YYYY-MM-dd hh:mm:ss"))
43+ (defn now [] (f/unparse basic-formatter (t/now)))
44+ (defn log
45+ ([] (println (now) "No message"))
46+ ([message] (println (now) message)))
47+ 
48+ (defn -main
49+ [& args]
50+ (println (:id product1))
51+ (println (:name product2))
52+ (println (:name (get (:sellers product3) 0)))
53+ (println (first categories))
54+ (println wishlist)
55+ (println (factorial 5))
56+ (log)
57+ (log "Message"))
58+ 
tests/syntax-tests/source/Clojure/test.cljnew file+58
@@ -0,0 +1,58 @@
1+(ns clojure-sample.core
2+ (:gen-class))
3+
4+ (require '[clj-time.core :as t])
5+ (require '[clj-time.format :as f])
6+
7+ ;; Product record
8+ (defrecord Product [id name available price])
9+
10+ ;; Positional constructor
11+ (def product1 (->Product "1" "T-Shirt 1" true 15.00))
12+
13+ ;; Map constructor
14+ (def product2 (map->Product
15+ {:id "2"
16+ :name "T-Shirt 2"
17+ :available true
18+ :price 20.00}))
19+
20+ ;; Nested
21+ (def product3 {:id "1"
22+ :name "Product 1"
23+ :available true
24+ :sellers [{:id "1"
25+ :name "Seller 1"
26+ :stock 3},
27+ {:id 2
28+ :name "Seller 2"
29+ :stock 5}]})
30+
31+ ;; Set
32+ (def categories #{"shirts" "shoes" "belts"})
33+
34+ ;; List
35+ (def wishlist '(1 2))
36+
37+ ;; Recursion
38+ (defn factorial [value] (cond
39+ (<= value 1) 1
40+ :else (* value (factorial (- value 1)))))
41+
42+ (def basic-formatter (f/formatter "YYYY-MM-dd hh:mm:ss"))
43+ (defn now [] (f/unparse basic-formatter (t/now)))
44+ (defn log
45+ ([] (println (now) "No message"))
46+ ([message] (println (now) message)))
47+
48+ (defn -main
49+ [& args]
50+ (println (:id product1))
51+ (println (:name product2))
52+ (println (:name (get (:sellers product3) 0)))
53+ (println (first categories))
54+ (println wishlist)
55+ (println (factorial 5))
56+ (log)
57+ (log "Message"))
58+