jruby-parser 0.5.0 → 0.5.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.
- checksums.yaml +4 -4
- data/lib/jruby-parser.jar +0 -0
- data/lib/jruby-parser/version.rb +1 -1
- data/spec/util/node_diff_spec.rb +168 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ff10f0bf92834272246c617b94993f1918c804e
|
4
|
+
data.tar.gz: e2e3475e078e7839f2f413bc42ebfbba4e9f4e6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f9484ea74a7d2c0d9bcbbec9079b34ff2ffbdba23e2b5a55f3e394c17134defee652feb799bade91f6366fc7268c373b451c1b1a9af0097d796b52b568659e9
|
7
|
+
data.tar.gz: b65f06c640f489f153e54fe2b3a7c035ea33703543a965dd18fa644f8e9d049f995ac9d06e6be613af64186aa103a849b783fd8a2aff2d9872740435ea736ced
|
data/lib/jruby-parser.jar
CHANGED
Binary file
|
data/lib/jruby-parser/version.rb
CHANGED
@@ -0,0 +1,168 @@
|
|
1
|
+
require_relative '../helpers'
|
2
|
+
import org.jrubyparser.util.diff.SequenceMatcher
|
3
|
+
import org.jrubyparser.util.diff.Change
|
4
|
+
import org.jrubyparser.util.diff.NodeDiff
|
5
|
+
|
6
|
+
describe org.jrubyparser.util.diff.SequenceMatcher do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
SequenceMatcher.__persistent__ = true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should take two nodes at creation' do
|
13
|
+
nodeA = parse('a = "a"')
|
14
|
+
nodeB = parse('b = "b"')
|
15
|
+
sm = SequenceMatcher.new(nodeA, nodeB)
|
16
|
+
sm.new_node.should == nodeA
|
17
|
+
sm.old_node.should == nodeB
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should calculate the complexity of a node' do
|
21
|
+
nodeA = parse("def foo(bar)\n bar\n end\n foo('astring')")
|
22
|
+
nodeB = parse('b = "b"')
|
23
|
+
sm = SequenceMatcher.new(nodeA, nodeB)
|
24
|
+
sm.calc_complexity(nodeA).should == 14
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
it 'should call a callback passed in' do
|
29
|
+
nodeA = parse('a = "a"')
|
30
|
+
nodeB = parse('b = "b"')
|
31
|
+
check = false
|
32
|
+
sm = SequenceMatcher.new(nodeA, nodeB) do |node|
|
33
|
+
check = true
|
34
|
+
end
|
35
|
+
sm.diff_nodes
|
36
|
+
check.should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should diff two Strings of different value' do
|
40
|
+
nodeA = parse("'The rain in Spain falls mainly on the plain. -- My Fair Lady'")
|
41
|
+
nodeB = parse("'The life of the wife is ended by the knife. -- Stewie, Family Guy'")
|
42
|
+
seqm = SequenceMatcher.new(nodeA, nodeB)
|
43
|
+
seqm.diff_nodes.size.should >= 1
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should diff fcalls' do
|
47
|
+
nodeA = parse('a()')
|
48
|
+
nodeB = parse('b()')
|
49
|
+
seqm = SequenceMatcher.new(nodeA, nodeB)
|
50
|
+
seqm.diff_nodes.size.should >= 1
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should diff massgnnodes' do
|
54
|
+
nodeA = parse('ninjas.each {|x,y,z| puts "#{x}, #{y}, #{z}"}')
|
55
|
+
nodeB = parse('ninjas.each {|m,n,o| puts "#{x}, #{y}, #{z}"}')
|
56
|
+
seqm = SequenceMatcher.new(nodeA, nodeB)
|
57
|
+
seqm.diff_nodes.size.should >= 1
|
58
|
+
|
59
|
+
|
60
|
+
nodeC = parse('ninjas.each {|m,n,o| puts "#{x}, #{y}, #{z}"}')
|
61
|
+
nodeD = parse('ninjas.each {|m| puts "#{x}, #{y}, #{z}"}')
|
62
|
+
seqmtoo = SequenceMatcher.new(nodeC, nodeD)
|
63
|
+
seqmtoo.diff_nodes.size.should >= 1
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should not diff matching if statements' do
|
67
|
+
nodeA = parse("if 1 == 1\nputs 1\nelse\n1\nend")
|
68
|
+
nodeB = parse("if 1 == 1\nputs 1\nelse\n1\nend")
|
69
|
+
seqm = SequenceMatcher.new(nodeA, nodeB)
|
70
|
+
seqm.diff_nodes.size.should == 0
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should diff a changed if statement' do
|
74
|
+
nodeA = parse("if 1 == 1\nputs 1\nelse\n1\nend")
|
75
|
+
nodeB = parse("if 2 == 2\nputs 1\nelse\n1\nend")
|
76
|
+
nodeC = parse("if 2 == 2\nputs 3\nelse\n1\nend")
|
77
|
+
nodeD = parse("if 2 == 2\nputs 1\nelse\n2\nend")
|
78
|
+
seqm = SequenceMatcher.new(nodeA, nodeB)
|
79
|
+
seqm2 = SequenceMatcher.new(nodeB, nodeC)
|
80
|
+
seqm3 = SequenceMatcher.new(nodeB, nodeD)
|
81
|
+
seqm.diff_nodes.size.should >= 1
|
82
|
+
seqm2.diff_nodes.size.should >= 1
|
83
|
+
seqm3.diff_nodes.size.should >= 1
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should diff an OpElementAsgnNode' do
|
87
|
+
nodeA = parse("a = [1, 2, 3]\na[1] += 2")
|
88
|
+
nodeB = parse("b = [1, 2, 3]\nb[1] += 2")
|
89
|
+
nodeC = parse("a = [1, 2, 3]\na[2] += 2")
|
90
|
+
nodeD = parse("a = [1, 2, 3]\na[1] += 3")
|
91
|
+
|
92
|
+
seqm = SequenceMatcher.new(nodeA, nodeB)
|
93
|
+
seqm2 = SequenceMatcher.new(nodeA, nodeC)
|
94
|
+
seqm3 = SequenceMatcher.new(nodeA, nodeD)
|
95
|
+
|
96
|
+
seqm.diff_nodes[3].old_node.receiver.name.should == 'b'
|
97
|
+
seqm.diff_nodes[2].new_node.receiver.name.should == 'a'
|
98
|
+
seqm2.diff_nodes[1].old_node.args.get(0).value.should == 2
|
99
|
+
seqm2.diff_nodes[0].new_node.args.get(0).value.should == 1
|
100
|
+
seqm3.diff_nodes[1].old_node.value.value.should == 3
|
101
|
+
seqm3.diff_nodes[0].new_node.value.value.should == 2
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should diff Regexps' do
|
105
|
+
nodeA = parse("/abc/")
|
106
|
+
nodeB = parse("/abc/")
|
107
|
+
nodeC = parse("/abd/")
|
108
|
+
nodeD = parse("/abc/i")
|
109
|
+
|
110
|
+
seqm = SequenceMatcher.new(nodeA, nodeB)
|
111
|
+
seqm2 = SequenceMatcher.new(nodeA, nodeC)
|
112
|
+
seqm3 = SequenceMatcher.new(nodeA, nodeD)
|
113
|
+
|
114
|
+
seqm.diff_nodes.size.should == 0
|
115
|
+
seqm2.diff_nodes.size.should >= 1
|
116
|
+
seqm3.diff_nodes.size.should >= 1
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "Change" do
|
123
|
+
nodeA = parse("b = 'b'")
|
124
|
+
nodeB = parse("b = 'a'")
|
125
|
+
change = Change.new(nodeA, 4, nodeB, 4)
|
126
|
+
|
127
|
+
it 'should hold the old node' do
|
128
|
+
change.old_node.should == nodeB
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should hold the new node' do
|
132
|
+
change.new_node.should == nodeA
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should hold the complexity of the nodes' do
|
136
|
+
change.old_cost.should == 4
|
137
|
+
change.new_cost.should == 4
|
138
|
+
change.total_cost.should == 8
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe org.jrubyparser.util.diff.NodeDiff do
|
143
|
+
before(:each) do
|
144
|
+
NodeDiff.__persistent__ = true
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should create a diff' do
|
148
|
+
stringA = "b = 'b'"
|
149
|
+
stringB = "b = 'a'"
|
150
|
+
nodeA = parse(stringA)
|
151
|
+
nodeB = parse(stringB)
|
152
|
+
nd = NodeDiff.new(nodeA, stringA, nodeB, stringB)
|
153
|
+
diff = nd.diff
|
154
|
+
diff.size.should >= 1
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should create a deepdiff (diff of subnodes)' do
|
158
|
+
stringA = "'astring'\ndef foo(bar)\n bar\n end\n"
|
159
|
+
stringB = "def foo(bar)\n puts bar\n end\n"
|
160
|
+
nodeA = parse(stringA)
|
161
|
+
nodeB = parse(stringB)
|
162
|
+
nd = NodeDiff.new(nodeA, stringA, nodeB, stringB)
|
163
|
+
ddiff = nd.deep_diff
|
164
|
+
ddiff[1].subdiff.size.should >= 1
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jruby-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas E. Enebo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Gem for syntactically correct parse trees of Ruby source
|
14
14
|
email: tom.enebo@gmail.com
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- spec/positions/name_spec.rb
|
70
70
|
- spec/positions/op_asgn_or_spec.rb
|
71
71
|
- spec/positions/str_spec.rb
|
72
|
+
- spec/util/node_diff_spec.rb
|
72
73
|
- lib/jruby-parser.jar
|
73
74
|
homepage: http://github.com/jruby/jruby-parser
|
74
75
|
licenses: []
|
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
version: '0'
|
90
91
|
requirements: []
|
91
92
|
rubyforge_project: jruby-parser
|
92
|
-
rubygems_version: 2.
|
93
|
+
rubygems_version: 2.1.2
|
93
94
|
signing_key:
|
94
95
|
specification_version: 4
|
95
96
|
summary: A Gem for syntactically correct parse trees of Ruby source
|
@@ -130,3 +131,4 @@ test_files:
|
|
130
131
|
- spec/positions/name_spec.rb
|
131
132
|
- spec/positions/op_asgn_or_spec.rb
|
132
133
|
- spec/positions/str_spec.rb
|
134
|
+
- spec/util/node_diff_spec.rb
|