PARSE-METADATA now handles CR-LF line endings
Closes #127 Thanks @chuntaro!
This commit is contained in:
parent
694c5a9290
commit
b90c0cc6fe
5 changed files with 33 additions and 2 deletions
|
@ -70,7 +70,7 @@
|
||||||
(defun parse-metadata (stream)
|
(defun parse-metadata (stream)
|
||||||
"Given a STREAM, parse metadata from it or signal an appropriate condition."
|
"Given a STREAM, parse metadata from it or signal an appropriate condition."
|
||||||
(flet ((get-next-line (input)
|
(flet ((get-next-line (input)
|
||||||
(string-trim '(#\Space #\Newline #\Tab) (read-line input nil))))
|
(string-trim '(#\Space #\Return #\Newline #\Tab) (read-line input nil))))
|
||||||
(unless (string= (get-next-line stream) (separator *config*))
|
(unless (string= (get-next-line stream) (separator *config*))
|
||||||
(error "The file, ~a, lacks the expected header: ~a" (file-namestring stream) (separator *config*)))
|
(error "The file, ~a, lacks the expected header: ~a" (file-namestring stream) (separator *config*)))
|
||||||
(loop for line = (get-next-line stream)
|
(loop for line = (get-next-line stream)
|
||||||
|
|
2
tests/files/.coleslawrc
Normal file
2
tests/files/.coleslawrc
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
;; -*- mode: lisp -*-
|
||||||
|
()
|
6
tests/files/127.txt
Normal file
6
tests/files/127.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
;;;;;
|
||||||
|
title: We should handle CR-LF
|
||||||
|
tags: fixtures
|
||||||
|
date: 2014-12-16
|
||||||
|
format: md
|
||||||
|
;;;;;
|
15
tests/for-fixture-generation.lisp
Normal file
15
tests/for-fixture-generation.lisp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
(in-package #:cl-user)
|
||||||
|
|
||||||
|
;; Code for generating some files in tests/files/
|
||||||
|
|
||||||
|
(defun write-with-cr-lf (line stream)
|
||||||
|
(format stream line)
|
||||||
|
(format stream "~A~A" #\Return #\Linefeed))
|
||||||
|
|
||||||
|
(with-open-file (out (asdf:system-relative-pathname :coleslaw-test "tests/files/127.txt") :direction :output :if-exists :overwrite)
|
||||||
|
(write-with-cr-lf ";;;;;" out)
|
||||||
|
(write-with-cr-lf "title: We should handle CR-LF" out)
|
||||||
|
(write-with-cr-lf "tags: fixtures" out)
|
||||||
|
(write-with-cr-lf "date: 2014-12-16" out)
|
||||||
|
(write-with-cr-lf "format: md" out)
|
||||||
|
(write-with-cr-lf ";;;;;" out))
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
(in-package :coleslaw-tests)
|
(in-package :coleslaw-tests)
|
||||||
|
|
||||||
(plan 3)
|
(plan 4)
|
||||||
|
|
||||||
(diag "COLESLAW-CONF:*BASEDIR* points to Coleslaw's top level directory")
|
(diag "COLESLAW-CONF:*BASEDIR* points to Coleslaw's top level directory")
|
||||||
(is (car (last (pathname-directory coleslaw-conf:*basedir*)))
|
(is (car (last (pathname-directory coleslaw-conf:*basedir*)))
|
||||||
|
@ -13,4 +13,12 @@
|
||||||
(ok (probe-file (merge-pathnames #P"themes" coleslaw-conf:*basedir*))
|
(ok (probe-file (merge-pathnames #P"themes" coleslaw-conf:*basedir*))
|
||||||
"COLESLAW-CONF:*BASEDIR* has a themes sub-directory")
|
"COLESLAW-CONF:*BASEDIR* has a themes sub-directory")
|
||||||
|
|
||||||
|
|
||||||
|
(coleslaw::load-config (asdf:system-relative-pathname :coleslaw-test "tests/files/"))
|
||||||
|
|
||||||
|
(with-open-file (in (asdf:system-relative-pathname :coleslaw-test "tests/files/127.txt"))
|
||||||
|
(diag "PARSE-METADATA should handle files with CR-LF line endings.")
|
||||||
|
(is (coleslaw::parse-metadata in) '(:TITLE "We should handle CR-LF" :TAGS "fixtures" :DATE "2014-12-16" :FORMAT
|
||||||
|
"md") :test 'equalp))
|
||||||
|
|
||||||
(finalize)
|
(finalize)
|
||||||
|
|
Loading…
Add table
Reference in a new issue