Class: Puppet::Pops::Types::TypeMismatch

Inherits:
ExpectedActualMismatch show all
Includes:
LabelProvider
Defined in:
lib/puppet/pops/types/type_mismatch_describer.rb

Direct Known Subclasses

PatternMismatch

Constant Summary

Constants included from LabelProvider

LabelProvider::A, LabelProvider::AN, LabelProvider::SKIPPED_CHARACTERS, LabelProvider::VOWELS

Instance Attribute Summary

Attributes inherited from ExpectedActualMismatch

#actual, #expected

Attributes inherited from Mismatch

#path

Instance Method Summary collapse

Methods included from LabelProvider

#a_an, #a_an_uc, #plural_s, #the, #the_uc

Methods inherited from ExpectedActualMismatch

#==, #hash, #initialize, #swap_expected

Methods inherited from Mismatch

#==, #canonical_path, #chop_path, #format, #hash, #initialize, #path_string, #to_s

Methods included from TenseVariants

#it_does_not_expect, #it_expects, #it_has_no

Constructor Details

This class inherits a constructor from Puppet::Pops::Types::ExpectedActualMismatch

Instance Method Details

#label(o) ⇒ Object



298
299
300
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 298

def label(o)
  o.to_s
end

#merge(path, o) ⇒ Object

Returns A new instance with the least restrictive respective boundaries.

Returns:

  • A new instance with the least restrictive respective boundaries



254
255
256
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 254

def merge(path, o)
  self.class.new(path, [expected, o.expected].flatten.uniq, actual)
end

#message(variant, position, tense = :present) ⇒ Object



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 258

def message(variant, position, tense = :present)
  e = expected
  a = actual
  multi = false
  if e.is_a?(PVariantType)
    e = e.types
    if report_detailed?(e, a)
      a = detailed_actual_to_s(e, a)
      e = e.map { |t| t.to_alias_expanded_s }
    else
      sns = e.map { |t| t.simple_name }.uniq
      e = e.map { |t| s = t.simple_name; sns.count {|x| x == s } == 1 ? s : t.to_s }.uniq
      a = a.simple_name
    end
    case e.size
    when 1
      e = e[0]
    when 2
      e = "#{e[0]} or #{e[1]}"
      multi = true
    else
      e = "#{e[0..e.size-2].join(', ')}, or #{e[e.size-1]}"
      multi = true
    end
  else
    if report_detailed?(e, a)
      a = detailed_actual_to_s(e, a)
      e = e.to_alias_expanded_s
    else
      e = e.simple_name
      a = a.simple_name
    end
  end
  if multi
    "#{variant}#{position} #{it_expects(tense)} a value of type #{e}, got #{label(a)}"
  else
    "#{variant}#{position} #{it_expects(tense)} #{a_an(e)} value, got #{label(a)}"
  end
end