jasmine-parser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +37 -0
- data/LICENSE.txt +29 -0
- data/README.md +118 -0
- data/Rakefile +43 -0
- data/jasmine-parser.gemspec +50 -0
- data/lib/jasmine-parser/announcer.rb +55 -0
- data/lib/jasmine-parser/config.rb +57 -0
- data/lib/jasmine-parser/exceptions.rb +46 -0
- data/lib/jasmine-parser/file_parser.rb +62 -0
- data/lib/jasmine-parser/jasmine_suite.rb +69 -0
- data/lib/jasmine-parser/javascript_object_wrapper.rb +136 -0
- data/lib/jasmine-parser/location_finder.rb +100 -0
- data/lib/jasmine-parser/node_collector.rb +88 -0
- data/lib/jasmine-parser/node_factory.rb +121 -0
- data/lib/jasmine-parser/nodes/example_node.rb +40 -0
- data/lib/jasmine-parser/nodes/function_invocation_node.rb +70 -0
- data/lib/jasmine-parser/nodes/group_node.rb +40 -0
- data/lib/jasmine-parser/nodes/node.rb +120 -0
- data/lib/jasmine-parser/nodes/root_node.rb +40 -0
- data/lib/jasmine-parser/nodes/shared_behavior_decl_node.rb +54 -0
- data/lib/jasmine-parser/nodes/shared_behavior_invoc_node.rb +80 -0
- data/lib/jasmine-parser.rb +53 -0
- data/spec/end_to_end_suite_parser_spec.rb +100 -0
- data/spec/file_parser_spec.rb +68 -0
- data/spec/fixture/spec/call_to_shared_example_in_other_file_spec.js +38 -0
- data/spec/fixture/spec/empty_shared_examples_spec.js +21 -0
- data/spec/fixture/spec/example_spec.js +48 -0
- data/spec/fixture/spec/example_spec_with_strange_spacing.js +48 -0
- data/spec/fixture/spec/multi_declaration_shared_spec.js +26 -0
- data/spec/fixture/spec/not_properly_formatted.js +24 -0
- data/spec/fixture/spec/shared_examples_function_declaration_spec.js +49 -0
- data/spec/fixture/spec/shared_examples_spec.js +43 -0
- data/spec/fixture/spec/small_file.js +5 -0
- data/spec/location_finder_spec.rb +263 -0
- data/spec/node_cloning_spec.rb +123 -0
- data/spec/node_collector_spec.rb +87 -0
- data/spec/node_spec.rb +102 -0
- data/spec/shared_behavior_decl_node_spec.rb +59 -0
- data/spec/shared_behavior_invoc_node_spec.rb +129 -0
- data/spec/shared_examples_for_end_to_end.rb +239 -0
- data/spec/shared_examples_in_new_function_spec.rb +74 -0
- data/spec/shared_examples_spec.rb +71 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/suite_spec.rb +70 -0
- metadata +128 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
# Copyright (c) 2013, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
|
32
|
+
require 'rkelly'
|
33
|
+
#TODO: Write tests for js wrapper
|
34
|
+
module JasmineParser
|
35
|
+
class JavascriptObjectWrapper
|
36
|
+
|
37
|
+
def self.parse_file(filename)
|
38
|
+
self.lines_already_covered.clear
|
39
|
+
parser = RKelly::Parser.new
|
40
|
+
file_string = File.open(filename, "r").read
|
41
|
+
parser.parse(file_string, filename)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def self.get_expression_statement_nodes(js_object)
|
46
|
+
classes = [RKelly::Nodes::ExpressionStatementNode,
|
47
|
+
RKelly::Nodes::ReturnNode,
|
48
|
+
RKelly::Nodes::FunctionDeclNode]
|
49
|
+
|
50
|
+
js_object.collect {|node| node if classes.include? node.class }.compact
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.lines_already_covered
|
54
|
+
@lines_already_covered ||= []
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.get_node_type(node)
|
58
|
+
#TODO: clean this mess up
|
59
|
+
if self.is_function_invocation?(node)
|
60
|
+
if self.is_reserved_word?(node)
|
61
|
+
return node.value.value.value
|
62
|
+
elsif self.is_shared_behavior_declaration?(node)
|
63
|
+
return :shared_behavior_declaration
|
64
|
+
elsif self.is_shared_behavior_invocation?(node)
|
65
|
+
return :shared_behavior_invocation
|
66
|
+
else
|
67
|
+
return :function_invocation
|
68
|
+
end
|
69
|
+
elsif self.is_function_declaration?(node)
|
70
|
+
return :shared_behavior_declaration
|
71
|
+
end
|
72
|
+
|
73
|
+
:not_supported #If we don't know what type of node it is, just ignore it
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.get_node_line(node)
|
77
|
+
if self.is_function_declaration?(node)
|
78
|
+
return node.line
|
79
|
+
else
|
80
|
+
return node.value.value.line if self.has_accessible_line?(node)
|
81
|
+
end
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.get_node_name(node)
|
86
|
+
|
87
|
+
name = ""
|
88
|
+
if self.is_function_invocation?(node)
|
89
|
+
if self.is_shared_behavior_declaration?(node) or self.is_shared_behavior_invocation?(node) or self.is_reserved_word?(node)
|
90
|
+
#ToDo: account for nodes that do not return a string in this case
|
91
|
+
name = node.value.entries[3].value if node.value.entries[3].value.kind_of? String
|
92
|
+
else
|
93
|
+
name = node.value.value.value if node.value.value.value.kind_of? String
|
94
|
+
end
|
95
|
+
elsif self.is_function_declaration?(node)
|
96
|
+
name = node.value
|
97
|
+
end
|
98
|
+
|
99
|
+
name = name.gsub(/^["']/, "").gsub(/['"]$/, "") #Strip off heading and trailing "' chars, but only those and nothing else
|
100
|
+
name = name.gsub(/\\/, "") #Get rid of any \ characters, because they confuse ruby strings a whole lot
|
101
|
+
name
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def self.has_accessible_line?(node)
|
107
|
+
#TODO: Need some test cases for these, i believe the return nodes are the ones that screw us over
|
108
|
+
return false unless node.value.respond_to? :value
|
109
|
+
return false unless node.value.value.respond_to? :line
|
110
|
+
true
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.is_function_invocation?(node)
|
114
|
+
node.value.kind_of? RKelly::Nodes::FunctionCallNode
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.is_function_declaration?(node)
|
118
|
+
node.kind_of? RKelly::Nodes::FunctionDeclNode
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.is_shared_behavior_declaration?(node)
|
122
|
+
Config.shared_behavior_declarations.include? node.value.value.value
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.is_shared_behavior_invocation?(node)
|
126
|
+
Config.shared_behavior_invocation.include? node.value.value.value
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.is_reserved_word?(node)
|
130
|
+
Config.reserved_group_example_words.include? node.value.value.value
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# Copyright (c) 2013, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
module JasmineParser
|
32
|
+
|
33
|
+
class LocationFiner
|
34
|
+
|
35
|
+
def initialize(suite)
|
36
|
+
sort_specs suite, all_examples
|
37
|
+
end
|
38
|
+
|
39
|
+
def all_examples
|
40
|
+
@all_examples ||= {}
|
41
|
+
end
|
42
|
+
|
43
|
+
alias :to_hash :all_examples
|
44
|
+
alias :[] :all_examples
|
45
|
+
|
46
|
+
def example_count
|
47
|
+
all_examples.keys.size
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_names
|
51
|
+
all_examples.keys
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def merge_shared_specs_into_suite(suite)
|
57
|
+
shared_examples = NodeCollector.new(suite.spec_files, :shared_behavior_declaration)
|
58
|
+
|
59
|
+
NodeCollector.new(suite.spec_files, :function_invocation).nodes.each do |node|
|
60
|
+
node.convert_to_shared_behavior_invocation if shared_examples[node.name]
|
61
|
+
end
|
62
|
+
|
63
|
+
calls_to_shared_examples = NodeCollector.new(suite.spec_files, :shared_behavior_invocation).nodes
|
64
|
+
|
65
|
+
deep_copy_adopt(calls_to_shared_examples, shared_examples)
|
66
|
+
|
67
|
+
shared_examples.nodes.each {|node| node.delete!}
|
68
|
+
end
|
69
|
+
|
70
|
+
def deep_copy_adopt(nodes, shared_examples)
|
71
|
+
still_needs_to_adopt = NodeCollector.new(nodes, :shared_behavior_invocation, {:adoptable? => false}).nodes
|
72
|
+
|
73
|
+
still_needs_to_adopt.each do |node|
|
74
|
+
if shared_examples[node.name]
|
75
|
+
node.adopt_children(shared_examples[node.name])
|
76
|
+
else
|
77
|
+
#If invocation is looking for a shared node that does not exist/not found, delete the invocation
|
78
|
+
#From the list, otherwise we have an endless loop
|
79
|
+
Announcer.warning("Could not find a shared example node with name\n#{node.name}")
|
80
|
+
still_needs_to_adopt.delete node
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
deep_copy_adopt still_needs_to_adopt, shared_examples unless still_needs_to_adopt.empty?
|
85
|
+
end
|
86
|
+
|
87
|
+
def sort_specs(suite, example_collection_hash)
|
88
|
+
merge_shared_specs_into_suite(suite)
|
89
|
+
|
90
|
+
all_examples = NodeCollector.new(suite.spec_files, :it).nodes
|
91
|
+
all_examples.each do |node|
|
92
|
+
example_info = {:name => "", :backtrace => []}
|
93
|
+
NodeCollector.map_path_to_parent(node, example_info)
|
94
|
+
|
95
|
+
example_collection_hash[example_info[:name].strip] = example_info[:backtrace]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# Copyright (c) 2013, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
module JasmineParser
|
32
|
+
|
33
|
+
class NodeCollector
|
34
|
+
|
35
|
+
|
36
|
+
def find_by_name(name)
|
37
|
+
name_key_hash(nodes)[name]
|
38
|
+
end
|
39
|
+
alias :[] :find_by_name
|
40
|
+
|
41
|
+
attr_reader :nodes
|
42
|
+
|
43
|
+
def initialize(nodes, type_wanted, refine_search = {})
|
44
|
+
@nodes = []
|
45
|
+
|
46
|
+
drill_down(nodes, type_wanted, @nodes, refine_search)
|
47
|
+
end
|
48
|
+
|
49
|
+
def drill_down(nodes, type_wanted, collection, refine_search)
|
50
|
+
nodes.each do |node|
|
51
|
+
type_match = node.type == type_wanted
|
52
|
+
refine_match = true
|
53
|
+
if !refine_search.empty?
|
54
|
+
refine_results = refine_search.keys.collect do |key|
|
55
|
+
node.send(key.to_sym) == refine_search[key] if node.respond_to? :adoptable?
|
56
|
+
end
|
57
|
+
refine_match = false if refine_results.include? false
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
collection << node if type_match and refine_match
|
62
|
+
drill_down node.children, type_wanted, collection, refine_search
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.map_path_to_parent(node, example_info)
|
67
|
+
if node.parent
|
68
|
+
example_info[:name] = node.formatted_name + example_info[:name] if node.formatted_name
|
69
|
+
example_info[:backtrace] << "#{node.filename}:#{node.line}:in `#{node.name}'"
|
70
|
+
self.map_path_to_parent(node.parent, example_info)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def name_key_hash(collection)
|
77
|
+
hash = {}
|
78
|
+
collection.each do |node|
|
79
|
+
hash[node.name] = node
|
80
|
+
end
|
81
|
+
hash
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# Copyright (c) 2013, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
module JasmineParser
|
32
|
+
#TODO: Add some tests for node factory
|
33
|
+
class NodeFactory
|
34
|
+
|
35
|
+
def self.create_node(args)
|
36
|
+
self.verify(args)
|
37
|
+
|
38
|
+
node = Node.send(args[:type], args)
|
39
|
+
|
40
|
+
node.js_object.each do |js_node|
|
41
|
+
begin
|
42
|
+
child_node_line = JavascriptObjectWrapper.get_node_line js_node
|
43
|
+
child_node_type = JavascriptObjectWrapper.get_node_type js_node
|
44
|
+
child_node_name = JavascriptObjectWrapper.get_node_name js_node
|
45
|
+
rescue => e
|
46
|
+
#I know that blank rescue is the root of all evil
|
47
|
+
#However, this is still early stages, and we have not run into every possibility to account for
|
48
|
+
#So it would be bad to fail someone's test run because their file contains something we don't expect
|
49
|
+
#This way, we just throw a warning that we had an issue, and update the parser to account for that scenario
|
50
|
+
#In the future, remove this rescue once all of the types of nodes have been accounted for
|
51
|
+
|
52
|
+
Announcer.warning("Had an issue parsing one of the children nodes, check jasmine-parser-error.log for details")
|
53
|
+
File.open("jasmine-parser-error.log", "a") do |file|
|
54
|
+
file.write "\n\n\n"
|
55
|
+
file.write "#{Time.now}"
|
56
|
+
file.write "Encountered error trying to parse one of the children nodes for #{node.filename} starting on line #{node.line}"
|
57
|
+
file.write e
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
if JavascriptObjectWrapper.lines_already_covered.include? child_node_line
|
64
|
+
next
|
65
|
+
else
|
66
|
+
JavascriptObjectWrapper.lines_already_covered << child_node_line
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
child_node_js_object = JavascriptObjectWrapper.get_expression_statement_nodes js_node
|
71
|
+
child_node_js_object.shift #Delete the very first item in array, because it contains the whole self node in it.
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
if Node.respond_to? child_node_type
|
77
|
+
node.children << self.create_node({
|
78
|
+
:name => child_node_name,
|
79
|
+
:line => child_node_line,
|
80
|
+
:type => child_node_type,
|
81
|
+
:js_object => child_node_js_object,
|
82
|
+
:filename => node.filename,
|
83
|
+
:parent => node
|
84
|
+
})
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
node
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.verify(args)
|
93
|
+
raise NodeTypeCannotBeBlankOrNilError if (args[:type].nil? or args[:type] == "")
|
94
|
+
raise NodeStartLineHasToBeIntegerOrNilError unless (args[:line].nil? or args[:line].kind_of?(Fixnum))
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def self.parse_file(filename)
|
99
|
+
|
100
|
+
full_page_js_object = JavascriptObjectWrapper.parse_file filename
|
101
|
+
js_object = JavascriptObjectWrapper.get_expression_statement_nodes full_page_js_object
|
102
|
+
|
103
|
+
root_node = self.create_node({
|
104
|
+
:name => "",
|
105
|
+
:filename => filename,
|
106
|
+
:line => 0,
|
107
|
+
:type => :root,
|
108
|
+
:js_object => js_object
|
109
|
+
|
110
|
+
})
|
111
|
+
|
112
|
+
root_node
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2013, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
module JasmineParser
|
32
|
+
|
33
|
+
class ExampleNode < Node
|
34
|
+
|
35
|
+
def type
|
36
|
+
:it
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Copyright (c) 2013, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
module JasmineParser
|
32
|
+
class FunctionInvocation < Node
|
33
|
+
def type
|
34
|
+
:function_invocation
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(args)
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def ready_to_be_adopted?
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
#TODO: really really really make some tests for this method
|
46
|
+
def convert_to_shared_behavior_invocation
|
47
|
+
|
48
|
+
args = {
|
49
|
+
:name => name,
|
50
|
+
:line => line,
|
51
|
+
:parent => parent,
|
52
|
+
:children => [],
|
53
|
+
:filename => filename,
|
54
|
+
:js_object => js_object
|
55
|
+
}
|
56
|
+
|
57
|
+
new_node = Node.shared_behavior_invocation args
|
58
|
+
self_index = self.parent.children.index self
|
59
|
+
self.parent.children[self_index] = new_node
|
60
|
+
self.parent = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def formatted_name
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2013, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
module JasmineParser
|
32
|
+
|
33
|
+
class GroupNode < Node
|
34
|
+
|
35
|
+
def type
|
36
|
+
:group
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|