Class: JasmineParser::JavascriptObjectWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/jasmine-parser/javascript_object_wrapper.rb

Class Method Summary collapse

Class Method Details

.get_expression_statement_nodes(js_object) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/jasmine-parser/javascript_object_wrapper.rb', line 45

def self.get_expression_statement_nodes(js_object)
  classes = [RKelly::Nodes::ExpressionStatementNode,
             RKelly::Nodes::ReturnNode,
             RKelly::Nodes::FunctionDeclNode]
  
  js_object.collect {|node| node if classes.include? node.class }.compact
end

.get_node_line(node) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/jasmine-parser/javascript_object_wrapper.rb', line 76

def self.get_node_line(node)
  if self.is_function_declaration?(node)
    return node.line 
  else
    return node.value.value.line if self.has_accessible_line?(node)
  end
  nil
end

.get_node_name(node) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/jasmine-parser/javascript_object_wrapper.rb', line 85

def self.get_node_name(node)

  name = ""
  if self.is_function_invocation?(node)
    if self.is_shared_behavior_declaration?(node) or self.is_shared_behavior_invocation?(node) or self.is_reserved_word?(node)
      #ToDo: account for nodes that do not return a string in this case
      name = node.value.entries[3].value if node.value.entries[3].value.kind_of? String
    else
      name = node.value.value.value if node.value.value.value.kind_of? String
    end
  elsif self.is_function_declaration?(node)
    name = node.value
  end

  name = name.gsub(/^["']/, "").gsub(/['"]$/, "") #Strip off heading and trailing "' chars, but only those and nothing else
  name = name.gsub(/\\/, "") #Get rid of any \ characters, because they confuse ruby strings a whole lot
  name
end

.get_node_type(node) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/jasmine-parser/javascript_object_wrapper.rb', line 57

def self.get_node_type(node)
  #TODO: clean this mess up
  if self.is_function_invocation?(node)
    if self.is_reserved_word?(node)
      return node.value.value.value
    elsif self.is_shared_behavior_declaration?(node)
      return :shared_behavior_declaration
    elsif self.is_shared_behavior_invocation?(node)
      return :shared_behavior_invocation
    else
      return :function_invocation
    end
  elsif self.is_function_declaration?(node)
    return :shared_behavior_declaration
  end

  :not_supported #If we don't know what type of node it is, just ignore it
end

.lines_already_coveredObject



53
54
55
# File 'lib/jasmine-parser/javascript_object_wrapper.rb', line 53

def self.lines_already_covered
  @lines_already_covered ||= []
end

.parse_file(filename) ⇒ Object



37
38
39
40
41
42
# File 'lib/jasmine-parser/javascript_object_wrapper.rb', line 37

def self.parse_file(filename)
  self.lines_already_covered.clear
  parser = RKelly::Parser.new
  file_string = File.open(filename, "r").read
  parser.parse(file_string, filename)
end