*.lib
*~
*.d
-
+test_runner*
SRC_OBJS = $(SRC_FILES:%.$(SRC_EXT)=%.o)
TEST_OBJS = $(TEST_FILES:%.$(TEST_EXT)=%.o)
+# Include Directories
+SRC_INCS =
+TEST_INCS = -I inc
+
# Compiler and Linker Options
#----------------------------
CSC = csc
$(TEST_OBJS): %.o : %.$(TEST_EXT)
@echo $<
- @$(CSC) $(CSCFLAGS) -o $@ $<
+ @$(CSC) $(CSCFLAGS) $(TEST_INCS) -o $@ $<
# Cleanup
clean:
--- /dev/null
+(declare (unit loops))
+
+; For loop macro
+(define-syntax for
+ (syntax-rules ()
+ ((_ var lst body ...)
+ (let loop ((var (car lst)))
+ body ...
+ (if (< var (cadr lst))
+ (loop (+ var (caddr lst))))))))
+
+; While loop macro
+(define-syntax while
+ (syntax-rules ()
+ ((_ cnd body ...)
+ (let loop ()
+ body ...
+ (if cnd (loop))))))
+
+; Until loop macro
+(define-syntax until
+ (syntax-rules ()
+ ((_ cnd body ...)
+ (let loop ()
+ body ...
+ (if (not cnd) (loop))))))
+
--- /dev/null
+
+(define-syntax def-test
+ (syntax-rules ()
+ ((_ desc body ...)
+ (register-test!
+ (cons desc
+ (lambda () body ...))))))
+
(vector? (buf-data obj))))
(define (buf-marked? b)
- (if (buf? b)
- (> (length (buf-marks b)) 0)))
+ (> (length (buf-marks b)) 0))
-(define (buf-mark b)
- (if (buf? b)
- (buf-marks-set! b (cons (buf-pos b) (buf-marks b)))))
+(define (buf-mark! b)
+ (buf-marks-set! b (cons (buf-pos b) (buf-marks b))))
-(define (buf-release b)
- (if (buf? b)
- (buf-marks-set! b (cdr (buf-marks b)))))
+(define (buf-release! b)
+ (buf-marks-set! b (cdr (buf-marks b))))
-(define (buf-advance b)
- (if (buf? b)
- (buf-pos-set! b (+ 1 (buf-pos b)))))
+(define (buf-advance! b)
+ (buf-pos-set! b (+ 1 (buf-pos b))))
-(define (buf-sync b n)
- (if (buf? b)
- (let* ((pos (buf-pos b))
- (size (length (buf-data)))
- (nxt_idx (- (+ pos n) 1))
- (max_idx (- size 1)))
- (if (= size 0)
- (buf-fill b n)
- (if (>= nxt_idx max_idx)
- (buf-fill b (- nxt_idx max_idx)))))))
+(define (buf-sync! b n)
+ (let* ((pos (buf-pos b))
+ (size (length (buf-data)))
+ (nxt_idx (- (+ pos n) 1))
+ (max_idx (- size 1)))
+ (if (= size 0)
+ (buf-fill! b n)
+ (if (>= nxt_idx max_idx)
+ (buf-fill! b (- nxt_idx max_idx))))))
-(define (buf-fill b n)
- (if (buf? b)
- (let loop ((i 0))
- (buf-data-set!
- (vector-append (buf-data b) ((buf-ldfn b))))
- (if (< i n) (loop (+ i 1))))))
+(define (buf-fill! b n)
+ (let loop ((i 0))
+ (buf-data-set!
+ (vector-append (buf-data b) ((buf-ldfn b))))
+ (if (< i n) (loop (+ i 1)))))
-(define (buf-lookahead b n)
- (if (buf? b)
- (buf-sync b n)
- (vector-ref
- (buf-data b)
- (- (+ (buf-pos b) n) 1))))
+(define (buf-lookahead! b n)
+ (buf-sync b n)
+ (vector-ref
+ (buf-data b)
+ (- (+ (buf-pos b) n) 1)))
-(define (buf-consume b n)
- (if (buf? b)
+(define (buf-consume! b n)
+ (buf-advance! b)
+ (if
+ (and
+ (= (buf-pos b) (length (buf-data b)))
+ (not (buf-marked? b)))
(begin
- (buf-advance b)
- (if
- (and
- (= location size)
- (not (buf-marked? b)))
- (begin
- (buf-pos-set! 0)
- (buf-data-set! (vector))))
- (buf-sync b1))))
+ (buf-pos-set! 0)
+ (buf-data-set! (vector))))
+ (buf-sync! b1))
(declare
(uses library)
- (uses test_foo))
+ (uses test_buf)
+ (uses test))
-;(run-unit-tests)
+(run-all-unit-tests)
--- /dev/null
+(declare (unit test)
+ (compile-syntax))
+
+(define unit-tests '())
+
+(define (register-test! test)
+ (set! unit-tests (append unit-tests (list test))))
+
+(define (print-summary pass fail)
+ (if (zero? fail)
+ (print "Success: " pass " tests passed.")
+ (print "Failure: " fail " / " (+ pass fail) " tests failed.")))
+
+(define (run-all-unit-tests)
+ (let loop ((pass 0)
+ (fail 0)
+ (tests unit-tests))
+ (if (not (null? tests))
+ (let* ((test (car tests))
+ (desc (car test))
+ (fn (cdr test)))
+ (if (not (fn))
+ (begin
+ (print "FAIL: " desc)
+ (loop pass (+ fail 1) (cdr tests)))
+ (loop (+ pass 1) fail (cdr tests))))
+ (print-summary pass fail))))
+
--- /dev/null
+(include "test.scm")
+(declare (unit test_buf)
+ (uses test))
+
+; buf
+;------------------------------------------------------------------------------
+(def-test "buf should create a new general purpose buffer" '())
+
+; buf-struct?
+;------------------------------------------------------------------------------
+(def-test "buf-struct? should return true if passed a buffer struct" '())
+(def-test "buf-struct? should return fals if not a buffer struct" '())
+
+; buf?
+;------------------------------------------------------------------------------
+(def-test "buf? should return true if passed a buffer struct with the right elements" '())
+(def-test "buf? should return false if no load function" '())
+(def-test "buf? should return false if pos is not an integer" '())
+(def-test "buf? should return false if marks is not a list" '())
+(def-test "buf? should return false if data is not a vector" '())
+
+; buf-marked?
+;------------------------------------------------------------------------------
+(def-test "buf-marked? should return true if the buffer is marked" '())
+(def-test "buf-marked? should return false if the buffer is NOT marked" '())
+
+; buf-mark!
+;------------------------------------------------------------------------------
+(def-test "buf-mark! should store the current pos in the marks list when the marks list is empty" '())
+(def-test "buf-mark! should prepend the current pos to the marks list" '())
+
+; buf-release!
+;------------------------------------------------------------------------------
+(def-test "buf-release! should remove the current mark from the marks list when only one mark exists" '())
+(def-test "buf-release! should remove the current mark from the marks list when multiple marks exist" '())
+
+; buf-advance!
+;------------------------------------------------------------------------------
+(def-test "buf-advance! should advance pos by 1" '())
+
+; buf-sync!
+;------------------------------------------------------------------------------
+(def-test "buf-sync! should fill the buffer with the specified number of bytes when the buffer is empty" '())
+(def-test "buf-sync! should fill the buffer up to n when the buffer contains less data than required" '())
+(def-test "buf-sync! should do nothing if already synced" '())
+
+; buf-fill!
+;------------------------------------------------------------------------------
+(def-test "buf-fill! should load 0 bytes from the source" '())
+(def-test "buf-fill! should load 1 bytes from the source" '())
+(def-test "buf-fill! should load 2 bytes from the source" '())
+(def-test "buf-fill! should load 3 bytes from the source" '())
+
+; buf-lookahead!
+;------------------------------------------------------------------------------
+(def-test "buf-lookahead! should return the first item of lookahead" '())
+(def-test "buf-lookahead! should return the second item of lookahead" '())
+(def-test "buf-lookahead! should return the third item of lookahead" '())
+
+; buf-consume!
+;------------------------------------------------------------------------------
+(def-test "buf-consume! should clear the buffer if not marked and pos is equal to the buffer size" '())
+(def-test "buf-consume! should NOT clear the buffer if pos not equal to the buffer size" '())
+(def-test "buf-consume! should NOT clear the buffer if the buffer is marked" '())
+
+++ /dev/null
-(declare (unit test_foo))
-
-;(test-suite "Foo unit tests"
-; (test "Foo does cool stuff"
-; (check-equal 42 (foo 1 2)) ))
-
-(print "Hello, world!")
-