Skip to content

Commit ab082e3

Browse files
committed
Add test coverage
1 parent 0acb5f9 commit ab082e3

File tree

6 files changed

+68
-34
lines changed

6 files changed

+68
-34
lines changed

static_docs/case.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ Ruby also allows `case` statements without an explicit argument, which acts like
8484

8585
```ruby
8686
# Case statement without an argument
87-
# rubocop:disable Style/EmptyCaseCondition
8887
case
8988
when Time.now.saturday?
9089
puts "It's Saturday!"
@@ -93,7 +92,6 @@ when Time.now.sunday?
9392
else
9493
puts "It's a weekday"
9594
end
96-
# rubocop:enable Style/EmptyCaseCondition
9795
```
9896

9997
The case statement is particularly useful when you have multiple conditions to check against a single value, or when you want to use pattern matching to destructure complex data structures.

static_docs/class.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ class Product
2828
@@count = 0
2929

3030
# Class method
31-
def self.count
32-
@@count
31+
class << self
32+
def count
33+
@@count
34+
end
3335
end
3436

3537
def initialize(name, price)

static_docs/def.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ Methods can be defined at both the instance and class level.
5959

6060
```ruby
6161
class Timer
62+
# Class method - called on the class itself
63+
class << self
64+
def now
65+
Time.now.strftime("%H:%M:%S")
66+
end
67+
end
68+
6269
# Instance method - called on instances
6370
def start
6471
@time = Time.now
6572
"Timer started"
6673
end
67-
68-
# Class method - called on the class itself
69-
def self.now
70-
Time.now.strftime("%H:%M:%S")
71-
end
7274
end
7375

7476
timer = Timer.new

static_docs/defined.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ The `defined?` operator can check various types of expressions and returns diffe
1616
# Checking different types
1717
class Example
1818
CONSTANT = "Hello"
19-
@@class_var = "World"
2019

2120
def check_definitions
2221
@instance_var = "!"
2322

24-
puts defined?(CONSTANT) # Output: constant
25-
puts defined?(@@class_var) # Output: class variable
23+
puts defined?(CONSTANT) # Output: constant
2624
puts defined?(@instance_var) # Output: instance-variable
27-
puts defined?(yield) # Output: yield (if block given)
28-
puts defined?(super) # Output: super (if method has super)
25+
puts defined?(yield) # Output: yield (if block given)
26+
puts defined?(super) # Output: super (if method has super)
2927
end
3028
end
3129

static_docs/else.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ end
1818
The `else` clause can be used with various conditional structures in Ruby.
1919

2020
```ruby
21-
# With unless
21+
# With if (positive condition)
2222
temperature = 25
2323

24-
unless temperature < 20
24+
if temperature >= 20
2525
puts "It's warm"
2626
else
2727
puts "It's cool"

test/requests/hover_expectations_test.rb

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -929,26 +929,60 @@ def name; end
929929
end
930930

931931
def test_hover_for_keywords
932-
source = <<~RUBY
933-
def foo
934-
yield
935-
end
936-
RUBY
932+
test_cases = {
933+
"yield" => {
934+
source: <<~RUBY,
935+
def foo
936+
yield
937+
end
938+
RUBY
939+
position: { line: 1, character: 2 },
940+
},
941+
"class" => {
942+
source: <<~RUBY,
943+
class MyClass
944+
end
945+
RUBY
946+
position: { line: 0, character: 2 },
947+
},
948+
"def" => {
949+
source: <<~RUBY,
950+
def my_method
951+
end
952+
RUBY
953+
position: { line: 0, character: 2 },
954+
},
955+
"else" => {
956+
source: <<~RUBY,
957+
if condition
958+
true
959+
else
960+
false
961+
end
962+
RUBY
963+
position: { line: 2, character: 2 },
964+
},
965+
}
937966

938-
with_server(source) do |server, uri|
939-
server.process_message(
940-
id: 1,
941-
method: "textDocument/hover",
942-
params: { textDocument: { uri: uri }, position: { character: 2, line: 1 } },
943-
)
967+
test_cases.each do |keyword, config|
968+
with_server(config[:source]) do |server, uri|
969+
server.process_message(
970+
id: 1,
971+
method: "textDocument/hover",
972+
params: {
973+
textDocument: { uri: uri },
974+
position: config[:position],
975+
},
976+
)
944977

945-
contents = server.pop_response.response.contents.value
946-
assert_match("```ruby\nyield\n```", contents)
947-
assert_match(
948-
RubyLsp::KEYWORD_DOCS["yield"], #: as !nil
949-
contents,
950-
)
951-
assert_match("[Read more](#{RubyLsp::STATIC_DOCS_PATH}/yield.md)", contents)
978+
contents = server.pop_response.response.contents.value
979+
assert_match("```ruby\n#{keyword}\n```", contents)
980+
assert_match(
981+
RubyLsp::KEYWORD_DOCS[keyword] || "No documentation found for #{keyword}",
982+
contents,
983+
)
984+
assert_match("[Read more](#{RubyLsp::STATIC_DOCS_PATH}/#{keyword}.md)", contents)
985+
end
952986
end
953987
end
954988

0 commit comments

Comments
 (0)