fix images and add image tests
This commit is contained in:
parent
23c22a6432
commit
6523eb8d89
|
@ -29,7 +29,8 @@ TESTS = \
|
|||
tests/inlines/backslash-escape.scm \
|
||||
tests/inlines/softbreak.scm \
|
||||
tests/inlines/hardbreak.scm \
|
||||
tests/inlines/links.scm
|
||||
tests/inlines/links.scm \
|
||||
tests/inlines/images.scm
|
||||
|
||||
TEST_EXTENSIONS = .scm
|
||||
|
||||
|
|
|
@ -421,14 +421,14 @@
|
|||
|
||||
(define image? (make-link-parser
|
||||
(lambda (text ref-proc)
|
||||
(link-text? (text-advance text 1) ref-proc #t))
|
||||
(link-text? text ref-proc #t))
|
||||
make-image-node))
|
||||
|
||||
(define (parse-image text nodes delim-stack ref-proc)
|
||||
(let-values (((image text) (image? text ref-proc)))
|
||||
(let-values (((image text) (image? (text-advance text 1) ref-proc)))
|
||||
(if image
|
||||
(parse-char text (cons link nodes) delim-stack ref-proc)
|
||||
(parse-char (text-advance text 2) (cons (make-text-node "![") nodes) delim-stack ref-proc))))
|
||||
(parse-char text (cons image nodes) delim-stack ref-proc)
|
||||
(parse-char (text-advance text 1) (cons (make-text-node "![") nodes) delim-stack ref-proc))))
|
||||
|
||||
(define (parse-link text nodes delim-stack ref-proc)
|
||||
(let-values (((link text) (link? text ref-proc)))
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
;; 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 images)
|
||||
#:use-module (srfi srfi-64)
|
||||
#:use-module (ice-9 match)
|
||||
#:use-module (commonmark inlines)
|
||||
#:use-module (commonmark node))
|
||||
|
||||
(test-begin "inlines images")
|
||||
|
||||
(define (make-paragraph text)
|
||||
(make-node 'document #f
|
||||
(list (make-node 'paragraph #f
|
||||
(list (make-node 'text #f (list text)))))))
|
||||
|
||||
(define (image-destination=? node-data destination)
|
||||
(equal? (assq-ref node-data 'destination) destination))
|
||||
|
||||
(define (image-title=? node-data title)
|
||||
(equal? (assq-ref node-data 'title) title))
|
||||
|
||||
(test-assert "parse-inlines, simple inline image"
|
||||
(match (parse-inlines (make-paragraph "![foo](/url \"title\")"))
|
||||
(('document doc-data
|
||||
('paragraph para-data
|
||||
('image image-data
|
||||
('text text-data "foo"))))
|
||||
(and (image-destination=? image-data "/url")
|
||||
(image-title=? image-data "title")))
|
||||
(x (pk 'fail x #f))))
|
||||
|
||||
|
||||
(test-end)
|
||||
|
||||
(exit (= (test-runner-fail-count (test-runner-current)) 0))
|
Loading…
Reference in New Issue