Merge pull request #128 from PuercoPop/127

PARSE-METADATA now handles CR-LF line endings
This commit is contained in:
Javier Olaechea 2016-11-15 10:06:13 -05:00 committed by GitHub
commit 9cc9eaf241
5 changed files with 33 additions and 2 deletions

View file

@ -70,7 +70,7 @@
(defun parse-metadata (stream)
"Given a STREAM, parse metadata from it or signal an appropriate condition."
(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*))
(error "The file, ~a, lacks the expected header: ~a" (file-namestring stream) (separator *config*)))
(loop for line = (get-next-line stream)

2
tests/files/.coleslawrc Normal file
View file

@ -0,0 +1,2 @@
;; -*- mode: lisp -*-
()

6
tests/files/127.txt Normal file
View file

@ -0,0 +1,6 @@
;;;;;
title: We should handle CR-LF
tags: fixtures
date: 2014-12-16
format: md
;;;;;

View 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))

View file

@ -3,7 +3,7 @@
(in-package :coleslaw-tests)
(plan 3)
(plan 4)
(diag "COLESLAW-CONF:*BASEDIR* points to Coleslaw's top level directory")
(is (car (last (pathname-directory coleslaw-conf:*basedir*)))
@ -13,4 +13,12 @@
(ok (probe-file (merge-pathnames #P"themes" coleslaw-conf:*basedir*))
"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)