Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle empty symbols and strings.

  • Loading branch information...
commit 873a85d82e4b2bc8d32a85c61f639c0ba5874e67 1 parent f5542d6
@rejeep authored
View
14 features/string-conversion.feature
@@ -43,3 +43,17 @@ Feature: String conversion
And I go to word "foo"
And I press "C-""
Then I should see ""foo""
+
+ Scenario: Turn empty single quote string to empty double quote string
+ When I insert "''"
+ And I turn on ruby-mode
+ And I go to point "2"
+ And I press "C-""
+ Then I should see """"
+
+ Scenario: Turn empty double quote string to empty single quote string
+ When I insert """"
+ And I turn on ruby-mode
+ And I go to point "2"
+ And I press "C-'"
+ Then I should see "''"
View
7 features/string-to-symbol.feature
@@ -64,3 +64,10 @@ Feature: String To Symbol
And I go to word "foo bar"
And I press "C-:"
Then I should see "'foo bar'"
+
+ Scenario: Turn empty string to symbol
+ When I insert "''"
+ And I turn on ruby-mode
+ And I go to point "2"
+ And I press "C-:"
+ Then I should see ":"
View
7 features/symbol-to-string.feature
@@ -57,3 +57,10 @@ Feature: Symbol To String
And I go to word "bar"
And I press "C-'"
Then I should see "'foo :bar baz'"
+
+ Scenario: Turn empty symbol to string
+ When I insert ":"
+ And I turn on ruby-mode
+ And I go to point "2"
+ And I press "C-'"
+ Then I should see "''"
View
8 ruby-tools.el
@@ -61,13 +61,13 @@
(defun ruby-tools-symbol-at-point-p ()
"Check if cursor is at a symbol or not."
(and
- (looking-at "[A-Za-z0-9_]+")
+ (looking-at "[A-Za-z0-9_]*")
(looking-back ":[A-Za-z0-9_]*")))
(defun ruby-tools-string-at-point-p ()
"Check if cursor is at a string or not."
(and
- (looking-at "[^\"']+['\"]")
+ (looking-at "[^\"']*['\"]")
(looking-back "['\"][^\"']*")))
(defun ruby-tools-symbol-region ()
@@ -86,7 +86,7 @@
(save-excursion
(re-search-backward "['\"][^\"']*" (line-beginning-position) t))
(save-excursion
- (re-search-forward "[^\"']+['\"]" (line-end-position) t))))
+ (re-search-forward "[^\"']*['\"]" (line-end-position) t))))
(defun ruby-tools-interpolate ()
"Interpolate with #{} in some places."
@@ -113,7 +113,7 @@
(min (nth 0 region))
(max (nth 1 region))
(content (buffer-substring-no-properties (1+ min) (1- max))))
- (when (string-match-p "^[a-ZA-Z_][a-ZA-Z0-9_]+$" content)
+ (when (string-match-p "^\\([a-ZA-Z_][a-ZA-Z0-9_]+\\)?$" content)
(delete-region min max)
(insert (concat ":" content))))))
Please sign in to comment.
Something went wrong with that request. Please try again.