~subsetpark/bagatto

ref: bf3c03db9dcce2cfb24e5ecc95d8c424961f889c bagatto/test/bagatto.janet -rw-r--r-- 1.5 KiB
bf3c03db — Zach Smith Spork deps 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
49
50
51
(import testament :prefix "" :exit true)
(import spork/temple)

(import /bagatto)

(temple/add-loader)

(deftest jdn-data
  (is (== {:foo "bar"} (bagatto/jdn-data "{:foo \"bar\"}"))))

(deftest json-data
  (is (== {"foo" "bar"} (bagatto/json-data "{\"foo\": \"bar\"}"))))

(deftest *
  (let [loader (bagatto/* "test/support/*.txt")]
    (is (== {:each @["test/support/test.txt"]} (loader)))))

(deftest slurp-*
  (let [loader (bagatto/slurp-* "test/support/*.txt")]
    (is (== {:each @[["test/support/test.txt" @"test file contents\n"]]} (loader)))))

(deftest render
  (is (== @"2\n" (bagatto/render "/test/support/test" {}))))

(def unslug " Make A_Slug ")

(deftest slugify
  (is (== "make-a-slug" (bagatto/slugify unslug))))

(deftest slug-from-attr
  (is (== "make-a-slug" (bagatto/slug-from-attr {:title unslug} :title))))

(deftest renderer
  (let [renderer (bagatto/renderer "/test/support/test")]
    (is (== @"2\n" (renderer {})))))

(deftest %p
  (def %p (bagatto/%p "site"))
  (is (== "site" (%p {:foo :bar} {:baz :quux})))
  (def %p-site (bagatto/%p "site" '%s :root))
  (is (== "site/bag" (%p-site {:root "bag"})))
  (def %p-item (bagatto/%p "site" '%i :title))
  (is (== "site/post" (%p-item {:root "bag"} {:title "post"})))
  (def %p-join (bagatto/%p "site" '%i :title '% ".html"))
  (is (== "site/post.html" (%p-join {:join "bag"} {:title "post"}))))

(deftest path-copier
  (let [copier (bagatto/path-copier "site")]
    (is (== "site/foo.png" (copier {} {:path "baz/foo.png"})))))

(run-tests!)