Skip to content

Commit 0a5edc6

Browse files
Add tests for recent ruby mode fixes
1 parent ca19beb commit 0a5edc6

File tree

3 files changed

+84
-12
lines changed

3 files changed

+84
-12
lines changed

Diff for: electric-operator.el

+1-12
Original file line numberDiff line numberDiff line change
@@ -1158,24 +1158,13 @@ Also handles C++ lambda capture by reference."
11581158
(defun electric-operator-ruby-mode-| ()
11591159
(cond
11601160
;; Start of block params
1161-
;; arr.map { |a| a }
1162-
;; ^^
1163-
;; arr.map do |a| a end
1164-
;; ^^
11651161
((electric-operator-looking-back-locally (rx (or "do" "{") (* whitespace)))
11661162
" |")
11671163
;; End of block params
1168-
;; arr.map { |a| a }
1169-
;; ^^
1170-
;; arr.map do |a| a end
1171-
;; ^^
11721164
((electric-operator-looking-back-locally (rx (or "do" "{") (* whitespace) "|" (* (not (any "|" "\n")))))
11731165
"| ")
11741166
;; Regular operator
1175-
;; 3 | 4
1176-
;; ^^^
1177-
(t
1178-
" | ")))
1167+
(t " | ")))
11791168
(defun electric-operator-ruby-mode-* ()
11801169
(cond
11811170
;; splat

Diff for: features/ruby-mode.feature

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
Feature: Ruby mode
2+
Background:
3+
When the buffer is empty
4+
When I turn on ruby-mode
5+
When I turn on electric-operator-mode
6+
# For some reason this is extremely slow in tests, like >1 second per |
7+
# character that it matches
8+
When I turn off smie-blink-matching-open
9+
10+
Scenario: don't modify string literal
11+
When I set electric-operator-enable-in-docs to nil
12+
When I type "'var+foo-1'"
13+
Then I should see "'var+foo-1'"
14+
15+
Scenario: block params with {}
16+
When I type "|foo arr.map { |a|a }"
17+
Then I should see "arr.map { |a| a }"
18+
19+
Scenario: block params with do
20+
When I type "arr.map do|a|a end"
21+
Then I should see "arr.map do |a| a end"
22+
23+
Scenario: Normal | usage
24+
When I type "3|4"
25+
Then I should see "3 | 4"
26+
27+
# Check *args works ok
28+
Scenario: Space *args on its own
29+
When I type "f(*args)"
30+
Then I should see "f(*args)"
31+
32+
Scenario: Space *args with other args
33+
When I type "f(a,*args)"
34+
Then I should see "f(a, *args)"
35+
36+
Scenario: Space *args with a newline before it
37+
When I insert:
38+
"""
39+
f(a,
40+
41+
"""
42+
When I type "*args)"
43+
Then I should see:
44+
"""
45+
f(a,
46+
*args)
47+
"""
48+
49+
# And **kwargs
50+
Scenario: Space **kwargs on its own
51+
When I type "f(**kwargs)"
52+
Then I should see "f(**kwargs)"
53+
54+
Scenario: Space **kwargs with other args
55+
When I type "f(a,**kwargs)"
56+
Then I should see "f(a, **kwargs)"
57+
58+
Scenario: Space **kwargs with a newline before it
59+
When I insert:
60+
"""
61+
f(a,
62+
63+
"""
64+
When I type "**kwargs)"
65+
Then I should see:
66+
"""
67+
f(a,
68+
**kwargs)
69+
"""
70+
71+
Scenario: Percentage literals
72+
When I insert "%[ship good code]"
73+
Then I should see "%[ship good code]"
74+
75+
# Unfortunately eckues doesn't handle % properly so we can't test the modulo
76+
# operator
77+

Diff for: features/step-definitions/electric-spacing-steps.el

+6
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,9 @@
5959
(When "^I add a custom rule \"\\([^\"]+\\)\" \"\\([^\"]+\\)\" to \\(.*\\)$"
6060
(lambda (from to rule-list)
6161
(add-to-list (intern rule-list) (cons from to))))
62+
63+
;; Ruby mode
64+
(When "^I turn off smie-blink-matching-open"
65+
(lambda ()
66+
(remove-hook 'post-self-insert-hook 'smie-blink-matching-open t)
67+
))

0 commit comments

Comments
 (0)