But there are some exceptions. For example, in Lua, one of the de facto testing libraries is busted, which tries to mimick rspec in many aspects.
A typical busted test looks like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description("unregistered user", function() | |
it("gets a 404", function() | |
assert.equals(404, http.client("/dashboard")) | |
end) | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description("unregistered user", function() | |
it("gets a 404", function() | |
assert.equals(404, http.client("/dashboard")) | |
end) | |
end) |
As the indentation code for lua-mode is quite complex and this is an exception to the general rule, I wrote this very ugly hack, that seems to solve my problem at hand.
As with all defadvice uses, it looks like a hack because it is a big ugly hack, but at least it lets me deal with it, and move on with my tasks without manually reindenting stuff.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun lua-busted-fuckups-fix () | |
(save-excursion | |
(lua-forward-line-skip-blanks 'back) | |
(let* ((current-indentation (current-indentation)) | |
(line (thing-at-point 'line t)) | |
(busted-p (s-matches? | |
(rx (+ bol (* space) | |
(or "context" "describe" "it" "setup" "teardown") | |
"(")) | |
line))) | |
(when busted-p | |
(+ current-indentation lua-indent-level))))) | |
(defun rgc-lua-calculate-indentation-override (old-function &rest arguments) | |
(or (lua-busted-fuckups-fix) | |
(apply old-function arguments))) | |
(advice-add #'lua-calculate-indentation-override | |
:around #'rgc-lua-calculate-indentation-override) | |
Another +1 for emacs hackability :)
3 comentarios:
Hi,
Thanks for your hack. Unfortunately it's not working for me :S
Hello!
Any other info about "not working for you"?
I'd debug it by:
1) check you have lua-mode installed and required
2) making sure the advice is working.
3) try do use edebug to see what's happening under the hood.
HTH
Hi Raimon,
Thanks for your help.
1) Done
2) How I can do that?
3) Returs no error.
Here's my file .
Ciao, have a nice day!
Publicar un comentario