summaryrefslogtreecommitdiff
path: root/tests/parse.scm
blob: 28707a0c6ad056ae42ddb30f99288f1f647f3a7e (plain)
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
(import (chibi)
        (chibi test)
        (chibi parse)
        (cook  debug)
        (cook  parse-internals))

(test-group "Amount"
  (test "with unit"
        (list 'amount 10 "l") (cook->list (parse amount "10%l")))
  (test "without unit"
        (list 'amount 10 #f)  (cook->list (parse amount "10"))))

(test-group "Quantity"
  (test "integer"  10   (parse quantity "10"))
  (test "float"    10.1 (parse quantity "10.1"))
  (test "fraction" 1/10 (parse quantity "1/10")))

;(define (test x y)
;  (display "Testing: ")
;  (display x)
;  (display " == ")
;  (display (cook->list y))
;  (newline))

;(test 'NEWLINE    (parse nl "\n\r\r\n"))
;(test 'WHITESPACE (parse whitespace "  \t    aaaa aaa    "))
;(test 'COMMENT    (parse comment "-- aasf ljalsfkjalsfdjalsfd\n"))
;
;(test 'BLOCK-COMMENT  ;; TODO: Check greediness
;      (parse comment "[- aasfjal sfkjalsfdjalsfd\nashfajsdf\nsdfasf-]"))
;
;(test 'WORD                     (parse word "hola. adios"))
;(test 'UNIT                     (parse unit "l"))
;(test 'WORD-COMPONENT           (parse-fully component "word{}"))
;(test 'WORD-COMPONENT           (parse-fully component "word{9%head}"))
;(test 'WORD-COMPONENT           (parse-fully component "word"))
;(test 'MULTI-WORD-COMPONENT     (parse-fully component "un multi word{}"))
;(test 'MULTI-WORD-COMPONENT     (parse-fully component "un multi word{10}"))
;(test 'MULTI-WORD-COMPONENT     (parse-fully component "un multi word{10%l}"))
;(test 'MULTI-WORD-COMPONENT     (parse-fully component "un multi word{80%mm}"))
;(test 'NO-NAME-TIMER            (parse-fully timer "~{}"))
;(test 'MULTI-WORD-TIMER         (parse-fully timer "~un multi word{10}"))
;(test 'MULTI-WORD-TIMER         (parse-fully timer "~un multi word{10%l}"))
;(test 'MULTI-WORD-TIMER         (parse-fully timer "~un multi word{80%mm}"))
;(test 'NO-NAME-TIMER            (parse-fully timer "~{12%min}"))
;(test 'INGREDIENT               (parse-fully ingredient "@potato{12%kg}"))
;(test 'STEP                     (parse-fully step   "un poco de texto seguido de ~un multi word{10}"))
;(test 'RECIPE                   (parse recipe "this is a recipe with @coconut{1}\nAnd takes ~{2%min}\n"))
;(test 'RECIPE                   (parse recipe ">> some: metadata\nthis is a recipe with @coconut{1}\nAnd takes ~{2%min}\n"))