Login
7 branches 0 tags
Ben (X13/Arch) Removed test of :mode result for [file/stat] call 37b8c17 3 years ago 782 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] [> [string/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]