Skip to content

Commit

Permalink
Fix #18
Browse files Browse the repository at this point in the history
  • Loading branch information
RRethy committed Jun 17, 2022
1 parent f73ed42 commit d618ada
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions queries/ruby/endwise.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
((module name: (_) @cursor) @endable @indent (#endwise! "end"))
((class name: (_) @cursor superclass: (_)? @cursor) @endable @indent (#endwise! "end"))
((singleton_class "class" . "<<" . value: (_) @cursor) @endable @indent (#endwise! "end"))
((method name: (_) @cursor parameters: (_)? @cursor) @endable @indent (#endwise! "end"))
((singleton_method name: (_) @cursor parameters: (_)? @cursor) @endable @indent (#endwise! "end"))
((while condition: (_) @cursor body: (do ("do")? @cursor) @endable) @indent (#endwise! "end"))
Expand All @@ -15,6 +16,7 @@

((ERROR ("module" @indent . [(constant) (scope_resolution)] @cursor)) (#endwise! "end"))
((ERROR ("class" @indent . [(constant) (scope_resolution)] @cursor . (superclass)? @cursor)) (#endwise! "end"))
((ERROR ("class" @indent . "<<" . (_) @cursor)) (#endwise! "end"))
((ERROR ("def" @indent . (identifier) @cursor . (method_parameters)? @cursor)) (#endwise! "end"))
((ERROR ("def" @indent . (identifier) . "." . (identifier) @cursor . (method_parameters)? @cursor)) (#endwise! "end"))
((ERROR ("while" @indent . (_) @cursor . "do"? @cursor)) (#endwise! "end"))
Expand Down
44 changes: 40 additions & 4 deletions tests/endwise/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@
END

test "ruby, subtree, class works", <<~END
-module Foo█
+module Foo
-class Foo█
+class Foo
+
+end
END
Expand Down Expand Up @@ -163,10 +163,10 @@
END

test "ruby, sequence, class works", <<~END
-module Foo█
-class Foo█
-def foo
-end
+module Foo
+class Foo
+
+end
+def foo
Expand Down Expand Up @@ -458,3 +458,39 @@
+
+FOO
END

test "ruby, sequence, superclass works", <<~END
-class Foo < self█
-def foo
-end
+class Foo < self
+
+end
+def foo
+end
END

test "ruby, subtree, superclass works", <<~END
-class Foo < self█
+class Foo < self
+
+end
END

test "ruby, sequence, singleton class", <<~END
-class << self█
-def foo
-end
+class << self
+
+end
+def foo
+end
END

test "ruby, subtree, singleton class", <<~END
-class << self█
+class << self
+
+end
END

0 comments on commit d618ada

Please sign in to comment.