Login
7 branches 0 tags
Ben (X13/Arch) Simplified things a little 0643405 9 days ago 1260 Commits
nujel / tests / fast / word-count.nuj
#!/usr/bin/env nujel
;; Simple test program that should give the same result as `wc -l` or `wc -w`

(defn count-lines (filename)
       (def text (:string (file/read filename)))
       (- (count (split text "\n")) 1))

(defn count-words (filename)
       (def text (:string (file/read filename)))
       (-> text
           (split "\n")
           (reduce (fn (a b)
                       (+ a (count (split b " ") (fn (a) (> (:length (trim a)) 0)))))
                   0)))

(def lines (count-lines "CODE_OF_CONDUCT.md"))
(when (not= lines 136)
      (throw (list :wrong-result "CoC Lines Wrong" lines)))
(def words (count-words "CODE_OF_CONDUCT.md"))
(when (not= words 717)
      (throw (list :wrong-result "CoC Words Wrong" words)))
(def llines (count-lines "LICENSE"))
(when (not= llines 19)
      (throw (list :wrong-result "LICENSE Lines Wrong" llines)))
(def lwords (count-words "LICENSE"))
(when (not= lwords 168)
      (throw (list :wrong-result "LICENSE Words Wrong" lwords)))

(return :success)