(syntree-children=? (cdr ch1) (cdr ch2))))))
(define-record charport port line column)
-(define (charport port) (make-charport port 0 0))
+(define (charport port) (make-charport port 1 1))
(define (charport-read chprt)
(define ch (read-char (charport-port chprt)))
(if (char=? ch #\newline)
(begin
(charport-line-set! chprt (+ 1 (charport-line chprt)))
- (charport-column-set! chprt 0))
+ (charport-column-set! chprt 1))
(charport-column-set! chprt (+ 1 (charport-column chprt))))
ch)
(define unit-tests '())
(define (register-test! test)
- (set! unit-tests (append unit-tests (list test))))
+ (set! unit-tests (cons test unit-tests)))
(define (print-summary pass fail)
(if (zero? fail)
(list (syntree 'foo "" '()))
(list (syntree 'bar "" '())))))
+; charport
+;------------------------------------------------------------------------------
+(def-test "charport should initialize a charport properly"
+ (call-with-input-string "a"
+ (lambda (input)
+ (define port (charport input))
+ (and (equal? input (charport-port port))
+ (equal? 1 (charport-line port))
+ (equal? 1 (charport-column port))))))
+
+; charport-read
+;------------------------------------------------------------------------------
+(def-test "charport-read should increment column when character is not newline"
+ (call-with-input-string "a"
+ (lambda (input)
+ (define port (charport input))
+ (and (equal? #\a (charport-read port))
+ (equal? 1 (charport-line port))
+ (equal? 2 (charport-column port))))))
+
+(def-test "charport-read should increment line when character is newline"
+ (call-with-input-string "\n"
+ (lambda (input)
+ (define port (charport input))
+ (and (equal? #\newline (charport-read port))
+ (equal? 2 (charport-line port))
+ (equal? 1 (charport-column port))))))
+
; char-match
;------------------------------------------------------------------------------
(def-test "char-match should consume and return char if the next char matches"