-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
;;; filet-test.lisp | ||
;;; Copyright (c) Thayne McCombs | ||
|
||
(defpackage liter/file-test | ||
(:use :cl :prove :liter)) | ||
|
||
(in-package liter/file-test) | ||
|
||
(defparameter *file-path* (asdf:component-pathname | ||
(asdf:find-component :colliflower-test | ||
'("liter" "test.txt")))) | ||
(defparameter *content-bytes* | ||
'(102 105 114 115 116 10 115 101 99 111 110 100 10 116 104 105 114 100 10)) | ||
|
||
(defparameter *content-characters* (coerce "first | ||
second | ||
third | ||
" 'list)) | ||
|
||
(plan nil) | ||
|
||
(subtest "character" | ||
(with-file-iterator (it *file-path* :element-type 'character) | ||
(is (iterator-list it) | ||
*content-characters* | ||
:test #'equalp | ||
"Read the fle as characters")) | ||
(let* ((f (make-file-iterator *file-path*)) | ||
(it (get-iterator f))) | ||
(is (iter-object-next f) #\f) | ||
(is (iter-object-next f) #\i) | ||
(is (funcall it) #\r) | ||
(is (inext it) #\s) | ||
(is (inext it) #\t) | ||
(is (inext it) #\newline) | ||
(is (coerce (iterator-list it) 'string) | ||
"second | ||
third | ||
" "Iterator should match rest of string.") | ||
(ok (iter-object-end-p f) "Iterator should be ended."))) | ||
|
||
|
||
(subtest "bytes" | ||
(with-file-iterator (it *file-path* :element-type '(unsigned-byte 8)) | ||
(is (iterator-list it) *content-bytes* "Read the file as bytes"))) | ||
|
||
(subtest "lines" | ||
(with-file-iterator (it *file-path* :reader #'read-line) | ||
(is (iterator-list it) '("first" "second" "third") "Read the file as lines"))) | ||
|
||
(finalize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
;;; iter-object-test.lips | ||
;;; Copyright (c) 2015 Thayne McCombs | ||
|
||
(defpackage liter/iter-object-test | ||
(:use :cl :prove :liter) | ||
#+closer-mop | ||
(:import-from :closer-mop | ||
#:funcallable-standard-class)) | ||
|
||
(in-package :liter/iter-object-test) | ||
|
||
(plan nil) | ||
|
||
(defclass test-iterator (iter-object) | ||
((val :initform 0 :accessor test-iterator-value)) | ||
#+closer-mop | ||
(:metaclass funcallable-standard-class)) | ||
|
||
(defmethod iter-object-next ((obj test-iterator) &rest args) | ||
(declare (ignore args)) | ||
(incf (test-iterator-value obj))) | ||
|
||
(defmethod iter-object-prev ((obj test-iterator) &rest args) | ||
(declare (ignore args)) | ||
(decf (test-iterator-value obj))) | ||
|
||
(defmethod iter-object-end-p ((obj test-iterator)) | ||
nil) | ||
|
||
#+closer-mop | ||
(subtest "funcall test-iterator" | ||
(diag "with closer-mop enabled") | ||
(let ((it (make-instance 'test-iterator))) | ||
(is (funcall it) 1) | ||
(is (inext it) 2) | ||
(is (get-iterator it) it :test #'eq "GET-ITERATOR should act as identity function."))) | ||
|
||
(let* ((test-it (make-instance 'test-iterator)) | ||
(it (get-iterator test-it))) | ||
(is (iter-object-next test-it) 1) | ||
(is (funcall it) 2) | ||
(is (iter-object-prev test-it) 1) | ||
(is (iter-object-prev test-it) 0)) | ||
|
||
(finalize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
first | ||
second | ||
third |