diff options
| author | Tom Tromey <tom@tromey.com> | 2017-08-05 10:52:47 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-05 10:52:47 -0600 |
| commit | b10ad4177786a139623984c4855eb9de3864c697 (patch) | |
| tree | 4ad673689038061dbe7b731c55718bf7cfaeec79 /rust-mode-tests.el | |
| parent | afeddec5a4755418cde1537364cfc30ae280354e (diff) | |
| parent | 89320ad26b8768e5db40e97c35be9f2b690ab9c5 (diff) | |
| download | rust-mode-b10ad4177786a139623984c4855eb9de3864c697.tar.gz | |
Merge pull request #220 from Aankhen/highlight-string-interpolation
Highlight interpolation in arguments to print! &c.
Diffstat (limited to 'rust-mode-tests.el')
| -rw-r--r-- | rust-mode-tests.el | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/rust-mode-tests.el b/rust-mode-tests.el index de8a2cc..a9b4af9 100644 --- a/rust-mode-tests.el +++ b/rust-mode-tests.el @@ -2074,6 +2074,226 @@ fn main() { '("r#\"\"\"#" font-lock-string-face "'q'" font-lock-string-face))) +(ert-deftest rust-macro-font-lock () + (rust-test-font-lock + "foo!\(\);" + '("foo!" font-lock-preprocessor-face)) + (rust-test-font-lock + "foo!{};" + '("foo!" font-lock-preprocessor-face)) + (rust-test-font-lock + "foo![];" + '("foo!" font-lock-preprocessor-face))) + +(ert-deftest rust-string-interpolation-matcher-works () + (dolist (test '(("print!\(\"\"\)" 9 11 nil) + ("print!\(\"abcd\"\)" 9 15 nil) + ("print!\(\"abcd {{}}\"\);" 9 19 nil) + ("print!\(\"abcd {{\"\);" 9 18 nil) + ("print!\(\"abcd {}\"\);" 9 18 ((14 16))) + ("print!\(\"abcd {{{}\"\);" 9 20 ((16 18))) + ("print!\(\"abcd {}{{\"\);" 9 20 ((14 16))) + ("print!\(\"abcd {} {{\"\);" 9 21 ((14 16))) + ("print!\(\"abcd {}}}\"\);" 9 20 ((14 16))) + ("print!\(\"abcd {{{}}}\"\);" 9 20 ((16 18))) + ("print!\(\"abcd {0}\"\);" 9 18 ((14 17))) + ("print!\(\"abcd {0} efgh\"\);" 9 23 ((14 17))) + ("print!\(\"{1} abcd {0} efgh\"\);" 9 27 ((9 12) (18 21))) + ("print!\(\"{{{1} abcd }} {0}}} {{efgh}}\"\);" 9 33 ((11 14) (23 26))))) + (destructuring-bind (text cursor limit matches) test + (with-temp-buffer + ;; make sure we have a clean slate + (save-match-data + (set-match-data nil) + (insert text) + (goto-char cursor) + (if (null matches) + (should (equal (progn + (rust-string-interpolation-matcher limit) + (match-data)) + nil)) + (dolist (pair matches) + (rust-string-interpolation-matcher limit) + (should (equal (match-beginning 0) (car pair))) + (should (equal (match-end 0) (cadr pair)))))))))) + +(ert-deftest rust-formatting-macro-font-lock () + ;; test that the block delimiters aren't highlighted and the comment + ;; is ignored + (rust-test-font-lock + "print!(\"\"); { /* print!(\"\"); */ }" + '("print!" rust-builtin-formatting-macro-face + "\"\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "print!(\"\"); */" font-lock-comment-face)) + ;; other delimiters + (rust-test-font-lock + "print!{\"\"}; { /* no-op */ }" + '("print!" rust-builtin-formatting-macro-face + "\"\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; other delimiters + (rust-test-font-lock + "print![\"\"]; { /* no-op */ }" + '("print!" rust-builtin-formatting-macro-face + "\"\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; no interpolation + (rust-test-font-lock + "print!(\"abcd\"); { /* no-op */ }" + '("print!" rust-builtin-formatting-macro-face + "\"abcd\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; only interpolation + (rust-test-font-lock + "print!(\"{}\"); { /* no-op */ }" + '("print!" rust-builtin-formatting-macro-face + "\"" font-lock-string-face + "{}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; text + interpolation + (rust-test-font-lock + "print!(\"abcd {}\", foo); { /* no-op */ }" + '("print!" rust-builtin-formatting-macro-face + "\"abcd " font-lock-string-face + "{}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; text + interpolation with specification + (rust-test-font-lock + "print!(\"abcd {0}\", foo); { /* no-op */ }" + '("print!" rust-builtin-formatting-macro-face + "\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; text + interpolation with specification and escape + (rust-test-font-lock + "print!(\"abcd {0}}}\", foo); { /* no-op */ }" + '("print!" rust-builtin-formatting-macro-face + "\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + "}}\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; multiple pairs + (rust-test-font-lock + "print!(\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" + '("print!" rust-builtin-formatting-macro-face + "\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + " efgh " font-lock-string-face + "{1}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; println + (rust-test-font-lock + "println!(\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" + '("println!" rust-builtin-formatting-macro-face + "\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + " efgh " font-lock-string-face + "{1}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; eprint + (rust-test-font-lock + "eprint!(\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" + '("eprint!" rust-builtin-formatting-macro-face + "\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + " efgh " font-lock-string-face + "{1}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; eprintln + (rust-test-font-lock + "eprintln!(\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" + '("eprintln!" rust-builtin-formatting-macro-face + "\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + " efgh " font-lock-string-face + "{1}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; format + (rust-test-font-lock + "format!(\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" + '("format!" rust-builtin-formatting-macro-face + "\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + " efgh " font-lock-string-face + "{1}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; print + raw string + (rust-test-font-lock + "format!(r\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" + '("format!" rust-builtin-formatting-macro-face + "r\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + " efgh " font-lock-string-face + "{1}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; print + raw string with hash + (rust-test-font-lock + "format!(r#\"abcd {0} efgh {1}\"#, foo, bar); { /* no-op */ }" + '("format!" rust-builtin-formatting-macro-face + "r#\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + " efgh " font-lock-string-face + "{1}" rust-string-interpolation-face + "\"#" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + ;; print + raw string with two hashes + (rust-test-font-lock + "format!(r##\"abcd {0} efgh {1}\"##, foo, bar); { /* no-op */ }" + '("format!" rust-builtin-formatting-macro-face + "r##\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + " efgh " font-lock-string-face + "{1}" rust-string-interpolation-face + "\"##" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face))) + +(ert-deftest rust-write-macro-font-lock () + (rust-test-font-lock + "write!(f, \"abcd {0}}} efgh {1}\", foo, bar); { /* no-op */ }" + '("write!" rust-builtin-formatting-macro-face + "\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + "}} efgh " font-lock-string-face + "{1}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face)) + (rust-test-font-lock + "writeln!(f, \"abcd {0}}} efgh {1}\", foo, bar); { /* no-op */ }" + '("writeln!" rust-builtin-formatting-macro-face + "\"abcd " font-lock-string-face + "{0}" rust-string-interpolation-face + "}} efgh " font-lock-string-face + "{1}" rust-string-interpolation-face + "\"" font-lock-string-face + "/* " font-lock-comment-delimiter-face + "no-op */" font-lock-comment-face))) + (ert-deftest rust-test-basic-paren-matching () (rust-test-matching-parens " |
