add initial emphasis tests and some fixes

This commit is contained in:
Erik Edrosa 2016-05-03 23:56:37 -04:00
parent 7f6d81df6a
commit 5a76c72c42
4 changed files with 70 additions and 8 deletions

View File

@ -22,8 +22,9 @@ TESTS = \
tests/blocks/list-items.scm \
tests/blocks/lists.scm \
tests/blocks/setext-headings.scm \
tests/blocks/thematic-breaks.scm \
tests/inlines/code-spans.scm
tests/blocks/thematic-breaks.scm \
tests/inlines/code-spans.scm \
tests/inlines/emphasis.scm
TEST_EXTENSIONS = .scm

View File

@ -176,13 +176,18 @@
(if matching-delim
(parse-matching-delim delim matching-delim)
(parse-char (text-advance text (delimiter-count delim))
nodes
(cons (delim->text delim) nodes)
delim-stack
nodes-stack))))
((delimiter-open? delim)
(parse-char (text-advance text (delimiter-count delim))
'()
(cons delim delim-stack)
(cons nodes nodes-stack)))
(else (parse-char (text-advance text (delimiter-count delim))
'()
(cons delim delim-stack)
(cons nodes nodes-stack))))))
(cons (delim->text delim) nodes)
delim-stack
nodes-stack)))))
(define (parse-ticks text nodes delim-stack nodes-stack)
(let ((start-ticks (start-ticks? text)))

View File

@ -148,7 +148,7 @@
;; with text nodes as children
;; String -> Node
(define (make-paragraph-node text)
(make-node 'paragraph #f (list (make-text-node text))))
(make-node 'paragraph #f (list (make-text-node (string-trim text)))))
;; Node -> Boolean
(define (paragraph-node? n)
@ -229,7 +229,7 @@
;; Text node
;; String Boolean -> Node
(define (make-text-node text)
(make-node 'text '((closed . #t)) (list (string-trim text))))
(make-node 'text '((closed . #t)) (list text)))
(define (join-text-nodes tn1 tn2)
(make-node 'text

View File

@ -0,0 +1,56 @@
;; Copyright (C) 2016 Erik Edrosa <erik.edrosa@gmail.com>
;;
;; This file is part of guile-commonmark
;;
;; guile-commonmark is free software: you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public License
;; as published by the Free Software Foundation, either version 3 of
;; the License, or (at your option) any later version.
;;
;; guile-commonmark is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public License
;; along with guile-commonmark. If not, see <http://www.gnu.org/licenses/>.
(define-module (test-inlines emphasis)
#:use-module (srfi srfi-64)
#:use-module (ice-9 match)
#:use-module (commonmark inlines)
#:use-module (commonmark node))
(test-begin "inlines emphasis")
(define (make-paragraph text)
(make-node 'document #f
(list (make-node 'paragraph #f
(list (make-node 'text #f (list text)))))))
(define (em? node-data)
(eq? 'em (assq-ref node-data 'type)))
(test-assert "parse-inlines, simple emphasis"
(match (parse-inlines (make-paragraph "*foo bar*"))
(('document doc-data
('paragraph para-data
('emphasis emphasis-data
('text text-data "foo bar"))))
(em? emphasis-data))
(x (pk 'fail x #f))))
(test-assert "parse-inlines, not emphasis because whitespace after *"
(match (parse-inlines (make-paragraph "a * foo bar*"))
(('document doc-data
('paragraph para-data
('text text-data1 "*")
('text text-data2 " foo bar")
('text text-data3 "*")
('text text-data4 "a ")))
#t)
(x (pk 'fail x #f))))
(test-end)
(exit (= (test-runner-fail-count (test-runner-current)) 0))