Class: TreeHaver::RSpec::MockInnerNode Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_haver/rspec/testable_node.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A mock inner node that provides the minimal interface TreeHaver::Node expects.

This is what TreeHaver::Node wraps - it simulates the backend-specific node
(like tree-sitter’s Node, Markly::Node, etc.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, text: nil, start_byte: 0, end_byte: nil, start_row: 0, start_column: 0, end_row: nil, end_column: nil, children: []) ⇒ MockInnerNode

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MockInnerNode.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tree_haver/rspec/testable_node.rb', line 17

def initialize(
  type:,
  text: nil,
  start_byte: 0,
  end_byte: nil,
  start_row: 0,
  start_column: 0,
  end_row: nil,
  end_column: nil,
  children: []
)
  @type = type.to_s
  @text_content = text
  @start_byte = start_byte
  @end_byte = end_byte || (text ? start_byte + text.length : start_byte)
  @start_row = start_row
  @start_column = start_column
  @end_row = end_row || start_row
  @end_column = end_column || (text ? start_column + text.length : start_column)
  @children_data = children
end

Instance Attribute Details

#children_dataObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/tree_haver/rspec/testable_node.rb', line 15

def children_data
  @children_data
end

#end_byteObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/tree_haver/rspec/testable_node.rb', line 15

def end_byte
  @end_byte
end

#start_byteObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/tree_haver/rspec/testable_node.rb', line 15

def start_byte
  @start_byte
end

#typeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/tree_haver/rspec/testable_node.rb', line 15

def type
  @type
end

Instance Method Details

#child(index) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



51
52
53
54
55
# File 'lib/tree_haver/rspec/testable_node.rb', line 51

def child(index)
  return if index.nil? || index < 0 || index >= @children_data.length

  @children_data[index]
end

#child_countObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
# File 'lib/tree_haver/rspec/testable_node.rb', line 47

def child_count
  @children_data.length
end

#childrenObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return children array (for enumerable behavior)



58
59
60
# File 'lib/tree_haver/rspec/testable_node.rb', line 58

def children
  @children_data
end

#each(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Iterate over children



71
72
73
74
75
# File 'lib/tree_haver/rspec/testable_node.rb', line 71

def each(&block)
  return enum_for(:each) unless block

  @children_data.each(&block)
end

#end_pointObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/tree_haver/rspec/testable_node.rb', line 43

def end_point
  TreeHaver::Point.new(@end_row, @end_column)
end

#first_childObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



62
63
64
# File 'lib/tree_haver/rspec/testable_node.rb', line 62

def first_child
  @children_data.first
end

#has_error?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test nodes are always valid (no parse errors)

Returns:

  • (Boolean)


82
83
84
# File 'lib/tree_haver/rspec/testable_node.rb', line 82

def has_error?
  false
end

#last_childObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
# File 'lib/tree_haver/rspec/testable_node.rb', line 66

def last_child
  @children_data.last
end

#missing?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test nodes are never missing (not error recovery insertions)

Returns:

  • (Boolean)


87
88
89
# File 'lib/tree_haver/rspec/testable_node.rb', line 87

def missing?
  false
end

#named?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


77
78
79
# File 'lib/tree_haver/rspec/testable_node.rb', line 77

def named?
  true
end

#start_pointObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
# File 'lib/tree_haver/rspec/testable_node.rb', line 39

def start_point
  TreeHaver::Point.new(@start_row, @start_column)
end

#string_contentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

For backends that use string_content (like Markly/Commonmarker)



97
98
99
# File 'lib/tree_haver/rspec/testable_node.rb', line 97

def string_content
  @text_content
end

#textObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Some backends provide text directly



92
93
94
# File 'lib/tree_haver/rspec/testable_node.rb', line 92

def text
  @text_content
end