summaryrefslogtreecommitdiff
path: root/test/lisp/textmodes/sgml-mode-tests.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/lisp/textmodes/sgml-mode-tests.el')
-rw-r--r--test/lisp/textmodes/sgml-mode-tests.el54
1 files changed, 53 insertions, 1 deletions
diff --git a/test/lisp/textmodes/sgml-mode-tests.el b/test/lisp/textmodes/sgml-mode-tests.el
index 0000b352ff0..5630036e55c 100644
--- a/test/lisp/textmodes/sgml-mode-tests.el
+++ b/test/lisp/textmodes/sgml-mode-tests.el
@@ -130,6 +130,36 @@ The point is set to the beginning of the buffer."
(sgml-delete-tag 1)
(should (string= "Winter is comin'" (buffer-string)))))
+(ert-deftest sgml-quote-works ()
+ (let ((text "Foo<Bar> \"Baz\" 'Qux'\n"))
+ (with-temp-buffer
+ ;; Back and forth transformation.
+ (insert text)
+ (sgml-quote (point-min) (point-max))
+ (should (string= "Foo&lt;Bar&gt; &#34;Baz&#34; &#39;Qux&#39;\n"
+ (buffer-string)))
+ (sgml-quote (point-min) (point-max) t)
+ (should (string= text (buffer-string)))
+
+ ;; The same text escaped differently.
+ (erase-buffer)
+ (insert "Foo&lt;Bar&gt; &#34;Baz&quot; &#x27;Qux&#X27;\n")
+ (sgml-quote (point-min) (point-max) t)
+ (should (string= text (buffer-string)))
+
+ ;; Lack of semicolon.
+ (erase-buffer)
+ (insert "&amp&amp")
+ (sgml-quote (point-min) (point-max) t)
+ (should (string= "&&" (buffer-string)))
+
+ ;; Double quoting
+ (sgml-quote (point-min) (point-max))
+ (sgml-quote (point-min) (point-max))
+ (sgml-quote (point-min) (point-max) t)
+ (sgml-quote (point-min) (point-max) t)
+ (should (string= "&&" (buffer-string))))))
+
(ert-deftest sgml-tests--quotes-syntax ()
(dolist (str '("a\"b <t>c'd</t>"
"a'b <t>c\"d</t>"
@@ -138,7 +168,7 @@ The point is set to the beginning of the buffer."
"<t>\"a'\"</t>"
"<t>'a\"'</t>"
"a\"b <tag>c'd</tag>"
- ;;"<tag>c>'d</tag>" Fixed in master.
+ "<tag>c>'d</tag>"
"<t><!-- \" --></t>"
"<t><!-- ' --></t>"
"<t>(')</t>"
@@ -152,5 +182,27 @@ The point is set to the beginning of the buffer."
(should (= 1 (car (syntax-ppss (1- (point-max))))))
(should (= 0 (car (syntax-ppss (point-max)))))))))
+(ert-deftest sgml-mode-quote-in-long-text ()
+ (with-temp-buffer
+ (sgml-mode)
+ (insert "<t>"
+ ;; `syntax-propertize-wholelines' extends chunk size based
+ ;; on line length, so newlines are significant!
+ (make-string syntax-propertize-chunk-size ?a) "\n"
+ "'"
+ (make-string syntax-propertize-chunk-size ?a) "\n"
+ "</t>")
+ ;; If we just check (syntax-ppss (point-max)) immediately, then
+ ;; we'll end up propertizing the whole buffer in one chunk (so the
+ ;; test is useless). Simulate something more like what happens
+ ;; when the buffer is viewed normally.
+ (cl-loop for pos from (point-min) to (point-max)
+ by syntax-propertize-chunk-size
+ do (syntax-ppss pos))
+ (syntax-ppss (point-max))
+ ;; Check that last tag is parsed as a tag.
+ (should (= 1 (- (car (syntax-ppss (1- (point-max))))
+ (car (syntax-ppss (point-max))))))))
+
(provide 'sgml-mode-tests)
;;; sgml-mode-tests.el ends here