machete 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,38 +2,66 @@ require "spec_helper"
2
2
 
3
3
  describe Machete do
4
4
  describe "matches?" do
5
+ before do
6
+ # The same pattern in a string form and a compiled form.
7
+ @patterns = [
8
+ 'FixnumLiteral<value = 42>',
9
+ Machete::Matchers::NodeMatcher.new("FixnumLiteral",
10
+ :value => Machete::Matchers::LiteralMatcher.new(42)
11
+ )
12
+ ]
13
+ end
14
+
5
15
  it "returns true when passed matching node and pattern" do
6
- Machete.matches?('42'.to_ast, 'FixnumLiteral<value = 42>').should be_true
16
+ @patterns.each do |pattern|
17
+ Machete.matches?('42'.to_ast, pattern).should be_true
18
+ end
7
19
  end
8
20
 
9
21
  it "returns false when passed non-matching node and pattern" do
10
- Machete.matches?('43'.to_ast, 'FixnumLiteral<value = 42>').should be_false
22
+ @patterns.each do |pattern|
23
+ Machete.matches?('43'.to_ast, pattern).should be_false
24
+ end
11
25
  end
12
26
  end
13
27
 
14
28
  describe "find" do
29
+ before do
30
+ # The same pattern in a string form and a compiled form.
31
+ @patterns = [
32
+ 'FixnumLiteral',
33
+ Machete::Matchers::NodeMatcher.new("FixnumLiteral")
34
+ ]
35
+ end
36
+
15
37
  it "returns [] when no node matches the pattern" do
16
- Machete.find('"abcd"'.to_ast, 'FixnumLiteral').should == []
38
+ @patterns.each do |pattern|
39
+ Machete.find('"abcd"'.to_ast, pattern).should == []
40
+ end
17
41
  end
18
42
 
19
43
  it "returns root node if it matches the pattern" do
20
- nodes = Machete.find('42'.to_ast, 'FixnumLiteral')
44
+ @patterns.each do |pattern|
45
+ nodes = Machete.find('42'.to_ast, pattern)
21
46
 
22
- nodes.size.should == 1
23
- nodes[0].should be_instance_of(Rubinius::AST::FixnumLiteral)
24
- nodes[0].value.should == 42
47
+ nodes.size.should == 1
48
+ nodes[0].should be_instance_of(Rubinius::AST::FixnumLiteral)
49
+ nodes[0].value.should == 42
50
+ end
25
51
  end
26
52
 
27
53
  it "returns child nodes if they match the pattern" do
28
- nodes = Machete.find('42 + 43 + 44'.to_ast, 'FixnumLiteral').sort_by(&:value)
29
-
30
- nodes.size.should == 3
31
- nodes[0].should be_instance_of(Rubinius::AST::FixnumLiteral)
32
- nodes[0].value.should == 42
33
- nodes[1].should be_instance_of(Rubinius::AST::FixnumLiteral)
34
- nodes[1].value.should == 43
35
- nodes[2].should be_instance_of(Rubinius::AST::FixnumLiteral)
36
- nodes[2].value.should == 44
54
+ @patterns.each do |pattern|
55
+ nodes = Machete.find('42 + 43 + 44'.to_ast, pattern).sort_by(&:value)
56
+
57
+ nodes.size.should == 3
58
+ nodes[0].should be_instance_of(Rubinius::AST::FixnumLiteral)
59
+ nodes[0].value.should == 42
60
+ nodes[1].should be_instance_of(Rubinius::AST::FixnumLiteral)
61
+ nodes[1].value.should == 43
62
+ nodes[2].should be_instance_of(Rubinius::AST::FixnumLiteral)
63
+ nodes[2].value.should == 44
64
+ end
37
65
  end
38
66
  end
39
67
  end
metadata CHANGED
@@ -1,22 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machete
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 1694540110752149318
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Majda
14
+ - "Piotr Nie\xC5\x82acny"
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-10-18 00:00:00 +02:00
19
- default_executable:
19
+ date: 2012-08-19 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: racc
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 3
29
+ hash: 2002549777813010636
30
30
  segments:
31
31
  - 0
32
32
  version: "0"
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- hash: 3
43
+ hash: 2002549777813010636
44
44
  segments:
45
45
  - 0
46
46
  version: "0"
@@ -54,7 +54,7 @@ dependencies:
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- hash: 3
57
+ hash: 2002549777813010636
58
58
  segments:
59
59
  - 0
60
60
  version: "0"
@@ -68,7 +68,7 @@ dependencies:
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
- hash: 3
71
+ hash: 2002549777813010636
72
72
  segments:
73
73
  - 0
74
74
  version: "0"
@@ -82,14 +82,16 @@ dependencies:
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- hash: 3
85
+ hash: 2002549777813010636
86
86
  segments:
87
87
  - 0
88
88
  version: "0"
89
89
  type: :development
90
90
  version_requirements: *id005
91
91
  description: Machete is a simple tool for matching Rubinius AST nodes against patterns. You can use it if you are writing any kind of tool that processes Ruby code and needs to do some work on specific types of nodes, needs to find patterns in the code, etc.
92
- email: dmajda@suse.de
92
+ email:
93
+ - dmajda@suse.cz
94
+ - piotr.nielacny@gmail.com
93
95
  executables: []
94
96
 
95
97
  extensions: []
@@ -115,7 +117,6 @@ files:
115
117
  - spec/machete_spec.rb
116
118
  - spec/spec_helper.rb
117
119
  - lib/machete/parser.rb
118
- has_rdoc: true
119
120
  homepage: https://github.com/openSUSE/machete
120
121
  licenses:
121
122
  - MIT
@@ -129,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
130
  requirements:
130
131
  - - ">="
131
132
  - !ruby/object:Gem::Version
132
- hash: 3
133
+ hash: 2002549777813010636
133
134
  segments:
134
135
  - 0
135
136
  version: "0"
@@ -138,16 +139,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
139
  requirements:
139
140
  - - ">="
140
141
  - !ruby/object:Gem::Version
141
- hash: 3
142
+ hash: 2002549777813010636
142
143
  segments:
143
144
  - 0
144
145
  version: "0"
145
146
  requirements: []
146
147
 
147
148
  rubyforge_project:
148
- rubygems_version: 1.5.2
149
+ rubygems_version: 1.8.23
149
150
  signing_key:
150
151
  specification_version: 3
151
152
  summary: Simple tool for matching Rubinius AST nodes against patterns
152
153
  test_files: []
153
154
 
155
+ has_rdoc: