kahl

R⁷RS Scheme parser combinator library for decoding BARE messages

git clone https://git.8pit.net/kahl.git

 1#!/usr/bin/env chibi-scheme
 2
 3(import (scheme base) (kahl) (chibi test))
 4
 5(define (%test-parse parser bv)
 6  (define (parse-with-error parser stream)
 7    (call-with-parse parser stream 0
 8                     (lambda (r s i fk) r)
 9                     (lambda (s i reason) (error reason))))
10
11  (let* ((stream (bytevector->parse-stream bv))
12         (result (parse-with-error parser stream)))
13    result))
14
15(define (test-parse expected parser bv)
16  (test expected (%test-parse parser bv)))
17
18(define (test-parse-error expected parser bv)
19  (let ((r (call-with-current-continuation
20             (lambda (k)
21               (with-exception-handler
22                 (lambda (e) (k e))
23                 (lambda ( ) (k (%test-parse parser bv))))))))
24    (test expected
25      (if (error-object? r)
26        (error-object-message r))))) ;; (not (error-object? r)) → undefined
27
28(test-group "Primitive Types"
29  (include "tests/primitive.scm"))
30(test-group "Aggregate Types"
31  (include "tests/aggregated.scm"))
32(test-group "Integration Tests"
33  (include "tests/integration.scm"))