Autumn Lisp Game Jam 2025

test-parser.fnl at [7a54cf9df3]
Login

test-parser.fnl at [7a54cf9df3]

File test-parser.fnl artifact 2f16386a91 part of check-in 7a54cf9df3


tonumber {}; return require("fennel").install().eval([==[

(local fennel (require :fennel))

(local {: parse} (require :parser))

(local VERBOSE false)

(local TESTS
  [
   ["hello" nil]
   ["i" [:INVENTORY]]
   ["inventory" [:INVENTORY]]
   ["take inventory" [:INVENTORY]]
   ["TAKE INVENTORY" [:INVENTORY]]
   ["look" [:LOOK]]
   ["l" [:LOOK]]
   ["ll" nil]
   ["x mush" [:EXAMINE :MUSHROOM]]
   ["look at" nil]
   ["look fungus" [:EXAMINE :MUSHROOM]]
   ["look the fungus" [:EXAMINE :MUSHROOM]]
   ["look at fungus" [:EXAMINE :MUSHROOM]]
   ["look at the fungus" [:EXAMINE :MUSHROOM]]
   ["look at mysterious fungus" [:EXAMINE :MUSHROOM]]
   ["examine mysterious fungus" [:EXAMINE :MUSHROOM]]
   ["listen" [:LISTEN]]
   ["listen to the radio" [:LISTEN :RADIO]]
   ["listen to the rapids" [:LISTEN]]
   ["listen to the sounds" [:LISTEN]]
   ["listen room" [:LISTEN]]
   ["n" [:GO :N]]
   ["e" [:GO :E]]
   ["s" [:GO :S]]
   ["w" [:GO :W]]
   ["u" [:GO :U]]
   ["d" [:GO :D]]
   ["in" [:GO :IN]]
   ["out" [:GO :OUT]]
   ["climb" [:GO :U]]
   ["climb up" [:GO :U]]
   ["climb down" [:GO :D]]
   ["ascend" [:GO :U]]
   ["descend" [:GO :D]]
   ["up ladder" [:GO :U]]
   ["down stairs" [:GO :D]]
   ["climb ladder" [:GO :U]]
   ["climb stairs" [:GO :U]]
   ["climb down stairs" [:GO :D]]
   ["climb up stairs" [:GO :U]]
   ["ascend ladder" [:GO :U]]
   ["descend stairs" [:GO :D]]
   ["east" [:GO :E]]
   ["go south" [:GO :S]]
   ["  walk w  " [:GO :W]]
   ["go d" [:GO :D]]
   ["walk to the east" [:GO :E]]
   ["to the east" nil]
   ["go up" [:GO :U]]
   ["go to the up" nil]
   ["go in" [:GO :IN]]
   ["go to the in" nil]
   ["take mushroom" [:TAKE :MUSHROOM]]
   ["take the mushroom" [:TAKE :MUSHROOM]]
   ["take the the mushroom" nil]
   ["acquire the mush" [:TAKE :MUSHROOM]]
   ["take ye cat" [:TAKE :CAT]]
   ["grab ye cat" [:TAKE :CAT]]
   ["x cat" [:EXAMINE :CAT]]
   ["x grey cat" [:EXAMINE :CAT]]
   ["x my gray cat" [:EXAMINE :CAT]]
   ["x my little gray kitty cat" [:EXAMINE :CAT]]
   ["x the little gray kitty cat" [:EXAMINE :CAT]]
   ["x kitty kat" [:EXAMINE :CAT]]
   ["x the feline" [:EXAMINE :CAT]]
   ["get" nil]
   ["get mysterious fungus" [:TAKE :MUSHROOM]]
   ["drop mush" [:DROP :MUSHROOM]]
   ["tune" [:TUNE :RADIO]]
   ["tune radio" [:TUNE :RADIO]]
   ["tune radio to" nil]
   ["tune radio to 103.5" [:TUNE :RADIO ["103.5"]]]
   ["tune radio to the dusty rock room" [:TUNE :RADIO [:dusty :rock :room]]]
   ["TUNE RADIO TO THE DUSTY ROCK ROOM" [:TUNE :RADIO [:dusty :rock :room]]]
   ["change radio" [:TUNE :RADIO]]
   ["change radio station" [:TUNE :RADIO]]
   ["change radio station to 3" [:TUNE :RADIO ["3"]]]
   ["tune mushroom" [:TUNE :MUSHROOM]]
   ["take lock" [:TAKE :BOX]]
   ["90210" [:ENTER "90210"]]
   ["9 0  21 0  " [:ENTER "90210"]]
   ["enter 90210" [:ENTER "90210"]]
   ["enter 9 0 2 1 0" [:ENTER "90210"]]
   ["type 90210" [:ENTER "90210"]]
   ["enter 90210 into" nil]
   ["enter 90210 into lock" [:ENTER "90210" :BOX]]
   ["enter 9 0 2 1 0 into lock" [:ENTER "90210" :BOX]]
   ["enter code 90210 into lock" [:ENTER "90210" :BOX]]
   ["enter code 90210 into combination lock" [:ENTER "90210" :BOX]]
   ["enter 90210 into keypad" [:ENTER "90210" :BOX]]
   ["enter code 90210 on box" [:ENTER "90210" :BOX]]
   ["open box with code 90210" [:ENTER "90210" :BOX]]
   ["open lock using 90210" [:ENTER "90210" :BOX]]
   ["open lock 90210" [:ENTER "90210" :BOX]]
   ["feed cat" [:FEED :CAT]]
   ["feed catfood to cat" [:FEED :CAT :CAT-FOOD]]
   ["feed cat food to cat" [:FEED :CAT :CAT-FOOD]]
   ["feed cat food to the cat" [:FEED :CAT :CAT-FOOD]]
   ["offer cat food to the cat" [:FEED :CAT :CAT-FOOD]]
   ["give cat food to the cat" [:FEED :CAT :CAT-FOOD]]
   ["feed cat cat food" [:FEED :CAT :CAT-FOOD]]
   ["feed my little grey cat with the cat food" [:FEED :CAT :CAT-FOOD]]
   ["feed radio to cat" [:FEED :CAT :RADIO]]
   ["feed cat to radio" [:FEED :RADIO :CAT]]
   ["feed the feisty feline" [:FEED :CAT]]
   ;; ["give cat food" [:FEED :CAT :FOOD]]
   ["pet cat" [:PET :CAT]]
   ["play with cat" [:PET :CAT]]
   ["pet the damn cat" [:PET :CAT]]
   ["knock on ye door" [:KNOCK :DOOR]]
   ["listen to the damn rapids" [:LISTEN]]
   ["quit" [:QUIT]]
   ["quit game" [:QUIT]]
   ["quit the game" [:QUIT]]
   ["vamoose" [:QUIT]]
   ["exit" [:GO :OUT]]
   ["volume" [:VOLUME]]
   ["volume 0" [:VOLUME 0]]
   ["volume 9" [:VOLUME 9]]
   ["volume 99" [:VOLUME 99]]
   ["volume up" [:VOLUME :UP]]
   ["volume down" [:VOLUME :DOWN]]
   ["help" [:HELP]]
   ["help me" [:HELP]]
   ["help please" [:HELP]]
   ["help me please" [:HELP]]
   ["debug" [:DEBUG]]
   ["debug on" [:DEBUG true]]
   ["debug no" [:DEBUG false]]
   ["debug 1 1" nil]
   ])

(lambda equal? [?a ?b]
  (case (values (type ?a) (type ?b))
    (:table :table) (and (accumulate [ok true
                                      k (pairs ?a)
                                      &until (not ok)]
                           (equal? (. ?a k) (. ?b k)))
                         (accumulate [ok true
                                      k (pairs ?b)
                                      &until (not ok)]
                           (equal? (. ?a k) (. ?b k))))
    (t t) (= ?a ?b)
    _ false))

(lambda view [?x ?options]
  (let [options (collect [k v
                          (pairs (or ?options {}))
                          &into {:one-line? true :prefer-colon? true}] ;; Default options.
                  (values k v))] ;; Override options.
    (fennel.view ?x options)))

(each [_ [line ?expected] (ipairs TESTS)]
  (let [?parsed (parse line)]
    (if VERBOSE
      (print (string.format "%s --> %s"
                            (view line {:prefer-colon? false})
                            (view ?parsed))))
    (assert (equal? ?parsed ?expected)
            (string.format "%s --> %s, expected %s"
                           (view line {:prefer-colon? false})
                           (view ?parsed)
                           (view ?expected)))))

; ]==], {}, ...)