tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

consumer_count_lines_compact.tri (1758B)


      1 -- Source, reference, lexical and lambda agree on compact line counts.
      2 !import "prelude" !Local
      3 !import "io" !Local
      4 !import "consumers.base-source" B
      5 !import "consumers.structural" S
      6 !import "consumers.lexical-worker" X
      7 !import "consumers.comparison.text-summary-lambda" L
      8 load path = do onOk_
      9   source <- readFile path
     10   pure (B.compileBaseSource source)
     11 rules named = snd (snd named)
     12 configure named initial = S.makeConsumer initial (rules named)
     13 check ref compiled bytes = (and?
     14   (equal? (S.runConsumer ref bytes) (ok (L.countBytes bytes) t))
     15   (equal? (X.lRunChecked compiled bytes) (S.runConsumer ref bytes)))
     16 eight = "\n\n\n\n\n\n\n\n"
     17 sixteen = append eight eight
     18 thirtyTwo = append sixteen sixteen
     19 sixtyFour = append thirtyTwo thirtyTwo
     20 probes ref compiled = (foldl and? true (map (check ref compiled)
     21   ["" "a" "a\n" "\n" "a\n\n" "a\nb" "a\r\nb\r\n" "x\ny\nz\n" "x\ny\nz"
     22    eight sixteen thirtyTwo sixtyFour]))
     23 run = do onOk_
     24   namedSucc <- load "lib/consumer/succ.scp"
     25   compiledSucc <- pure (X.lCompile (configure namedSucc t))
     26   namedCount <- load "lib/consumer/text/countLines.scp"
     27   compiledCount <- pure (X.lCompile (configure namedCount
     28     (pair 0 (pair t compiledSucc))))
     29   brokenCount <- pure (X.lCompile (configure namedCount
     30     (pair 0 (pair t t))))
     31   pure (ok (foldl and? true [
     32     (probes (configure namedCount
     33       (pair 0 (pair t (configure namedSucc t)))) compiledCount)
     34     (equal? (X.lRunChecked brokenCount "") (ok 0 t))
     35     (equal? (X.lRunChecked brokenCount "x") (err "invalid SCP worker" t))
     36     (equal? (X.lRunChecked brokenCount "\n") (err "invalid SCP worker" t))]) t)
     37 main = io (onResult_ run (_ : putStrLn "compact-count-ERROR")
     38   (passed : putStrLn (matchBool "compact-count-ok" "compact-count-DIFF" passed)))
     39 main