diff options
author | Kyle Meyer <kyle@kyleam.com> | 2016-05-11 01:26:52 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2016-05-11 01:26:52 -0400 |
commit | c4c05088e98179ab1ff5e90155b297fd2be9a087 (patch) | |
tree | cadc620758d5b072a54e7f205039d77ecbccfddc /snakemake-test.el | |
parent | a0f4cc461ef04b5c0853afa3c9e9f1e9bf6019a3 (diff) | |
parent | 1e404eccd2587c040c03ab7ed2b9ca0e910f94f5 (diff) | |
download | snakemake-mode-c4c05088e98179ab1ff5e90155b297fd2be9a087.tar.gz |
Merge branch 'indentation-rewrite'
Diffstat (limited to 'snakemake-test.el')
-rw-r--r-- | snakemake-test.el | 329 |
1 files changed, 120 insertions, 209 deletions
diff --git a/snakemake-test.el b/snakemake-test.el index f092756..034350c 100644 --- a/snakemake-test.el +++ b/snakemake-test.el @@ -96,7 +96,6 @@ rule: ;;;; Indentation (ert-deftest snakemake-test-indent-line/at-rule-block () - ;; Always shift first line of block to column 0. (should (string= "rule abc:" @@ -118,8 +117,6 @@ rule: " rule abc :" (snakemake-indent-line) (buffer-string)))) - - ;; Don't move point if beyond column 0. (should (string= "rule abc: " @@ -129,14 +126,28 @@ rule: (buffer-string)))) (should (string= - "rule " + " +if True: + rule abc:" (snakemake-with-temp-text - " rule <point>abc: <point>" + " +if True: +rule abc:<point>" (snakemake-indent-line) - (buffer-substring (point-min) (point)))))) + (buffer-string)))) + (should + (string= + " +if True: +rule abc:" + (snakemake-with-temp-text + " +if True: + <point>rule abc:" + (snakemake-indent-line 'prev) + (buffer-string))))) (ert-deftest snakemake-test-indent-line/outside-rule () - ;; Use standard Python mode indentation outside of rule blocks. (should (string= " @@ -149,10 +160,49 @@ def ok(): (snakemake-indent-line) (buffer-string))))) +(ert-deftest snakemake-test-indent-line/toplevel-command () + (should + (string= + "include: \"somefile\"" + (snakemake-with-temp-text + "include: \"somefile\"" + (snakemake-indent-line) + (buffer-string)))) + (should + (string= + "include: \"somefile\"" + (snakemake-with-temp-text + " include: \"somefile\"" + (snakemake-indent-line) + (buffer-string)))) + (should + (string= + " +if True: + include: \"somefile\" +" + (snakemake-with-temp-text + " +if True: +<point>include: \"somefile\" +" + (snakemake-indent-line) + (buffer-string)))) + (should + (string= + " +include: + \"somefile\" +" + (snakemake-with-temp-text + " +include: +<point>\"somefile\" +" + (snakemake-indent-line) + (buffer-string))))) + (ert-deftest snakemake-test-indent-line/field-key () - ;; Always indent first line to `snakemake-indent-field-offset'. - ;; Move point to `snakemake-indent-field-offset' if it is before any - ;; text on the line. (should (string= " @@ -168,22 +218,58 @@ rule abc: (string= " rule abc: + " (snakemake-with-temp-text " rule abc: + <point>" (snakemake-indent-line) - (snakemake-indent-line) (buffer-string)))) (should (string= " rule abc: + " + (snakemake-with-temp-text + " +rule abc: +<point>" + (snakemake-indent-line 'prev) + (buffer-string)))) + (should + (string= + " +rule abc: +" + (snakemake-with-temp-text + " +rule abc: + <point>" + (snakemake-indent-line 'prev) + (buffer-string)))) + (should + (string= + " +rule abc: + text" + (snakemake-with-temp-text + " +rule abc: +text<point>" + (snakemake-indent-line) + (buffer-substring (point-min) (point))))) + (should + (string= + " +rule abc: + text" (snakemake-with-temp-text " rule abc: + text<point>" (snakemake-indent-line) (buffer-substring (point-min) (point))))) @@ -198,10 +284,6 @@ rule abc: te<point>xt" (snakemake-indent-line) (buffer-substring (point-min) (point))))) - - ;; Always indent field key to `snakemake-indent-field-offset'. - ;; Move point to `snakemake-indent-field-offset' if it is before any - ;; text on the line. (should (string= " @@ -239,8 +321,7 @@ rule abc: rule abc: input: 'infile' <point>output:" - (snakemake-indent-line) - (snakemake-indent-line) + (snakemake-indent-line 'prev) (buffer-string)))) (should (string= @@ -270,10 +351,6 @@ rule abc: (buffer-substring (point-min) (point)))))) (ert-deftest snakemake-test-indent-line/field-value () - ;; Always indent line below naked field key to - ;; `snakemake-indent-field-offset' + - ;; `snakemake-indent-value-offset'. Move point to to this position - ;; as well if it is before any text on the line. (should (string= " @@ -298,8 +375,7 @@ rule abc: rule abc: output: <point>" - (snakemake-indent-line) - (snakemake-indent-line) + (snakemake-indent-line 'prev) (buffer-string)))) (should (string= @@ -314,24 +390,6 @@ rule abc: <point>" (snakemake-indent-line) (buffer-string)))) - - ;; Add step with Python indentation for non-blank lines under naked - ;; field keys. Field keys with values starting on the same line do - ;; not use Python indentation because this is invalid syntax in - ;; Snakemake. - (should - (string= - " -rule abc: - output: 'file{}{}'.format('one', - 'two'" - (snakemake-with-temp-text - " -rule abc: - output: 'file{}{}'.format('one', -<point>'two'" - (snakemake-indent-line) - (buffer-string)))) (should (string= " @@ -351,39 +409,6 @@ rule abc: (string= " rule abc: - output: - 'file{}{}'.format('one', - " - (snakemake-with-temp-text - " -rule abc: - output: - 'file{}{}'.format('one', -<point>" - (snakemake-indent-line) - (buffer-string)))) - - ;; On non-naked field key cycle indentation between - ;; `snakemake-indent-field-offset' and column of previous field - ;; value. If point is before any text on the line, move it to the - ;; start of the text instead. - (should - (string= - " -rule abc: - output: 'file' - " - (snakemake-with-temp-text - " -rule abc: - output: 'file' -<point>" - (snakemake-indent-line) - (buffer-string)))) - (should - (string= - " -rule abc: output: 'file' " (snakemake-with-temp-text @@ -392,7 +417,6 @@ rule abc: output: 'file' <point>" (snakemake-indent-line) - (snakemake-indent-line) (buffer-string)))) (should (string= @@ -404,23 +428,8 @@ rule abc: " rule abc: output: 'file' -<point>" - (snakemake-indent-line) - (snakemake-indent-line) - (snakemake-indent-line) - (buffer-string)))) - (should - (string= - " -rule abc: - output: 'file' - 'text'" - (snakemake-with-temp-text - " -rule abc: - output: 'file' -<point>'text'" - (snakemake-indent-line) + <point>" + (snakemake-indent-line 'prev) (buffer-string)))) (should (string= @@ -434,14 +443,13 @@ rule abc: output: 'file' <point>'text'" (snakemake-indent-line) - (snakemake-indent-line) (buffer-string)))) (should (string= " rule abc: output: 'file' - 'text' " + 'text' " (snakemake-with-temp-text " rule abc: @@ -454,7 +462,7 @@ rule abc: " rule abc: output: 'file' - " + " (snakemake-with-temp-text " rule abc: @@ -472,12 +480,9 @@ rule abc: " rule abc: output: 'file' -<point> 'text'" - (snakemake-indent-line) - (snakemake-indent-line) +<point> 'text'" + (snakemake-indent-line 'prev) (buffer-string)))) - - ;; Indent body of run field according to Python mode. (should (string= " @@ -511,6 +516,21 @@ output:" (should (string= " +if True: + rule abc: + input: 'infile' + output:" + (snakemake-with-temp-text + " +if True: +<point>rule abc: +input: 'infile' +output:" + (indent-region (point) (point-max)) + (buffer-string)))) + (should + (string= + " rule abc: input: one='one', two='two' @@ -613,115 +633,6 @@ subworkflow otherworkflow: snakefile: '../path/to/otherworkflow/Snakefile'" (should (snakemake-in-rule-or-subworkflow-block-p)))) -(ert-deftest snakemake-test-first-field-line-p () - (snakemake-with-temp-text - " -rule abc: -<point>" - (should (snakemake-first-field-line-p))) - (snakemake-with-temp-text - " -rule abc: -<point> output: 'file'" - (should (snakemake-first-field-line-p))) - (snakemake-with-temp-text - " -rule abc: - output: -<point>" - (should-not (snakemake-first-field-line-p)))) - -(ert-deftest snakemake-test-below-naked-field-p () - (snakemake-with-temp-text - " -rule abc: - output: -<point>" - (should (snakemake-below-naked-field-p))) - (snakemake-with-temp-text - " -rule abc: - output: 'file' -<point>" - (should-not (snakemake-below-naked-field-p))) - (snakemake-with-temp-text - " -rule abc: - output: <point>" - (should-not (snakemake-below-naked-field-p)))) - -(ert-deftest snakemake-test-naked-field-line-p () - (snakemake-with-temp-text - " -rule abc: - output: -<point>" - (should (snakemake-naked-field-line-p))) - (snakemake-with-temp-text - " -rule abc: - output: - 'file', - <point>" - (should (snakemake-naked-field-line-p))) - (snakemake-with-temp-text - " -rule abc: - output: <point>" - (should (snakemake-naked-field-line-p))) - (snakemake-with-temp-text - " -rule abc: - output: 'file' -<point>" - (should-not (snakemake-naked-field-line-p))) - (snakemake-with-temp-text - " -rule abc: - input: - 'infile' - output: 'file' -<point>" - (should-not (snakemake-naked-field-line-p)))) - -(ert-deftest snakemake-test-run-field-line-p () - (snakemake-with-temp-text - " -rule abc: - run: -<point>" - (should (snakemake-run-field-line-p))) - (snakemake-with-temp-text - " -rule abc: - run: - with file: -<point>" - (should (snakemake-run-field-line-p))) - (snakemake-with-temp-text - " -rule abc: - output: 'file' -<point>" - (should-not (snakemake-run-field-line-p)))) - -(ert-deftest snakemake-test-previous-field-value-column () - (should (= 12 - (snakemake-with-temp-text - " -rule abc: - output: 'file' -<point>" - (snakemake-previous-field-value-column)))) - (should (= 12 - (snakemake-with-temp-text - " -rule abc: - output: 'file', - 'another' -<point>" - (snakemake-previous-field-value-column))))) - ;;; snakemake.el |