Class: Mulang::Expectation::V0

Inherits:
Standard
  • Object
show all
Defined in:
lib/mulang/expectation/standard.rb

Constant Summary collapse

INSPECTIONS =
%w(HasBinding HasTypeDeclaration HasTypeSignature HasVariable HasArity HasDirectRecursion
HasComposition HasComprehension HasForeach HasIf HasGuards HasConditional HasLambda HasRepeat HasWhile
HasUsage HasAnonymousVariable HasNot HasForall HasFindall)

Instance Attribute Summary

Attributes inherited from Standard

#binding, #inspection

Instance Method Summary collapse

Methods inherited from Standard

#check!, #custom?, #initialize, parse, #standard?, #to_h, #translate, #translate!, valid?

Constructor Details

This class inherits a constructor from Mulang::Expectation::Standard

Instance Method Details

#as_v2Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mulang/expectation/standard.rb', line 57

def as_v2
  if has? 'Binding' then as_v2_declare ''
  elsif has? 'TypeDeclaration' then as_v2_declare 'TypeAlias'
  elsif has? 'TypeSignature' then as_v2_declare 'TypeSignature'
  elsif has? 'Variable' then as_v2_declare 'Variable'
  elsif has? 'Arity' then as_v2_declare "ComputationWithArity#{inspection.target.value}"
  elsif has? 'DirectRecursion' then as_v2_declare "Recursively"
  elsif has? 'Usage'
    Mulang::Expectation::V2.new binding, new_inspection('Uses', Mulang::Inspection::Target.named(inspection.target.value))
  else as_v2_use
  end
end

#as_v2_declare(simple_type) ⇒ Object



78
79
80
# File 'lib/mulang/expectation/standard.rb', line 78

def as_v2_declare(simple_type)
  Mulang::Expectation::V2.new '*', new_inspection("Declares#{simple_type}", Mulang::Inspection::Target.named(binding))
end

#as_v2_useObject



74
75
76
# File 'lib/mulang/expectation/standard.rb', line 74

def as_v2_use
  Mulang::Expectation::V2.new binding, new_inspection(inspection.type.gsub(/^Has/, 'Uses'), nil)
end

#binding?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/mulang/expectation/standard.rb', line 49

def binding?
  binding.present?
end

#has?(simple_type) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/mulang/expectation/standard.rb', line 70

def has?(simple_type)
  inspection.type == "Has#{simple_type}"
end

#inspection?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/mulang/expectation/standard.rb', line 53

def inspection?
  inspection.present? && INSPECTIONS.include?(inspection.type)
end

#new_inspection(type, target) ⇒ Object



82
83
84
# File 'lib/mulang/expectation/standard.rb', line 82

def new_inspection(type, target)
  Mulang::Inspection.new(type, target, negated: inspection.negated?)
end