[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gnuplot c2aedf8 111/184: Add ERT tests to check comment an
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gnuplot c2aedf8 111/184: Add ERT tests to check comment and string syntax. |
Date: |
Sun, 29 Aug 2021 11:03:26 -0400 (EDT) |
branch: elpa/gnuplot
commit c2aedf8cc5dd1f85e251c2d41b22b04bef051389
Author: joddie <jonxfield@gmail.com>
Commit: joddie <jonxfield@gmail.com>
Add ERT tests to check comment and string syntax.
Hopefully, these will prevent any regression when replacing the ad-hoc
syntax-scanning algorithm with `syntax-propertize` (#19)
---
gnuplot-tests.el | 251 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 251 insertions(+)
diff --git a/gnuplot-tests.el b/gnuplot-tests.el
new file mode 100644
index 0000000..6c4e9bc
--- /dev/null
+++ b/gnuplot-tests.el
@@ -0,0 +1,251 @@
+;;; Tests for gnuplot-mode.
+
+;;; Currently these attempt to cover the correct identification of
+;;; string and comment syntax.
+
+(require 'gnuplot)
+(require 'ert)
+(require 'cl-lib)
+
+;; Hide an annoying interactive message during batch testing
+(when (require 'nadvice nil t)
+ (advice-add
+ 'message
+ :around
+ (lambda (orig-message format-string &rest args)
+ (unless (string= format-string
+ "gnuplot-mode %s (gnuplot %s) -- report bugs with %S")
+ (apply orig-message format-string args)))))
+
+(eval-and-compile
+ (defvar gnuplot-string-test-contexts
+ '("%s"
+ "print %s"
+ "print %s, 2+3"
+ "print %s, 'another string'"
+ "print %s, \"another string\""
+ "print 'another string', %s"
+ "\"double-quoted string\" %s"
+ "\"double-quoted string\"%s"
+ "%s \"double-quoted string\""
+ "%s\"double-quoted string\""
+ "'single-quoted string' %s"
+ "%s 'single-quoted string'"
+ "'single-quoted string' %s 'single-quoted string'")))
+
+(defun gnuplot-test-string-in-context (string context)
+ "Test syntax-propertizing of STRING in CONTEXT in gnuplot-mode.
+
+STRING contains text representing a Gnuplot string literal.
+CONTEXT is a context is a context to place the literal within,
+represented by a format-string with a single %s placeholder.
+
+Returns non-nil if STRING is correctly recognised as a single
+string by `scan-sexps'."
+ (pcase-let
+ ((`(,prologue ,epilogue) (split-string context "%s")))
+ (with-temp-buffer
+ (gnuplot-mode)
+ (let (start end)
+ (save-excursion
+ (insert prologue)
+ (setq start (point))
+ (insert string)
+ (setq end (point))
+ (insert epilogue))
+ (syntax-propertize (point-max))
+ (string= (buffer-substring start (scan-sexps start 1))
+ string)))))
+
+(defmacro gnuplot-test-string (name string)
+ "Define an `ert' test to check syntax recognition of STRING in gnuplot-mode.
+
+The test checks that STRING is correctly recognised as a single
+string-literal in multiple different contexts, as determined by
+`gnuplot-string-test-contexts'."
+ (declare (indent 1))
+ `(ert-deftest ,name ()
+ ,string
+ ,@(cl-loop for context in gnuplot-string-test-contexts
+ collect
+ `(should (gnuplot-test-string-in-context ,string ,context)))))
+
+
+;;;; Tests for double-quoted strings
+(gnuplot-test-string gnuplot-double-quoted-string
+ "\"double-quoted string\"")
+
+(gnuplot-test-string gnuplot-double-quoted-with-single-quotes
+ "\"double-quoted 'with single quotes' embedded\"")
+
+(gnuplot-test-string gnuplot-double-quoted-with-single-quotes-2
+ "\"'single quotes inside double quotes'\"")
+
+(gnuplot-test-string gnuplot-double-quoted-escapes
+ "\"double-quoted \\\\ string \\\" with embedded \\\" escapes\"")
+
+(gnuplot-test-string gnuplot-double-quoted-escapes-2
+ "\"escaped quote before closing quote \\\"\"")
+
+(gnuplot-test-string gnuplot-double-quoted-escapes-3
+ "\"escaped backslash before closing quote \\\\\"")
+
+(gnuplot-test-string gnuplot-double-quoted-escapes-4
+ "\"\\\" escaped quote after opening quote\"")
+
+(gnuplot-test-string gnuplot-double-quoted-escapes-5
+ "\"\\\\ escaped backslash after opening quote\"")
+
+(gnuplot-test-string gnuplot-double-quoted-escapes-6
+ "\"\\\\\\\" escaped backslashes + escaped quotes (1) \\\\\\\"\"")
+
+(gnuplot-test-string gnuplot-double-quoted-empty
+ "\"\"")
+
+(gnuplot-test-string gnuplot-double-quoted-string-containing-escaped-quotes
+ "\"\\\"\\\"\"")
+
+(gnuplot-test-string gnuplot-newline-terminated-double-quoted-string
+ "\"newline-terminated
+")
+
+(gnuplot-test-string gnuplot-double-quoted-with-embedded-newlines
+ "\"string \\
+ with embedded \\
+newlines\"")
+
+(gnuplot-test-string
gnuplot-newline-terminated-double-quoted-string-with-newline
+ ;; with newlines
+ "\"newline-terminated string \\
+ with newlines
+")
+
+
+;;;; Tests for single-quoted strings
+(gnuplot-test-string gnuplot-single-quoted-strings
+ "'single-quoted string'")
+
+(gnuplot-test-string gnuplot-single-quoted-empty
+ "''")
+
+(gnuplot-test-string gnuplot-single-quoted-with-double-quotes
+ "'a single-quoted string \"containing a double-quoted string\"'")
+
+(gnuplot-test-string gnuplot-single-quoted-quotes
+ "'embedded '' quote '' characters'")
+
+(gnuplot-test-string gnuplot-single-quoted-quotes-2
+ "'embedded '' quote '' characters'''")
+
+(gnuplot-test-string gnuplot-single-quoted-quotes-3
+ "' '''")
+
+(gnuplot-test-string gnuplot-single-quoted-backslashes
+ "'embedded \\ backslashes \\'")
+
+(gnuplot-test-string gnuplot-single-quoted-backslashes-2
+ "'multiple \\ embedded \\\\ backslashes \\\\\\'")
+
+(gnuplot-test-string gnuplot-single-quoted-trailing-backslash
+ "'trailing backslash\\'")
+
+(gnuplot-test-string gnuplot-single-quoted-newline-terminated
+ "'newline terminated\n")
+
+(gnuplot-test-string gnuplot-single-quoted-newline-terminated-quotes
+ "'embedded '' escapes \\ ending at newline ''\n")
+
+(gnuplot-test-string gnuplot-single-quoted-embedded-newlines
+ "'string \\\n with embedded \\\nnewlines'")
+
+(gnuplot-test-string gnuplot-single-quoted-embedded-newlines-backslashes
+ "'string \\\\\n with \\\\\\\n multiple \\\\\\\\\n backslashes'")
+
+(gnuplot-test-string gnuplot-single-quoted-newline-terminated-embedded-newline
+ "'newline-terminated string \\\n with newlines\n")
+
+
+;;;; Comment syntax
+(eval-and-compile
+ (defvar gnuplot-comment-test-contexts
+ '("%s"
+ "\n%s"
+ "\n\n%s\n\n"
+ "print 'single-quoted string' %s"
+ "print \"double-quoted string\" %s"
+ "print 'single-quoted string # with hash mark' %s"
+ "print \"double-quoted string # with hash mark\" %s"
+ "plot sin(x), cos(x) %s"
+ "plot sin(x)
+%s
+plot cos(x)"
+ "# one-line comment
+%s"
+ "# multi-line \\
+comment
+%s")
+ "List of contexts in which to test syntax recognition of comments."))
+
+(defun gnuplot-test-comment-in-context (comment context)
+ "Non-nil if COMMENT is correctly recognised within CONTEXT in gnuplot-mode."
+ (pcase-let
+ ((`(,prologue ,epilogue) (split-string context "%s")))
+ (with-temp-buffer
+ (gnuplot-mode)
+ (let (start end)
+ (save-excursion
+ (insert prologue)
+ (setq start (point))
+ (insert comment)
+ (setq end (point))
+ (insert epilogue))
+ (syntax-propertize (point-max))
+ (goto-char (1+ start))
+ (cl-flet ((in-comment-p (position)
+ (nth 4 (syntax-ppss position))))
+ (and
+ (not (in-comment-p start))
+ (cl-loop for position from (1+ start) upto end
+ always (in-comment-p position))
+ (or (= end (point-max))
+ (not (in-comment-p (1+ end))))))))))
+
+(defmacro gnuplot-test-comment (name comment)
+ "Define an `ert' test to check syntax recognition of COMMENT in gnuplot-mode.
+
+The test checks that STRING is correctly recognised as a single
+string-literal in multiple different contexts, as determined by
+`gnuplot-string-test-contexts'."
+ (declare (indent 1))
+ `(ert-deftest ,name ()
+ ,comment
+ ,@(cl-loop for context in gnuplot-comment-test-contexts
+ collect
+ `(should (gnuplot-test-comment-in-context ,comment
,context)))))
+
+(gnuplot-test-comment gnuplot-comment-simple
+ "# a simple one-line comment")
+
+(gnuplot-test-comment gnuplot-comment-multiline
+ "# a comment\
+continued \
+over multiple lines")
+
+(gnuplot-test-comment gnuplot-comment-with-hashes
+ "# a comment # with more # hash # characters #")
+
+(gnuplot-test-comment gnuplot-comment-multiline-with-hashes
+ "# a comment \
+# continued # over \
+mutliple # lines #")
+
+(gnuplot-test-comment gnuplot-comment-with-single-quotes
+ "# a comment 'containing a single-quoted string'")
+
+(gnuplot-test-comment gnuplot-comment-with-single-quotes
+ "# a comment \"containing a double-quoted string\"")
+
+(gnuplot-test-comment gnuplot-comment-multiline-with-quotes
+ "# a continued \
+'comment' \
+\"containing strings\"")
- [nongnu] elpa/gnuplot 6792a81 083/184: Simple indentation fix for new block-structured do and if, (continued)
- [nongnu] elpa/gnuplot 6792a81 083/184: Simple indentation fix for new block-structured do and if, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 7e33d0d 087/184: three fixes: indentation, require cl macros, fix defc, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 9dd0e15 096/184: Avoid having text syntax-property changes mark buffer as modified, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot c52bb6c 089/184: grammar fixes for new-style if statement and blocks, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot e457287 099/184: Add aclocal.m4 into repository, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot f5c4437 100/184: Reduce autotools dependency to version 2.61, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot e1ee092 097/184: Merge branch 'devel' containing 0.7 release candidate., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot d9ed05b 105/184: remove broken link from readme, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot aefd4f6 106/184: Cleanup version numbers and copyright dates, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 4858b0d 110/184: Set syntax table in comint buffer, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot c2aedf8 111/184: Add ERT tests to check comment and string syntax.,
ELPA Syncer <=
- [nongnu] elpa/gnuplot 5efb8a9 112/184: Add Makefile targets to run all tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot ed930f3 116/184: Fix compile errors when testing from command line, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 2f36b36 118/184: Update Makefile.in, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot a50ac2b 119/184: Add autoloaded `run-gnuplot` command, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot d0828c0 126/184: Make gnuplot-context-sensitive-mode a normal minor mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 71e3174 129/184: Remove un-needed run-after-load hackery, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot d899379 123/184: Clarify comments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 536f2c3 122/184: Put alias for missing syntax-ppss with the other workarounds, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot b6eea0b 133/184: Add :set function for customizing context-sensitive mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot c4d464a 125/184: Use `gnuplot-completion-at-point-function' instead of advice hackery, ELPA Syncer, 2021/08/29