From 31ceb60a5b669f740be47f5ba3d3536531090a14 Mon Sep 17 00:00:00 2001 From: Micah Chalmer Date: Mon, 23 Feb 2015 00:29:33 -0500 Subject: Indent inside strings after ending backslash --- rust-mode-tests.el | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) (limited to 'rust-mode-tests.el') diff --git a/rust-mode-tests.el b/rust-mode-tests.el index 4b32e94..310eeaf 100644 --- a/rust-mode-tests.el +++ b/rust-mode-tests.el @@ -284,8 +284,8 @@ very very very long string */" )) -(defun test-indent (indented) - (let ((deindented (replace-regexp-in-string "^[[:blank:]]*" " " indented))) +(defun test-indent (indented &optional deindented) + (let ((deindented (or deindented (replace-regexp-in-string "^[[:blank:]]*" " " indented)))) (rust-test-manip-code deindented 1 @@ -1207,3 +1207,86 @@ impl Foo for Bar { } " )) + +(ert-deftest test-indent-string-with-eol-backslash () + (test-indent + " +pub fn foo() { + format!(\"abc \\ + def\") +} +" + )) + +(ert-deftest test-indent-string-with-eol-backslash-at-start () + (test-indent + " +pub fn foo() { + format!(\"\\ + abc \\ + def\") +} +" + )) + +(ert-deftest test-indent-string-without-eol-backslash-indent-is-not-touched () + (test-indent + " +pub fn foo() { + format!(\" +abc +def\"); +} + +pub fn foo() { + format!(\"la la la +la +la la\"); +} +" + ;; Should still indent the code parts but leave the string internals alone: + " + pub fn foo() { + format!(\" +abc +def\"); +} + +pub fn foo() { + format!(\"la la la +la +la la\"); + } +" + )) + +(ert-deftest test-indent-string-eol-backslash-mixed-with-literal-eol () + (test-indent + " +fn foo() { + println!(\" +Here is the beginning of the string + and here is a line that is arbitrarily indented \\ + and a continuation of that indented line + and another arbitrary indentation + still another + yet another \\ + with a line continuing it +And another line not indented +\") +} +" + " +fn foo() { + println!(\" +Here is the beginning of the string + and here is a line that is arbitrarily indented \\ + and a continuation of that indented line + and another arbitrary indentation + still another + yet another \\ +with a line continuing it +And another line not indented +\") +} +")) -- cgit v1.2.3 From 52febe93a0b15740a3891855701555af404953ba Mon Sep 17 00:00:00 2001 From: Micah Chalmer Date: Mon, 23 Feb 2015 01:53:56 -0500 Subject: Add a few more tests for indents inside strings --- rust-mode-tests.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'rust-mode-tests.el') diff --git a/rust-mode-tests.el b/rust-mode-tests.el index 310eeaf..007d116 100644 --- a/rust-mode-tests.el +++ b/rust-mode-tests.el @@ -1290,3 +1290,39 @@ And another line not indented \") } ")) + +(ert-deftest test-indent-string-eol-backslash-dont-touch-raw-strings () + (test-indent + " +pub fn foo() { + format!(r\"\ +abc\ + def\"); +} + +pub fn foo() { + format!(r\"la la la + la\ +la la\"); +} +" + ;; Should still indent the code parts but leave the string internals alone: + " + pub fn foo() { + format!(r\"\ +abc\ + def\"); +} + +pub fn foo() { + format!(r\"la la la + la\ +la la\"); +} +" + )) + +(ert-deftest indent-inside-string-first-line () + (test-indent + ;; Needs to leave 1 space before "world" + "\"hello \\\n world\"")) -- cgit v1.2.3