Skip to content

Instantly share code, notes, and snippets.

@sgithens
Created September 17, 2022 17:37
Show Gist options
  • Save sgithens/fc68d92af5bd0cea6e0e0f552ba7128b to your computer and use it in GitHub Desktop.
Save sgithens/fc68d92af5bd0cea6e0e0f552ba7128b to your computer and use it in GitHub Desktop.
initial tests for .boxer file format
;; Basic test of creating a box structure, saving it, re-opening it, and verifying a few bits
(let* ((boxer::*supress-graphics-recording?* t)
(boxer::*draw-status-line* nil)
(current-time (simple-name-timestamp))
(new-tests-dir (cl-fad:merge-pathnames-as-directory cl-user::*boxer-project-dir*
(format nil "tests/data/testing/~A/" current-time)))
(zip-results-dir (cl-fad:merge-pathnames-as-directory new-tests-dir "unzip-results/"))
(newbox (make-instance 'boxer::data-box))
(reopened-box nil)
(zipped-reopened-box nil))
(uiop:ensure-all-directories-exist (list new-tests-dir zip-results-dir))
(setf (boxer::name newbox) "WORLD")
(boxer::bash-box-to-number newbox 42)
(is (format nil "~A" newbox) "#<DATA-BOX 42 >")
(boxer::dump-top-level-box newbox
(cl-fad:merge-pathnames-as-file new-tests-dir "test42.box"))
(setf reopened-box
(boxer::read-internal
(cl-fad:merge-pathnames-as-file new-tests-dir "test42.box")))
(is (format nil "~A" reopened-box) "#<DATA-BOX 42 >")
;; Save to the new .boxer format
(boxer::save-box-to-boxer-document-format-zipped newbox
(cl-fad:merge-pathnames-as-file new-tests-dir "test42.boxer"))
;; Unzip the freshly created .boxer file
(zip:unzip (cl-fad:merge-pathnames-as-file new-tests-dir "test42.boxer") zip-results-dir)
;; Ensure the existence of /boxer/document.box
(ok (cl-fad:merge-pathnames-as-file zip-results-dir "boxer/document.box"))
;; Open it to verify the contents
(setf zipped-reopened-box
(boxer::read-internal
(cl-fad:merge-pathnames-as-file zip-results-dir "boxer/document.box")))
(is (format nil "~A" zipped-reopened-box) "#<DATA-BOX 42 >")
;; Compare the md5 of the original .box file and the freshly unzipped one
(is (md5:md5sum-file (cl-fad:merge-pathnames-as-file zip-results-dir "boxer/document.box"))
(md5:md5sum-file (cl-fad:merge-pathnames-as-file new-tests-dir "test42.box"))
:test #'equalp)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment