Class: Steep::Expectations

Inherits:
Object show all
Defined in:
lib/steep/expectations.rb

Defined Under Namespace

Classes: Diagnostic, TestResult

Constant Summary collapse

LSP =
LanguageServer::Protocol

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExpectations

Returns a new instance of Expectations.



190
191
192
# File 'lib/steep/expectations.rb', line 190

def initialize()
  @diagnostics = {}
end

Instance Attribute Details

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



188
189
190
# File 'lib/steep/expectations.rb', line 188

def diagnostics
  @diagnostics
end

Class Method Details

.emptyObject



198
199
200
# File 'lib/steep/expectations.rb', line 198

def self.empty
  new()
end

.load(path:, content:) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/steep/expectations.rb', line 216

def self.load(path:, content:)
  expectations = new()

  YAML.load(content, filename: path.to_s).each do |entry|
    file = Pathname(entry["file"])
    expectations.diagnostics[file] =
      entry["diagnostics"].map {|hash| Diagnostic.from_hash(hash) }.sort_by!(&:sort_key)
  end

  expectations
end

Instance Method Details

#test(path:, diagnostics:) ⇒ Object



194
195
196
# File 'lib/steep/expectations.rb', line 194

def test(path:, diagnostics:)
  TestResult.new(path: path, expectation: self.diagnostics[path] || [], actual: diagnostics)
end

#to_yamlObject



202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/steep/expectations.rb', line 202

def to_yaml
  array = [] #: Array[{ "file" => String, "diagnostics" => Array[untyped] }]

  diagnostics.each_key.sort.each do |key|
    ds = diagnostics.fetch(key)
    array << {
      "file" => key.to_s,
      'diagnostics' => ds.sort_by(&:sort_key).map(&:to_hash)
    }
  end

  YAML.dump(array)
end