branch: elpa/julia-mode
commit 70bbe82260e1baacb3d657306a7d24c159955fb7
Author: Wilfred Hughes <[email protected]>
Commit: Yichao Yu <[email protected]>
Adding unit tests for indentation.
---
julia-mode.el | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 130 insertions(+)
diff --git a/julia-mode.el b/julia-mode.el
index 788a116..b99cab1 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -410,6 +410,136 @@ before point. Returns nil if we're not within nested
parens."
(when (>= point-offset 0)
(move-to-column (+ (current-indentation) point-offset)))))
+;; Emacs 23.X doesn't include ert, so we ignore any errors that occur
+;; when we define tests.
+(ignore-errors
+ (require 'ert)
+
+ (defmacro julia--should-indent (from to)
+ "Assert that we indent text FROM producing text TO in `julia-mode'."
+ `(with-temp-buffer
+ (julia-mode)
+ (insert ,from)
+ (indent-region (point-min) (point-max))
+ (should (equal (buffer-substring-no-properties (point-min) (point-max))
+ ,to))))
+
+ (ert-deftest julia--test-indent-if ()
+ "We should indent inside if bodies."
+ (julia--should-indent
+ "
+if foo
+bar
+end"
+ "
+if foo
+ bar
+end"))
+
+ (ert-deftest julia--test-indent-else ()
+ "We should indent inside else bodies."
+ (julia--should-indent
+ "
+if foo
+ bar
+else
+baz
+end"
+ "
+if foo
+ bar
+else
+ baz
+end"))
+
+ (ert-deftest julia--test-indent-toplevel ()
+ "We should not indent toplevel expressions. "
+ (julia--should-indent
+ "
+foo()
+bar()"
+ "
+foo()
+bar()"))
+
+ (ert-deftest julia--test-indent-nested-if ()
+ "We should indent for each level of indentation."
+ (julia--should-indent
+ "
+if foo
+ if bar
+bar
+ end
+end"
+ "
+if foo
+ if bar
+ bar
+ end
+end"))
+
+ (ert-deftest julia--test-indent-function ()
+ "We should indent function bodies."
+ (julia--should-indent
+ "
+function foo()
+bar
+end"
+ "
+function foo()
+ bar
+end"))
+
+ (ert-deftest julia--test-indent-begin ()
+ "We should indent after a begin keyword."
+ (julia--should-indent
+ "
+@async begin
+bar
+end"
+ "
+@async begin
+ bar
+end"))
+
+ (ert-deftest julia--test-indent-paren ()
+ "We should indent to line up with open parens."
+ (julia--should-indent
+ "
+foobar(bar,
+baz)"
+ "
+foobar(bar,
+ baz)"))
+
+ (ert-deftest julia--test-indent-equals ()
+ "We should increase indent on a trailing =."
+ (julia--should-indent
+ "
+foo() =
+bar"
+ "
+foo() =
+ bar"))
+
+ (ert-deftest julia--test-indent-ignores-blank-lines ()
+ "Blank lines should not affect indentation of non-blank lines."
+ (julia--should-indent
+ "
+if foo
+
+bar
+end"
+ "
+if foo
+
+ bar
+end"))
+
+ (defun julia--run-tests ()
+ (interactive)
+ (ert-run-tests-interactively "julia--test")))
+
(defalias 'julia-mode-prog-mode
(if (fboundp 'prog-mode)
'prog-mode