reflexive 0.0.5 → 0.0.6

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.
@@ -0,0 +1,8 @@
1
+ module Kernel
2
+ # Returns the object's singleton class.
3
+ def singleton_class
4
+ class << self
5
+ self
6
+ end
7
+ end unless respond_to?(:singleton_class) # exists in 1.9.2
8
+ end
@@ -1,3 +1,5 @@
1
+ require "reflexive/core_ext/kernel/singleton_class"
2
+
1
3
  module Reflexive
2
4
  module_function
3
5
 
@@ -1,3 +1,5 @@
1
+ require "reflexive/core_ext/kernel/singleton_class"
2
+
1
3
  module Reflexive
2
4
  class Methods
3
5
  def initialize(klass_or_module, options = {})
@@ -55,7 +57,7 @@ module Reflexive
55
57
  ancestor_name(ancestor, singleton)
56
58
  end
57
59
  end
58
-
60
+
59
61
  def find_all
60
62
  ancestors = [] # flattened ancestors (both normal and singleton)
61
63
 
@@ -25,170 +25,136 @@ describe Reflexive::CodeRayRubyScanner do
25
25
  end
26
26
  end
27
27
 
28
- pending "squeezes constants" do
29
- src = <<-RUBY
30
- class ConstRef < Const::PathRef
31
- RefenceConstInClassBody = ::TopConstRef
32
- def m
33
- Const::PathRef
34
- end
35
- end
36
-
37
- class Const::PathRef < ::TopConstRef
38
- def self.m
39
- reference_in_method_body ::TopConstRef
40
- end
41
- end
42
-
43
- class ::TopConstRef
44
- end
45
-
46
- class Const::Deeply::Nested::PathRef < ConstRef
47
- end
48
- RUBY
49
- tokens = reflexive_tokens(src)
50
- tokens.should include(["ConstRef", :constant, { :scope => nil }])
51
- tokens.should include(["Const::PathRef", :constant, { :scope => ["ConstRef"] }])
52
- tokens.should include(["Const::PathRef", :constant, { :scope => nil }])
53
- tokens.should include(["::TopConstRef", :constant, { :scope => nil }])
54
- tokens.should include(["::TopConstRef", :constant, { :scope => ["Const::PathRef"] }])
55
- tokens.should include(["Const::Deeply::Nested::PathRef", :constant, { :scope => nil }])
56
- end
57
-
58
28
  it "injects load_path tags" do
59
29
  reflexive_tokens("require('f')").should include(["f", :content, { :load_path => true }])
60
30
  reflexive_tokens("require 'f'").should include(["f", :content, { :load_path => true }])
61
31
  end
62
32
 
63
- it "injects instance method tags"
33
+ SOURCE_TO_TOKENS = {
34
+ '%Q{str}' => [[:open, :string], ["%Q{", :delimiter], ["str", :content], ["}", :delimiter], [:close, :string]],
35
+ '%r<regexp>' => [[:open, :regexp], ["%r<", :delimiter], ["regexp", :content], [">", :delimiter], [:close, :regexp]],
36
+ ":symbol" => [[:open, :symbol], [":", :delimiter], ["symbol", :content], [:close, :symbol]],
37
+ ":@instance_var_symbol" => [[:open, :symbol], [":", :delimiter], ["@instance_var_symbol", :content], [:close, :symbol]],
38
+ ":@@class_var_symbol" => [[:open, :symbol], [":", :delimiter], ["@@class_var_symbol", :content], [:close, :symbol]],
39
+ ":$global_var_symbol" => [[:open, :symbol], [":", :delimiter], ["$global_var_symbol", :content], [:close, :symbol]],
40
+ ":ConstantSymbol" => [[:open, :symbol], [":", :delimiter], ["ConstantSymbol", :content], [:close, :symbol]],
41
+ ":+" => [[:open, :symbol], [":", :delimiter], ["+", :content], [:close, :symbol]],
42
+ ":if" => [[:open, :symbol], [":", :delimiter], ["if", :content], [:close, :symbol]],
43
+ "#!/usr/bin/env ruby" => [["#!/usr/bin/env ruby", :comment]],
44
+ '%q[haha! [nesting [rocks] ] ! ]' => [[:open, :string], ["%q[", :delimiter], ["haha! [nesting [rocks] ] ! ", :content],
45
+ ["]", :delimiter], [:close, :string]],
46
+ '%Q[hehe! #{ %Q]nesting #{"really"} rocks] } ! ]' => [[:open, :string], ["%Q[", :delimiter], ["hehe! ", :content],
47
+ [:open, :inline], ["\#{", :inline_delimiter], [" ", :space],
48
+ [:open, :string], ["%Q]", :delimiter], ["nesting ", :content],
49
+ [:open, :inline], ["\#{", :inline_delimiter], [:open, :string],
50
+ ["\"", :delimiter], ["really", :content], ["\"", :delimiter],
51
+ [:close, :string], ["}", :inline_delimiter], [:close, :inline],
52
+ [" rocks", :content], ["]", :delimiter], [:close, :string],
53
+ [" ", :space], ["}", :inline_delimiter], [:close, :inline],
54
+ [" ! ", :content], ["]", :delimiter], [:close, :string]],
55
+ 'some_string.to_i /\\s+/' => [["some_string", :ident], [".", :operator], ["to_i", :ident], [" ", :space], [:open, :regexp], ["/", :delimiter], ["\\s+", :content], ["/", :delimiter], [:close, :regexp]],
56
+ 'S = \'bla\' * 100 + "\n" + "\t"*4' => [["S", :constant], [" ", :space], ["=", :operator],
57
+ [" ", :space], [:open, :string], ["'", :delimiter],
58
+ ["bla", :content], ["'", :delimiter], [:close, :string],
59
+ [" ", :space], ["*", :operator], [" ", :space],
60
+ ["100", :integer], [" ", :space], ["+", :operator],
61
+ [" ", :space], [:open, :string], ["\"", :delimiter],
62
+ ["\\n", :content], ["\"", :delimiter], [:close, :string],
63
+ [" ", :space], ["+", :operator], [" ", :space], [:open, :string],
64
+ ["\"", :delimiter], ["\\t", :content], ["\"", :delimiter], [:close, :string],
65
+ ["*", :operator], ["4", :integer]],
66
+ ':"#{undef :blubb}#@@cv"' => [[:open, :symbol], [":\"", :delimiter], [:open, :inline],
67
+ ["\#{", :inline_delimiter], ["undef", :content],
68
+ [:close, :symbol], [" ", :space], [:open, :symbol],
69
+ [":", :delimiter], ["blubb", :content], [:close, :symbol],
70
+ ["}", :inline_delimiter], [:close, :inline], ["#", :escape],
71
+ ["@@cv", :class_variable], ["\"", :delimiter], [:close, :string]],
72
+ 'undef :"bla", /, :"#{undef :blubb}#@@cv"' => [["undef", :reserved], [" ", :space],
73
+ [:open, :symbol], [":\"", :delimiter],
74
+ ["bla", :content], ["\"", :delimiter],
75
+ [:close, :symbol], [",", :operator], [" ", :space],
76
+ ["/,", :operator], [" ", :space], [:open, :symbol],
77
+ [":\"", :delimiter], [:open, :inline], ["\#{", :inline_delimiter],
78
+ ["undef", :content], [:close, :symbol], [" ", :space], [:open, :symbol],
79
+ [":", :delimiter], ["blubb", :content], [:close, :symbol],
80
+ ["}", :inline_delimiter], [:close, :inline], ["#", :escape],
81
+ ["@@cv", :class_variable], ["\"", :delimiter], [:close, :string]],
82
+ '@hash.delete_if { |o,| yield(o) }' => [["@hash", :instance_variable], [".", :operator], ["delete_if", :ident], [" ", :space], ["{", :operator], [" ", :space], ["|", :operator], ["o", :ident], [",|", :operator], [" ", :space], ["yield", :reserved], ["(", :operator], ["o", :ident], [")", :operator], [" ", :space], ["}", :operator]],
83
+ '"double quoted string"' => [[:open, :string], ["\"", :delimiter], ["double quoted string", :content], ["\"", :delimiter], [:close, :string]],
84
+ '# comment' => [["# comment", :comment]],
85
+ '"a #{ b + "c"}"' => [[:open, :string], ["\"", :delimiter], ["a ", :content], [:open, :inline], ["\#{", :inline_delimiter], [" ", :space], ["b", :ident], [" ", :space], ["+", :operator], [" ", :space], [:open, :string], ["\"", :delimiter], ["c", :content], ["\"", :delimiter], [:close, :string], ["}", :inline_delimiter], [:close, :inline], ["\"", :delimiter], [:close, :string]],
86
+ '42 if true' => [["42", :integer], [" ", :space], ["if", :reserved], [" ", :space], ["true", :reserved]],
87
+ '/regexp with modifiers/xm' => [[:open, :regexp], ["/", :delimiter], ["regexp with modifiers", :content], ["/xm", :delimiter], [:close, :regexp]],
88
+ 'a = ?s' => [["a", :ident], [" ", :space], ["=", :operator], [" ", :space], ["?s", :integer]],
89
+ 'q = "\\n"' => [["q", :ident], [" ", :space], ["=", :operator], [" ", :space], [:open, :string], ["\"", :delimiter], ["\\n", :content], ["\"", :delimiter], [:close, :string]],
90
+ 'call_something()' => [["call_something", :ident], ["()", :operator]],
91
+ 'a = 1 && 2 || 3' => [["a", :ident], [" ", :space], ["=", :operator], [" ", :space], ["1", :integer], [" ", :space], ["&&", :operator], [" ", :space], ["2", :integer], [" ", :space], ["||", :operator], [" ", :space], ["3", :integer]],
92
+ '@ivar = 123' => [["@ivar", :instance_variable], [" ", :space], ["=", :operator], [" ", :space], ["123", :integer]],
93
+ '@@cvar = 345' => [["@@cvar", :class_variable], [" ", :space], ["=", :operator], [" ", :space], ["345", :integer]],
94
+ '$gvar = 345' => [["$gvar", :global_variable], [" ", :space], ["=", :operator], [" ", :space], ["345", :integer]],
95
+ 'float = 1.2345' => [["float", :ident], [" ", :space], ["=", :operator], [" ", :space], ["1.2345", :float]],
96
+ '`shell`' => [[:open, :shell], ["`", :delimiter], ["shell", :content], ["`", :delimiter], [:close, :shell]],
97
+ 'v = %w(w1 w2)' => [["v", :ident], [" ", :space], ["=", :operator], [" ", :space], ["%w(w1 w2)", :content]],
98
+ '"a#{" b #{@c} d" if @c} d #{@e}; f."' => [[:open, :string], ["\"", :delimiter], ["a", :content],
99
+ [:open, :inline], ["\#{", :inline_delimiter], [:open, :string],
100
+ ["\"", :delimiter], [" b ", :content], [:open, :inline],
101
+ ["\#{", :inline_delimiter], ["@c", :instance_variable], ["}", :inline_delimiter],
102
+ [:close, :inline], [" d", :content], ["\"", :delimiter], [:close, :string],
103
+ [" ", :space], ["if", :reserved], [" ", :space], ["@c", :instance_variable],
104
+ ["}", :inline_delimiter], [:close, :inline], [" d ", :content], [:open, :inline],
105
+ ["\#{", :inline_delimiter], ["@e", :instance_variable], ["}", :inline_delimiter],
106
+ [:close, :inline], ["; f.", :content], ["\"", :delimiter], [:close, :string]],
107
+ '[].each do |*args, &block|
108
+ self.class.define_method do
109
+ end
110
+ end' => [["[].", :operator], ["each", :ident], [" ", :space], ["do", :reserved], [" ", :space], ["|*", :operator], ["args", :ident], [",", :operator], [" ", :space], ["&", :operator], ["block", :ident], ["|", :operator], ["\n", :space],
111
+ ["self", :reserved], [".", :operator], ["class", :ident], [".", :operator], ["define_method", :ident], [" ", :space], ["do", :reserved], ["\n", :space],
112
+ ["end", :reserved], ["\n", :space],
113
+ ["end", :reserved]
114
+ ],
64
115
 
65
- ONE_LINERS = <<-RUBY.gsub(/^ */, "")
66
- %Q{str}
67
- %r<regexp>
68
- :symbol
69
- :@instance_var_symbol
70
- :@@class_var_symbol
71
- :$global_var_symbol
72
- :ConstantSymbol
73
- :+
74
- :if
75
- #!/usr/bin/env ruby
76
- %q[haha! [nesting [rocks] ] ! ]
77
- %Q[hehe! \#{ %Q]nesting \#{"really"} rocks] } ! ]
78
- some_string.to_i /\\s+/
79
- S = 'bla' * 100 + "\n" + "\t"*4
80
- :"\#{undef :blubb}\#@@cv"
81
- undef :"bla", /, :"\#{undef :blubb}\#@@cv"
82
- @hash.delete_if { |o,| yield(o) }
83
- "double quoted string"
84
- # comment
85
- "a \#{ b + "c"}"
86
- 42 if true
87
- /regexp with modifiers/xm
88
- a = ?s
89
- q = "\\n"
90
- call_something()
91
- a = 1 && 2 || 3
92
- @ivar = 123
93
- @@cvar = 345
94
- $gvar = 345
95
- float = 1.2345
96
- `shell`
97
- v = %w(w1 w2)
98
- "a\#{" b \#{@c} d" if @c} d \#{@e}; f."
99
- RUBY
116
+ 'class Qwe < Asd
117
+ alias qwe asd
118
+ module Sdf
119
+ def self.sm
120
+ end
121
+ end
122
+ end' => [["class", :reserved], [" ", :space], ["Qwe", :constant], [" ", :space], ["<", :operator], [" ", :space],
123
+ ["Asd", :constant], ["\n", :space],
124
+ ["alias", :reserved], [" ", :space], ["qwe", :ident], [" ", :space], ["asd", :ident], ["\n", :space],
125
+ ["module", :reserved], [" ", :space], ["Sdf", :constant], ["\n", :space],
126
+ ["def", :reserved], [" ", :space], ["self", :reserved], [".", :operator], ["sm", :ident], ["\n", :space],
127
+ ["end", :reserved], ["\n", :space],
128
+ ["end", :reserved], ["\n", :space],
129
+ ["end", :reserved]],
130
+ '=begin
131
+ heredoc1
132
+ =end' => [["=begin\nheredoc1\n=end", :comment]],
100
133
 
101
- # ONE_LINERS.split("\n").each do |src|
102
- # it "should parse `#{ src }' just as CodeRay parser does" do
103
- # reflexive_tokens(src).should == coderay_tokens(src)
104
- # end
105
- # end
134
+ '<<-QWE
135
+ QWE' =>
136
+ (RUBY_VERSION > '1.9.1' ?
137
+ [["<<-QWE", :heredoc_beg], ["\n", :space]] :
138
+ [["<<-QWE", :heredoc_beg], ["QWE", :heredoc_end], ["\n", :space]]),
106
139
 
140
+ 'if 1 > 0
141
+ elsif false
142
+ end' => [["if", :reserved], [" ", :space], ["1", :integer], [" ", :space], [">", :operator], [" ", :space], ["0", :integer], ["\n", :space], ["elsif", :reserved], [" ", :space], ["false", :reserved], ["\n", :space], ["end", :reserved]],
107
143
 
108
- it "generates CodeRay compatible token stream" do
109
- src = <<-RUBY.gsub(/^ */, "")
110
- #{ ONE_LINERS }
111
- [].each do |*args, &block|
112
- self.class.define_method do
113
- end
114
- end
115
- class Qwe < Asd
116
- alias qwe asd
117
- module Sdf
118
- def self.sm
119
- end
120
- end
121
- end
122
- =begin
123
- heredoc1
124
- =end
125
- <<-QWE
126
- QWE
127
- if 1 > 0
128
- elsif false
129
- end
130
- begin
131
- 42
132
- rescue Exception => e
133
- [] << 'q'
134
- end
135
- def `(cmd)
136
- end
137
- RUBY
138
- expected_tokens = [
139
- [:open, :string], ["%Q{", :delimiter], ["str", :content], ["}", :delimiter], [:close, :string], ["\n", :space],
140
- [:open, :regexp], ["%r<", :delimiter], ["regexp", :content], [">", :delimiter], [:close, :regexp], ["\n", :space],
141
- [:open, :symbol], [":", :delimiter], ["symbol", :content], [:close, :symbol], ["\n", :space],
142
- [:open, :symbol], [":", :delimiter], ["@instance_var_symbol", :content], [:close, :symbol], ["\n", :space],
143
- [:open, :symbol], [":", :delimiter], ["@@class_var_symbol", :content], [:close, :symbol], ["\n", :space],
144
- [:open, :symbol], [":", :delimiter], ["$global_var_symbol", :content], [:close, :symbol], ["\n", :space],
145
- [:open, :symbol], [":", :delimiter], ["ConstantSymbol", :content], [:close, :symbol], ["\n", :space],
146
- [:open, :symbol], [":", :delimiter], ["+", :content], [:close, :symbol], ["\n", :space],
147
- [:open, :symbol], [":", :delimiter], ["if", :content], [:close, :symbol], ["\n", :space],
148
- ["#!/usr/bin/env ruby\n", :comment], [:open, :string], ["%q[", :delimiter], ["haha! [nesting [rocks] ] ! ", :content], ["]", :delimiter], [:close, :string], ["\n", :space],
149
- [:open, :string], ["%Q[", :delimiter], ["hehe! ", :content], [:open, :inline], ["\#{", :inline_delimiter], [" ", :space], [:open, :string], ["%Q]", :delimiter], ["nesting ", :content], [:open, :inline], ["\#{", :inline_delimiter], [:open, :string], ["\"", :delimiter], ["really", :content], ["\"", :delimiter], [:close, :string], ["}", :inline_delimiter], [:close, :inline], [" rocks", :content], ["]", :delimiter], [:close, :string], [" ", :space], ["}", :inline_delimiter], [:close, :inline], [" ! ", :content], ["]", :delimiter], [:close, :string], ["\n", :space],
150
- ["some_string", :ident], [".", :operator], ["to_i", :ident], [" ", :space], [:open, :regexp], ["/", :delimiter], ["\\s+", :content], ["/", :delimiter], [:close, :regexp], ["\n", :space],
151
- ["S", :constant], [" ", :space], ["=", :operator], [" ", :space], [:open, :string], ["'", :delimiter], ["bla", :content], ["'", :delimiter], [:close, :string], [" ", :space], ["*", :operator], [" ", :space], ["100", :integer], [" ", :space], ["+", :operator], [" ", :space], [:open, :string], ["\"", :delimiter], ["\n", :content], ["\"", :delimiter], [:close, :string], [" ", :space], ["+", :operator], [" ", :space], [:open, :string], ["\"", :delimiter], ["\t", :content], ["\"", :delimiter], [:close, :string], ["*", :operator], ["4", :integer], ["\n", :space],
152
- [:open, :symbol], [":\"", :delimiter], [:open, :inline], ["\#{", :inline_delimiter], ["undef", :content], [:close, :symbol], [" ", :space], [:open, :symbol], [":", :delimiter], ["blubb", :content], [:close, :symbol], ["}", :inline_delimiter], [:close, :inline], ["#", :escape], ["@@cv", :class_variable], ["\"", :delimiter], [:close, :string], ["\n", :space],
153
- ["undef", :reserved], [" ", :space], [:open, :symbol], [":\"", :delimiter], ["bla", :content], ["\"", :delimiter], [:close, :symbol], [",", :operator], [" ", :space], ["/,", :operator], [" ", :space], [:open, :symbol], [":\"", :delimiter], [:open, :inline], ["\#{", :inline_delimiter], ["undef", :content], [:close, :symbol], [" ", :space], [:open, :symbol], [":", :delimiter], ["blubb", :content], [:close, :symbol], ["}", :inline_delimiter], [:close, :inline], ["#", :escape], ["@@cv", :class_variable], ["\"", :delimiter], [:close, :string], ["\n", :space],
154
- ["@hash", :instance_variable], [".", :operator], ["delete_if", :ident], [" ", :space], ["{", :operator], [" ", :space], ["|", :operator], ["o", :ident], [",|", :operator], [" ", :space], ["yield", :reserved], ["(", :operator], ["o", :ident], [")", :operator], [" ", :space], ["}", :operator], ["\n", :space],
155
- [:open, :string], ["\"", :delimiter], ["double quoted string", :content], ["\"", :delimiter], [:close, :string], ["\n", :space],
156
- ["# comment\n", :comment], [:open, :string], ["\"", :delimiter], ["a ", :content], [:open, :inline], ["\#{", :inline_delimiter], [" ", :space], ["b", :ident], [" ", :space], ["+", :operator], [" ", :space], [:open, :string], ["\"", :delimiter], ["c", :content], ["\"", :delimiter], [:close, :string], ["}", :inline_delimiter], [:close, :inline], ["\"", :delimiter], [:close, :string], ["\n", :space],
157
- ["42", :integer], [" ", :space], ["if", :reserved], [" ", :space], ["true", :reserved], ["\n", :space],
158
- [:open, :regexp], ["/", :delimiter], ["regexp with modifiers", :content], ["/xm", :delimiter], [:close, :regexp], ["\n", :space],
159
- ["a", :ident], [" ", :space], ["=", :operator], [" ", :space], ["?s", :integer], ["\n", :space],
160
- ["q", :ident], [" ", :space], ["=", :operator], [" ", :space], [:open, :string], ["\"", :delimiter], ["\\n", :content], ["\"", :delimiter], [:close, :string], ["\n", :space],
161
- ["call_something", :ident], ["()", :operator], ["\n", :space],
162
- ["a", :ident], [" ", :space], ["=", :operator], [" ", :space], ["1", :integer], [" ", :space], ["&&", :operator], [" ", :space], ["2", :integer], [" ", :space], ["||", :operator], [" ", :space], ["3", :integer], ["\n", :space],
163
- ["@ivar", :instance_variable], [" ", :space], ["=", :operator], [" ", :space], ["123", :integer], ["\n", :space],
164
- ["@@cvar", :class_variable], [" ", :space], ["=", :operator], [" ", :space], ["345", :integer], ["\n", :space],
165
- ["$gvar", :global_variable], [" ", :space], ["=", :operator], [" ", :space], ["345", :integer], ["\n", :space],
166
- ["float", :ident], [" ", :space], ["=", :operator], [" ", :space], ["1.2345", :float], ["\n", :space],
167
- [:open, :shell], ["`", :delimiter], ["shell", :content], ["`", :delimiter], [:close, :shell], ["\n", :space],
168
- ["v", :ident], [" ", :space], ["=", :operator], [" ", :space], ["%w(w1 w2)", :content], ["\n", :space],
169
- [:open, :string], ["\"", :delimiter], ["a", :content], [:open, :inline], ["\#{", :inline_delimiter], [:open, :string], ["\"", :delimiter], [" b ", :content], [:open, :inline], ["\#{", :inline_delimiter], ["@c", :instance_variable], ["}", :inline_delimiter], [:close, :inline], [" d", :content], ["\"", :delimiter], [:close, :string], [" ", :space], ["if", :reserved], [" ", :space], ["@c", :instance_variable], ["}", :inline_delimiter], [:close, :inline], [" d ", :content], [:open, :inline], ["\#{", :inline_delimiter], ["@e", :instance_variable], ["}", :inline_delimiter], [:close, :inline], ["; f.", :content], ["\"", :delimiter], [:close, :string], ["\n\n", :space], ["[].", :operator], ["each", :ident], [" ", :space], ["do", :reserved], [" ", :space], ["|*", :operator], ["args", :ident], [",", :operator], [" ", :space], ["&", :operator], ["block", :ident], ["|", :operator], ["\n", :space],
170
- ["self", :reserved], [".", :operator], ["class", :ident], [".", :operator], ["define_method", :ident], [" ", :space], ["do", :reserved], ["\n", :space],
171
- ["end", :reserved], ["\n", :space],
172
- ["end", :reserved], ["\n", :space],
173
- ["class", :reserved], [" ", :space], ["Qwe", :constant], [" ", :space], ["<", :operator], [" ", :space], ["Asd", :constant], ["\n", :space],
174
- ["alias", :reserved], [" ", :space], ["qwe", :ident], [" ", :space], ["asd", :ident], ["\n", :space],
175
- ["module", :reserved], [" ", :space], ["Sdf", :constant], ["\n", :space],
176
- ["def", :reserved], [" ", :space], ["self", :reserved], [".", :operator], ["sm", :ident], ["\n", :space],
177
- ["end", :reserved], ["\n", :space],
178
- ["end", :reserved], ["\n", :space],
179
- ["end", :reserved], ["\n", :space],
180
- ["=begin\nheredoc1\n=end\n", :comment], ["<<-QWE", :heredoc_beg], ["\n", :space],
181
- ["if", :reserved], [" ", :space], ["1", :integer], [" ", :space], [">", :operator], [" ", :space], ["0", :integer], ["\n", :space],
182
- ["elsif", :reserved], [" ", :space], ["false", :reserved], ["\n", :space],
183
- ["end", :reserved], ["\n", :space],
184
- ["begin", :reserved], ["\n", :space],
185
- ["42", :integer], ["\n", :space],
186
- ["rescue", :reserved], [" ", :space], ["Exception", :constant], [" ", :space], ["=>", :operator], [" ", :space], ["e", :ident], ["\n", :space],
187
- ["[]", :operator], [" ", :space], ["<<", :operator], [" ", :space], [:open, :string], ["'", :delimiter], ["q", :content], ["'", :delimiter], [:close, :string], ["\n", :space],
188
- ["end", :reserved], ["\n", :space],
189
- ["def", :reserved], [" ", :space], ["`", :method], ["(", :operator], ["cmd", :ident], [")", :operator], ["\n", :space],
190
- ["end", :reserved], ["\n", :space]]
191
- reflexive_tokens_without_meta_and_tags(src).should == expected_tokens
144
+ 'begin
145
+ 42
146
+ rescue Exception => e
147
+ [] << \'q\'
148
+ end' => [["begin", :reserved], ["\n", :space], ["42", :integer], ["\n", :space], ["rescue", :reserved], [" ", :space], ["Exception", :constant], [" ", :space], ["=>", :operator], [" ", :space], ["e", :ident], ["\n", :space], ["[]", :operator], [" ", :space], ["<<", :operator], [" ", :space], [:open, :string], ["'", :delimiter], ["q", :content], ["'", :delimiter], [:close, :string], ["\n", :space], ["end", :reserved]],
149
+
150
+ 'def `(cmd)
151
+ end' => [["def", :reserved], [" ", :space], ["`", :method], ["(", :operator], ["cmd", :ident], [")", :operator], ["\n", :space], ["end", :reserved]],
152
+ }
153
+
154
+ SOURCE_TO_TOKENS.each do |source, tokens|
155
+ it "parses #{ source } just as CodeRay parser does" do
156
+ reflexive_tokens_without_meta_and_tags(source.dup.gsub(/^ */, "")).should == tokens
157
+ end
192
158
  end
193
159
  end
194
160
 
@@ -2,6 +2,30 @@ require "reflexive/helpers"
2
2
  require "reflexive/constantize"
3
3
  require "reflexive/descendants"
4
4
 
5
+ # define all the fixtures here so that tests won't step on each other's toes
6
+ module M1
7
+ class C1
8
+ end
9
+ module M2
10
+ module M3
11
+ class C2
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ class X2 ; end
18
+ class A2 < X2; end
19
+ class B2 < X2; end
20
+
21
+ module M2
22
+ end
23
+
24
+ class C2
25
+ end
26
+
27
+ C2.extend(M2)
28
+
5
29
  describe "Reflexive.loaded_features_lookup" do
6
30
  before(:all) do
7
31
  @native_feature = $LOADED_FEATURES.detect { |f| f =~ /\.so\z/ }
@@ -33,17 +57,6 @@ describe "Reflexive.loaded_features_lookup" do
33
57
  end
34
58
 
35
59
  describe "Reflexive.constant_lookup" do
36
- module M1
37
- class C1
38
- end
39
- module M2
40
- module M3
41
- class C2
42
- end
43
- end
44
- end
45
- end
46
-
47
60
  it "looks up top-level constants" do
48
61
  Reflexive.constant_lookup("::String", "Some::Ignored::Scope").should == ::String
49
62
  end
@@ -76,18 +89,6 @@ describe "Reflexive.load_path_lookup" do
76
89
  end
77
90
 
78
91
  describe "Reflexive.descendants" do
79
- class X2 ; end
80
- class A2 < X2; end
81
- class B2 < X2; end
82
-
83
- module M2
84
- end
85
-
86
- class C2
87
- end
88
-
89
- C2.extend(M2)
90
-
91
92
  it "finds class descendant" do
92
93
  Reflexive.descendants(X2).should =~ [B2, A2]
93
94
  end
data/spec/ripper_spec.rb CHANGED
@@ -2,6 +2,10 @@ require "ripper"
2
2
 
3
3
  require File.expand_path("../sexp_builder_with_scanner_events", __FILE__)
4
4
 
5
+ def bodystmt_sym
6
+ RUBY_VERSION > '1.9.1' ? :bodystmt : :body_stmt
7
+ end
8
+
5
9
  describe Ripper do
6
10
  def events_tree(src)
7
11
  parser = SexpBuilderWithScannerEvents.new(src)
@@ -21,7 +25,8 @@ describe Ripper do
21
25
  end
22
26
  end
23
27
 
24
- BODYSTMT_VOID = [:bodystmt, [[:void_stmt]], nil, nil, nil].freeze
28
+ BODYSTMT_VOID = [bodystmt_sym, [[:void_stmt]], nil, nil, nil].freeze
29
+
25
30
  PARAMS_VOID = [:params, nil, nil, nil, nil, nil].freeze
26
31
 
27
32
  describe "parser events" do
@@ -62,7 +67,7 @@ describe Ripper do
62
67
  [:rest_param, {:ident=>"r"}],
63
68
  [{:ident=>"a2"}],
64
69
  [:blockarg, {:ident=>"b"}]]],
65
- [:bodystmt,
70
+ [bodystmt_sym,
66
71
  [[:void_stmt]],
67
72
  [:rescue,
68
73
  [:mrhs_new_from_args,
@@ -145,17 +150,18 @@ describe Ripper do
145
150
  {:ident=>"v1"})
146
151
  block_variables("m do |;v1,v2| end",
147
152
  {:ident=>"v1"}, {:ident=>"v2"})
148
- end
153
+ end if RUBY_VERSION > '1.9.1'
149
154
 
150
155
  specify "tOROP => blockvar_new(params_new(Qnil,Qnil,Qnil,Qnil,Qnil), Qnil);" do
151
156
  block_variables("m do || end", nil)
152
157
  end
153
158
 
159
+
154
160
  specify "'|' block_param opt_bv_decl '|' => blockvar_new(escape_Qundef($2), escape_Qundef($3));" do
155
161
  block_params_and_variables("m do |a,o=1,*r,a2,&b;v1,v2| end",
156
162
  [f_arg, f_block_optarg, f_rest_arg, f_arg2, opt_f_block_arg],
157
163
  [{:ident=>"v1"}, {:ident=>"v2"}])
158
- end
164
+ end if RUBY_VERSION > '1.9.1'
159
165
  end
160
166
 
161
167
  describe "block params according to parse.y" do
data/views/dashboard.erb CHANGED
@@ -32,7 +32,8 @@
32
32
  <% favorites = filter_existing_constants(%w(Rails ActiveSupport ActiveResource
33
33
  ActiveRecord ActionView ActionController ActionDispatch ActionMailer ActiveModel
34
34
  Sinatra DataMapper Sequel Rack Arel Capistrano Gem Haml Sass Hpricot Nokogiri
35
- Rack Rake Rcov RDoc)) %>
35
+ Rack Rake Rcov RDoc
36
+ CGI Date Net REXML URI YAML FileUtils OpenStruct Pathname Time)) %>
36
37
  <%= content_tag(:pre,
37
38
  constants_list(nil, favorites)) %>
38
39
  </div>
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reflexive
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 5
9
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
10
11
  platform: ruby
11
12
  authors:
12
13
  - Evgeniy Dolzhenko
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 0
30
32
  version: "0"
@@ -38,6 +40,7 @@ dependencies:
38
40
  requirements:
39
41
  - - ">="
40
42
  - !ruby/object:Gem::Version
43
+ hash: 3
41
44
  segments:
42
45
  - 0
43
46
  version: "0"
@@ -51,6 +54,7 @@ dependencies:
51
54
  requirements:
52
55
  - - ">="
53
56
  - !ruby/object:Gem::Version
57
+ hash: 3
54
58
  segments:
55
59
  - 0
56
60
  version: "0"
@@ -64,6 +68,7 @@ dependencies:
64
68
  requirements:
65
69
  - - ">="
66
70
  - !ruby/object:Gem::Version
71
+ hash: 3
67
72
  segments:
68
73
  - 0
69
74
  version: "0"
@@ -77,6 +82,7 @@ dependencies:
77
82
  requirements:
78
83
  - - ">="
79
84
  - !ruby/object:Gem::Version
85
+ hash: 3
80
86
  segments:
81
87
  - 0
82
88
  version: "0"
@@ -90,6 +96,7 @@ dependencies:
90
96
  requirements:
91
97
  - - "="
92
98
  - !ruby/object:Gem::Version
99
+ hash: -690468206
93
100
  segments:
94
101
  - 3
95
102
  - 0
@@ -106,6 +113,7 @@ dependencies:
106
113
  requirements:
107
114
  - - "="
108
115
  - !ruby/object:Gem::Version
116
+ hash: -44051750
109
117
  segments:
110
118
  - 2
111
119
  - 0
@@ -123,6 +131,7 @@ dependencies:
123
131
  requirements:
124
132
  - - ">="
125
133
  - !ruby/object:Gem::Version
134
+ hash: 3
126
135
  segments:
127
136
  - 0
128
137
  version: "0"
@@ -143,6 +152,7 @@ files:
143
152
  - lib/reflexive/coderay_ruby_scanner.rb
144
153
  - lib/reflexive/columnizer.rb
145
154
  - lib/reflexive/constantize.rb
155
+ - lib/reflexive/core_ext/kernel/singleton_class.rb
146
156
  - lib/reflexive/descendants.rb
147
157
  - lib/reflexive/faster_open_struct.rb
148
158
  - lib/reflexive/helpers.rb
@@ -170,7 +180,6 @@ files:
170
180
  - spec/coderay_ruby_scanner_spec.rb
171
181
  - spec/io_interceptor.rb
172
182
  - spec/methods_spec.rb
173
- - spec/method_lookup_spec.rb
174
183
  - spec/rails_integration_spec.rb
175
184
  - spec/rails_integration_spec_helper.rb
176
185
  - spec/reflexive_ripper_spec.rb
@@ -179,7 +188,6 @@ files:
179
188
  - spec/ripper_spec.rb
180
189
  - spec/sexp_builder_with_scanner_events.rb
181
190
  - spec/shell_out.rb
182
- - spec/spec_helper.rb
183
191
  - reflexive.gemspec
184
192
  - Rakefile
185
193
  - Gemfile
@@ -198,6 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
206
  requirements:
199
207
  - - ">="
200
208
  - !ruby/object:Gem::Version
209
+ hash: 49
201
210
  segments:
202
211
  - 1
203
212
  - 9
@@ -208,13 +217,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
217
  requirements:
209
218
  - - ">="
210
219
  - !ruby/object:Gem::Version
220
+ hash: 3
211
221
  segments:
212
222
  - 0
213
223
  version: "0"
214
224
  requirements: []
215
225
 
216
226
  rubyforge_project:
217
- rubygems_version: 1.3.6.1
227
+ rubygems_version: 1.3.7
218
228
  signing_key:
219
229
  specification_version: 3
220
230
  summary: Reflexive
File without changes
data/spec/spec_helper.rb DELETED
@@ -1,4 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'rspec/expectations'
3
- require 'rspec/matchers'
4
- require 'rspec/core'