~technomancy/fnlfmt

4f933d02891c0d74299d39b125369853386eb013 — Phil Hagelberg 9 months ago 7e09bb0
Test cases are just single files now, not pairs.
9 files changed, 28 insertions(+), 57 deletions(-)

M test.fnl
M tests/body.fnl
D tests/call-fixed.fnl
M tests/call.fnl
D tests/misc-fixed.fnl
D tests/table-fixed.fnl
M tests/table.fnl
D tests/top-fixed.fnl
M tests/top.fnl
M test.fnl => test.fnl +4 -5
@@ 20,12 20,11 @@
  (print actual))

(each [_ name (ipairs cases)]
  (let [before (read (.. "tests/" name ".fnl"))
        after (read (.. "tests/" name "-fixed.fnl"))
        actual (.. (fmt.fmt before) "\n")]
    (if (= actual after)
  (let [expected (read (.. "tests/" name ".fnl"))
        actual (.. (fmt.fmt expected) "\n")]
    (if (= actual expected)
        (set pass (+ pass 1))
        (failed after actual))))
        (failed expected actual))))

(print (: "%s passed, %s failed" :format pass fail))
(os.exit fail)

M tests/body.fnl => tests/body.fnl +8 -8
@@ 1,14 1,14 @@
(when true
(print "you can't handle the truth!")
     (os.exit 1))
  (print "you can't handle the truth!")
  (os.exit 1))

;; what

(fn abc []
  (do (set fail (+ fail 1))
          (print "FAIL")
   ;; hey
          (print "Expected:")
          (print after)
          (print "Got:")
          (print actual)))
    (print "FAIL")
    ;; hey
    (print "Expected:")
    (print after)
    (print "Got:")
    (print actual)))

D tests/call-fixed.fnl => tests/call-fixed.fnl +0 -11
@@ 1,11 0,0 @@
(call tbl
      :a
      (print :b)
      :c)

(table.concat []
              " ")

(call (call 1

            2))

M tests/call.fnl => tests/call.fnl +6 -6
@@ 1,11 1,11 @@
(call tbl
:a
  (print :b)
     :c)
      :a
      (print :b)
      :c)

(table.concat []
          " ")
              " ")

  (call (call 1
(call (call 1

          2))
            2))

D tests/misc-fixed.fnl => tests/misc-fixed.fnl +0 -16
@@ 1,16 0,0 @@
;; this example comes from fennelview

(fn one-line [str]
  ;; save return value as local to ignore gsub's extra return value
  (let [ret (-> str
                (: :gsub "\n" " ")
                (: :gsub "%[ " "[") (: :gsub " %]" "]")
                (: :gsub "%{ " "{") (: :gsub " %}" "}")
                (: :gsub "%( " "(") (: :gsub " %)" ")"))]
    ret))

;; this )comment has a ( in it!
xyz

(let [what-is "a\"quoted string"]
  this-is-weird)

D tests/table-fixed.fnl => tests/table-fixed.fnl +0 -5
@@ 1,5 0,0 @@
(local t {:a 1
          :b.5 1.5
          :b [2 3
              4 "("
              4]})

M tests/table.fnl => tests/table.fnl +4 -4
@@ 1,5 1,5 @@
(local t {:a 1
            :b.5 1.5
:b [2 3
  4 "("
    4]})
          :b.5 1.5
          :b [2 3
              4 "("
              4]})

D tests/top-fixed.fnl => tests/top-fixed.fnl +0 -1
@@ 1,1 0,0 @@
(local hello 12)

M tests/top.fnl => tests/top.fnl +6 -1
@@ 1,1 1,6 @@
   (local hello 12)
(local hello 12)

(print "this string
has many
lines"
       "in it")