Class: RubyLsp::Requests::Support::TestItem

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_lsp/requests/support/test_item.rb

Overview

Represents a test item as defined by the VS Code interface to be used in the test explorer See code.visualstudio.com/api/references/vscode-api#TestItem

Note: this test item object can only represent test groups or examples discovered inside files. It cannot be used to represent test files, directories or workspaces

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, label, uri, range, framework:) ⇒ TestItem

: (String id, String label, URI::Generic uri, Interface::Range range, framework: Symbol) -> void



23
24
25
26
27
28
29
30
# File 'lib/ruby_lsp/requests/support/test_item.rb', line 23

def initialize(id, label, uri, range, framework:)
  @id = id
  @label = label
  @uri = uri
  @range = range
  @tags = ["framework:#{framework}"] #: Array[String]
  @children = {} #: Hash[String, TestItem]
end

Instance Attribute Details

#idObject (readonly)

: String



14
15
16
# File 'lib/ruby_lsp/requests/support/test_item.rb', line 14

def id
  @id
end

#labelObject (readonly)

: String



14
15
16
# File 'lib/ruby_lsp/requests/support/test_item.rb', line 14

def label
  @label
end

#rangeObject (readonly)

: Interface::Range



20
21
22
# File 'lib/ruby_lsp/requests/support/test_item.rb', line 20

def range
  @range
end

#uriObject (readonly)

: URI::Generic



17
18
19
# File 'lib/ruby_lsp/requests/support/test_item.rb', line 17

def uri
  @uri
end

Instance Method Details

#[](id) ⇒ Object

: (String id) -> TestItem?



38
39
40
# File 'lib/ruby_lsp/requests/support/test_item.rb', line 38

def [](id)
  @children[id]
end

#add(item) ⇒ Object

: (TestItem item) -> void



33
34
35
# File 'lib/ruby_lsp/requests/support/test_item.rb', line 33

def add(item)
  @children[item.id] = item
end

#childrenObject

: -> Array



43
44
45
# File 'lib/ruby_lsp/requests/support/test_item.rb', line 43

def children
  @children.values
end

#to_hashObject

: -> Hash[Symbol, untyped]



48
49
50
51
52
53
54
55
56
57
# File 'lib/ruby_lsp/requests/support/test_item.rb', line 48

def to_hash
  {
    id: @id,
    label: @label,
    uri: @uri,
    range: @range,
    tags: @tags,
    children: children.map(&:to_hash),
  }
end