From b90c0cc6fe1c2226a93fb4eec721313bfb6ec8e2 Mon Sep 17 00:00:00 2001 From: Javier Olaechea Date: Tue, 15 Nov 2016 10:01:41 -0500 Subject: [PATCH] PARSE-METADATA now handles CR-LF line endings Closes #127 Thanks @chuntaro! --- src/content.lisp | 2 +- tests/files/.coleslawrc | 2 ++ tests/files/127.txt | 6 ++++++ tests/for-fixture-generation.lisp | 15 +++++++++++++++ tests/tests.lisp | 10 +++++++++- 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/files/.coleslawrc create mode 100644 tests/files/127.txt create mode 100644 tests/for-fixture-generation.lisp diff --git a/src/content.lisp b/src/content.lisp index 0d610b2..91b5391 100644 --- a/src/content.lisp +++ b/src/content.lisp @@ -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) diff --git a/tests/files/.coleslawrc b/tests/files/.coleslawrc new file mode 100644 index 0000000..57b0afb --- /dev/null +++ b/tests/files/.coleslawrc @@ -0,0 +1,2 @@ +;; -*- mode: lisp -*- +() \ No newline at end of file diff --git a/tests/files/127.txt b/tests/files/127.txt new file mode 100644 index 0000000..366c726 --- /dev/null +++ b/tests/files/127.txt @@ -0,0 +1,6 @@ +;;;;; +title: We should handle CR-LF +tags: fixtures +date: 2014-12-16 +format: md +;;;;; diff --git a/tests/for-fixture-generation.lisp b/tests/for-fixture-generation.lisp new file mode 100644 index 0000000..0897a19 --- /dev/null +++ b/tests/for-fixture-generation.lisp @@ -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)) diff --git a/tests/tests.lisp b/tests/tests.lisp index 1db239c..f1618d8 100644 --- a/tests/tests.lisp +++ b/tests/tests.lisp @@ -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)