rcodetools 0.4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/CHANGES +18 -0
  2. data/README +34 -0
  3. data/README.emacs +54 -0
  4. data/README.method_analysis +13 -0
  5. data/README.vim +84 -0
  6. data/README.xmpfilter +202 -0
  7. data/Rakefile +123 -0
  8. data/Rakefile.method_analysis +30 -0
  9. data/THANKS +6 -0
  10. data/bin/rct-complete +37 -0
  11. data/bin/rct-doc +50 -0
  12. data/bin/rct-meth-args +392 -0
  13. data/bin/xmpfilter +75 -0
  14. data/icicles-rcodetools.el +31 -0
  15. data/lib/method_analyzer.rb +107 -0
  16. data/lib/rcodetools/completion.rb +282 -0
  17. data/lib/rcodetools/doc.rb +176 -0
  18. data/lib/rcodetools/options.rb +83 -0
  19. data/lib/rcodetools/xmpfilter.rb +208 -0
  20. data/lib/rcodetools/xmptestunitfilter.rb +197 -0
  21. data/rcodetools.el +162 -0
  22. data/rcodetools.vim +118 -0
  23. data/setup.rb +1585 -0
  24. data/test/data/add_markers-input.rb +2 -0
  25. data/test/data/add_markers-output.rb +2 -0
  26. data/test/data/bindings-input.rb +26 -0
  27. data/test/data/bindings-output.rb +31 -0
  28. data/test/data/completion-input.rb +1 -0
  29. data/test/data/completion-output.rb +2 -0
  30. data/test/data/completion_emacs-input.rb +1 -0
  31. data/test/data/completion_emacs-output.rb +5 -0
  32. data/test/data/completion_emacs_icicles-input.rb +1 -0
  33. data/test/data/completion_emacs_icicles-output.rb +5 -0
  34. data/test/data/doc-input.rb +1 -0
  35. data/test/data/doc-output.rb +1 -0
  36. data/test/data/method_analyzer-data.rb +33 -0
  37. data/test/data/method_args.data.rb +106 -0
  38. data/test/data/no_warnings-input.rb +3 -0
  39. data/test/data/no_warnings-output.rb +4 -0
  40. data/test/data/refe-input.rb +1 -0
  41. data/test/data/refe-output.rb +1 -0
  42. data/test/data/ri-input.rb +1 -0
  43. data/test/data/ri-output.rb +1 -0
  44. data/test/data/ri_emacs-input.rb +1 -0
  45. data/test/data/ri_emacs-output.rb +1 -0
  46. data/test/data/ri_vim-input.rb +1 -0
  47. data/test/data/ri_vim-output.rb +1 -0
  48. data/test/data/rspec-input.rb +48 -0
  49. data/test/data/rspec-output.rb +52 -0
  50. data/test/data/rspec_poetry-input.rb +48 -0
  51. data/test/data/rspec_poetry-output.rb +52 -0
  52. data/test/data/simple_annotation-input.rb +8 -0
  53. data/test/data/simple_annotation-output.rb +8 -0
  54. data/test/data/unit_test-input.rb +50 -0
  55. data/test/data/unit_test-output.rb +52 -0
  56. data/test/data/unit_test_poetry-input.rb +50 -0
  57. data/test/data/unit_test_poetry-output.rb +52 -0
  58. data/test/test_completion.rb +467 -0
  59. data/test/test_doc.rb +403 -0
  60. data/test/test_functional.rb +18 -0
  61. data/test/test_method_analyzer.rb +99 -0
  62. data/test/test_method_args.rb +134 -0
  63. data/test/test_run.rb +41 -0
  64. data/test/test_xmpfilter.rb +36 -0
  65. data/test/test_xmptestunitfilter.rb +84 -0
  66. metadata +139 -0
@@ -0,0 +1,134 @@
1
+ require 'test/unit'
2
+ module MethodArgsScriptConfig
3
+ DIR = File.join(File.dirname(__FILE__))
4
+ SCRIPT = File.join(DIR, "..", "bin", "rct-meth-args")
5
+ DATAFILE = File.join(DIR, "data/method_args.data.rb")
6
+ end
7
+
8
+ class TestMethodArgs < Test::Unit::TestCase
9
+ # (find-sh "cd ..; method_args.rb -n test/method_args.data.rb")
10
+ include MethodArgsScriptConfig
11
+ @@result = `ruby '#{SCRIPT}' -n '#{DATAFILE}'`.split(/\n/)
12
+ @@result.delete_if{ |line| line =~ /Digest/ and line !~ /method_in_Digest_Base/ }
13
+ @@result.delete "zzzz OK"
14
+
15
+ @@expected = <<XXX.split(/\n/)
16
+ method_args.data.rb:3:FixedArgsMethods.singleton (a1)
17
+ method_args.data.rb:4:FixedArgsMethods#initialize (arg)
18
+ method_args.data.rb:5:FixedArgsMethods#f (a1)
19
+ method_args.data.rb:6:FixedArgsMethods#b (a1, &block)
20
+ method_args.data.rb:7:FixedArgsMethods#defmethod (...)
21
+ method_args.data.rb:8:FixedArgsMethods#by_attr_accessor
22
+ method_args.data.rb:8:FixedArgsMethods#by_attr_accessor= (value)
23
+ method_args.data.rb:9:FixedArgsMethods#by_attr_false
24
+ method_args.data.rb:10:FixedArgsMethods#by_attr_true
25
+ method_args.data.rb:10:FixedArgsMethods#by_attr_true= (value)
26
+ method_args.data.rb:11:FixedArgsMethods#by_attr_reader_1
27
+ method_args.data.rb:11:FixedArgsMethods#by_attr_reader_2
28
+ method_args.data.rb:12:FixedArgsMethods#by_attr_writer= (value)
29
+ method_args.data.rb:13:FixedArgsMethods#private_meth (x)
30
+ method_args.data.rb:16:FixedArgsMethods.singleton_attr_accessor
31
+ method_args.data.rb:16:FixedArgsMethods.singleton_attr_accessor= (value)
32
+ method_args.data.rb:17:FixedArgsMethods.singleton_defmethod (...)
33
+ method_args.data.rb:22:VariableArgsMethods#s (a1, *splat)
34
+ method_args.data.rb:23:VariableArgsMethods#sb (a1, *splat, &block)
35
+ method_args.data.rb:24:VariableArgsMethods#d (a1, default = nil)
36
+ method_args.data.rb:25:VariableArgsMethods#ds (a1, default = nil, *splat)
37
+ method_args.data.rb:26:VariableArgsMethods#dsb (a1, default = nil, *splat, &block)
38
+ method_args.data.rb:27:VariableArgsMethods#db (a1, default = nil, &block)
39
+ method_args.data.rb:31:Fixnum#method_in_Fixnum (arg1, arg2)
40
+ method_args.data.rb:32:Fixnum.singleton_method_in_Fixnum (arg1, arg2)
41
+ method_args.data.rb:35:Bignum#method_in_Bignum (arg1, arg2)
42
+ method_args.data.rb:38:Float#method_in_Float (arg1, arg2)
43
+ method_args.data.rb:41:Symbol#method_in_Symbol (arg1, arg2)
44
+ method_args.data.rb:44:Binding#method_in_Binding (arg1, arg2)
45
+ method_args.data.rb:47:UnboundMethod#method_in_UnboundMethod (arg1, arg2)
46
+ method_args.data.rb:50:Method#method_in_Method (arg1, arg2)
47
+ method_args.data.rb:53:Proc#method_in_Proc (arg1, arg2)
48
+ method_args.data.rb:56:Continuation#method_in_Continuation (arg1, arg2)
49
+ method_args.data.rb:59:Thread#method_in_Thread (arg1, arg2)
50
+ method_args.data.rb:66:TrueClass#method_in_TrueClass (arg1, arg2)
51
+ method_args.data.rb:69:NilClass#method_in_NilClass (arg1, arg2)
52
+ method_args.data.rb:72:Struct#method_in_Struct (arg1, arg2)
53
+ Digest::Base#method_in_Digest_Base (...)
54
+ AnAbstractClass#method_in_AnAbstractClass (...)
55
+ method_args.data.rb:93:include AClass <= VariableArgsMethods
56
+ method_args.data.rb:94:extend AClass <- VariableArgsMethods
57
+ method_args.data.rb:97:class ASubClass < AClass
58
+ method_args.data.rb:100:class <Struct: a,b> < Struct
59
+ method_args.data.rb:101:class SubclassOfStructA < StructA
60
+ method_args.data.rb:102:SubclassOfStructA#method_in_b
61
+ method_args.data.rb:104:class <Struct: c> < Struct
62
+ method_args.data.rb:104:class StructSubclass < <Struct: c>
63
+ method_args.data.rb:105:StructSubclass#method_in_c
64
+ XXX
65
+
66
+ # To avoid dependency of pwd.
67
+ module StripDir
68
+ def strip_dir!
69
+ slice! %r!^.*/!
70
+ self
71
+ end
72
+ end
73
+
74
+ @@expected.each do |line|
75
+ begin
76
+ file_lineno_klass_meth, rest = line.split(/\s+/,2)
77
+ if file_lineno_klass_meth =~ /:/
78
+ file, lineno, klass_meth = file_lineno_klass_meth.split(/:/)
79
+ klass_meth = rest if %w[class include extend].include? klass_meth
80
+ else # filename/lineno is unknown
81
+ klass_meth = file_lineno_klass_meth
82
+ end
83
+
84
+ test_method_name = "test_" + klass_meth
85
+ define_method(test_method_name) do
86
+ actual = @@result.grep(/#{klass_meth}/)[0].extend(StripDir).strip_dir!
87
+ assert_equal line, actual
88
+ end
89
+ rescue Exception
90
+ end
91
+ end
92
+
93
+ def test_all_tests
94
+ assert_equal @@expected.length, @@result.length, @@result.join("\n")
95
+ end
96
+
97
+ def test_without_n_option
98
+ first_line = "FixedArgsMethods.singleton (a1)"
99
+ command_output = `ruby '#{SCRIPT}' '#{DATAFILE}'`
100
+ assert_match(/\A#{Regexp.quote(first_line)}\n/, command_output)
101
+ end
102
+ end
103
+
104
+
105
+ class TestTAGS < Test::Unit::TestCase
106
+ include MethodArgsScriptConfig
107
+
108
+ @@TAGS = `ruby '#{SCRIPT}' -t '#{DATAFILE}'`
109
+ def test_filename
110
+ # check whether full path is passed.
111
+ assert_match %r!^\cl\n/.+method_args.data.rb,\d!, @@TAGS
112
+ end
113
+
114
+ def test_singleton_method
115
+ # including line/byte test
116
+ assert @@TAGS.include?(" def self.singleton(a1) end::FixedArgsMethods.singleton3,45")
117
+ end
118
+
119
+ def test_instance_method
120
+ assert @@TAGS.include?(" def initialize(arg) end::FixedArgsMethods#initialize4,74")
121
+ end
122
+
123
+ def test_include
124
+ assert_match(/^ include VariableArgsMethods::AClass/, @@TAGS)
125
+ end
126
+
127
+ def test_extend
128
+ assert_match(/^ extend VariableArgsMethods::AClass/, @@TAGS)
129
+ end
130
+
131
+ def test_inheritance
132
+ assert_match(/^class ASubClass < AClass::ASubClass/, @@TAGS)
133
+ end
134
+ end
data/test/test_run.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'test/unit'
2
+ require 'rcodetools/xmpfilter'
3
+ require 'rcodetools/xmptestunitfilter'
4
+ require 'rcodetools/completion'
5
+ require 'rcodetools/doc'
6
+ require 'rcodetools/options'
7
+ require 'stringio'
8
+
9
+ class TestRun < Test::Unit::TestCase
10
+ tests = {
11
+ :simple_annotation => {:klass => XMPFilter},
12
+ :unit_test => {:klass => XMPTestUnitFilter},
13
+ :rspec => {:klass => XMPRSpecFilter, :interpreter => "spec"},
14
+ :rspec_poetry => {:klass => XMPRSpecFilter, :interpreter => "spec", :use_parentheses => false},
15
+ :no_warnings => {:klass => XMPFilter, :warnings => false},
16
+ :bindings => {:klass => XMPTestUnitFilter, :use_parentheses => false},
17
+ :unit_test_poetry => {:klass => XMPTestUnitFilter, :use_parentheses => false},
18
+ :add_markers => {:klass => XMPAddMarkers},
19
+
20
+ :completion => {:klass => XMPCompletionFilter, :lineno => 1},
21
+ :completion_emacs => {:klass => XMPCompletionEmacsFilter, :lineno => 1},
22
+ :completion_emacs_icicles => {:klass => XMPCompletionEmacsIciclesFilter, :lineno => 1},
23
+
24
+ :doc => {:klass => XMPDocFilter, :lineno => 1},
25
+ :refe => {:klass => XMPReFeFilter, :lineno => 1},
26
+ :ri => {:klass => XMPRiFilter, :lineno => 1},
27
+ :ri_emacs => {:klass => XMPRiEmacsFilter, :lineno => 1},
28
+ :ri_vim => {:klass => XMPRiVimFilter, :lineno => 1},
29
+
30
+ }
31
+ tests.each_pair do |test, opts|
32
+ define_method("test_#{test}") do
33
+ dir = File.expand_path(File.dirname(__FILE__))
34
+ inputfile = "#{dir}/data/#{test}-input.rb"
35
+ outputfile = "#{dir}/data/#{test}-output.rb"
36
+ sio = StringIO.new
37
+ sio.puts opts[:klass].run(File.read(inputfile), DEFAULT_OPTIONS.merge(opts))
38
+ assert_equal(File.read(outputfile), sio.string)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,36 @@
1
+
2
+ require 'test/unit'
3
+ $: << ".." << "../lib[s]"
4
+ require "rcodetools/xmpfilter"
5
+
6
+ class TestXMPFilter < Test::Unit::TestCase
7
+ def setup
8
+ @xmp = XMPFilter.new
9
+ @marker = XMPFilter::MARKER
10
+ end
11
+
12
+ def test_extract_data
13
+ str = <<-EOF
14
+ #{@marker}[1] => Fixnum 42
15
+ #{@marker}[1] => Fixnum 0
16
+ #{@marker}[1] ==> var
17
+ #{@marker}[1] ==> var2
18
+ #{@marker}[4] ==> var3
19
+ #{@marker}[2] ~> some exception
20
+ #{@marker}[10] => Fixnum 42
21
+ EOF
22
+ data = @xmp.extract_data(str)
23
+ assert_kind_of(XMPFilter::RuntimeData, data)
24
+ assert_equal([[1, [["Fixnum", "42"], ["Fixnum", "0"]]], [10, [["Fixnum", "42"]]]], data.results.sort)
25
+ assert_equal([[2, ["some exception"]]], data.exceptions.sort)
26
+ assert_equal([[1, ["var", "var2"]], [4, ["var3"]]], data.bindings.sort)
27
+ end
28
+ end
29
+
30
+ class TestXMPAddMarkers < Test::Unit::TestCase
31
+
32
+
33
+ def test_
34
+
35
+ end
36
+ end
@@ -0,0 +1,84 @@
1
+
2
+ require 'test/unit'
3
+ $: << ".." << "../lib"
4
+ require "rcodetools/xmptestunitfilter"
5
+
6
+ class TestXMPTestUnitFilter < Test::Unit::TestCase
7
+ def setup
8
+ @xmp = XMPTestUnitFilter.new
9
+ end
10
+
11
+ ANNOTATION_VAR_INFERENCE_INPUT = <<EOF
12
+ arr = []
13
+ X = Struct.new(:foo, :bar)
14
+ x = X.new("foo", "bar")
15
+ arr << x
16
+ arr # \=>
17
+ arr.last # \=>
18
+ EOF
19
+ ANNOTATION_VAR_INFERENCE_OUTPUT = <<EOF
20
+ arr = []
21
+ X = Struct.new(:foo, :bar)
22
+ x = X.new(\"foo\", \"bar\")
23
+ arr << x
24
+ assert_equal([x], arr)
25
+ assert_kind_of(Array, arr)
26
+ assert_equal(\"[#<struct X foo=\\\"foo\\\", bar=\\\"bar\\\">]\", arr.inspect)
27
+ assert_equal(x, arr.last)
28
+ assert_kind_of(X, arr.last)
29
+ assert_equal(\"#<struct X foo=\\\"foo\\\", bar=\\\"bar\\\">\", arr.last.inspect)
30
+ EOF
31
+
32
+ def test_annotation_var_inference
33
+ assert_equal(ANNOTATION_VAR_INFERENCE_OUTPUT,
34
+ @xmp.annotate(ANNOTATION_VAR_INFERENCE_INPUT).join(""))
35
+ end
36
+
37
+ def test_equality_assertions
38
+ assert_equal(["a = 1\n", "assert_equal(1, a)"], @xmp.annotate("a = 1\na # \=>"))
39
+ assert_equal(["a = {1,2}\n", "assert_equal({1=>2}, a)"],
40
+ @xmp.annotate("a = {1,2}\na # \=>"))
41
+ assert_equal(["a = [1,2]\n", "assert_equal([1, 2], a)"],
42
+ @xmp.annotate("a = [1,2]\na # \=>"))
43
+ assert_equal(["a = 'foo'\n", "assert_equal(\"foo\", a)"],
44
+ @xmp.annotate("a = 'foo'\na # \=>"))
45
+ assert_equal(["a = 1.0\n", "assert_in_delta(1.0, a, 0.0001)"],
46
+ @xmp.annotate("a = 1.0\na # \=>"))
47
+ end
48
+
49
+ def test_raise_assertion
50
+ code = <<EOF
51
+ class NoGood < Exception; end
52
+ raise NoGood # \=>
53
+ EOF
54
+ assert_equal(["class NoGood < Exception; end\n",
55
+ "assert_raise(NoGood){raise NoGood}\n"], @xmp.annotate(code))
56
+ end
57
+
58
+ def test_assert_nil
59
+ assert_equal(["a = nil\n", "assert_nil(a)"], @xmp.annotate("a = nil\na # \=>"))
60
+ end
61
+
62
+ def test_poetry_mode
63
+ code = <<EOF
64
+ a = 1
65
+ a # \=>
66
+ a = 1.0
67
+ a # \=>
68
+ raise "foo" # \=>
69
+ a = nil
70
+ a # \=>
71
+ EOF
72
+ output = <<EOF
73
+ a = 1
74
+ assert_equal 1, a
75
+ a = 1.0
76
+ assert_in_delta 1.0, a, 0.0001
77
+ assert_raise(RuntimeError){raise "foo"}
78
+ a = nil
79
+ assert_nil a
80
+ EOF
81
+ xmp = XMPTestUnitFilter.new(:use_parentheses => false)
82
+ assert_equal(output, xmp.annotate(code).join)
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: rcodetools
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.4.0.0
7
+ date: 2006-12-29 00:00:00 +01:00
8
+ summary: rcodetools is a collection of Ruby code manipulation tools
9
+ require_paths:
10
+ - lib
11
+ email: "\"rubikitch\" <rubikitch@ruby-lang.org>, \"Mauricio Fernandez\" <mfp@acm.org>"
12
+ homepage: http://eigenclass.org/hiki.rb?rcodetools
13
+ rubyforge_project:
14
+ description: "rcodetools is a collection of Ruby code manipulation tools. It includes xmpfilter and editor-independent Ruby development helper tools, as well as emacs and vim interfaces. Currently, rcodetools comprises: * xmpfilter: Automagic Test::Unit assertions/RSpec expectations and code annotations * rct-complete: Accurate method/class/constant etc. completions * rct-doc: Document browsing and code navigator * rct-meth-args: Precise method info (meta-prog. aware) and TAGS generation"
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message: |+
29
+
30
+ ==============================================================================
31
+
32
+ rcodetools will work better if you use it along with FastRI, an alternative to
33
+ the standard 'ri' documentation browser which features intelligent searching,
34
+ better RubyGems integration, vastly improved performance, remote queries via
35
+ DRb... You can find it at http://eigenclass.org/hiki.rb?fastri and it is also
36
+ available in RubyGems format:
37
+
38
+ gem install fastri
39
+
40
+ Read README.emacs and README.vim for information on how to integrate
41
+ rcodetools in your editor.
42
+
43
+ ==============================================================================
44
+
45
+ authors:
46
+ - rubikitch and Mauricio Fernandez
47
+ files:
48
+ - bin/rct-complete
49
+ - bin/rct-doc
50
+ - bin/xmpfilter
51
+ - bin/rct-meth-args
52
+ - lib/method_analyzer.rb
53
+ - lib/rcodetools/completion.rb
54
+ - lib/rcodetools/doc.rb
55
+ - lib/rcodetools/options.rb
56
+ - lib/rcodetools/xmptestunitfilter.rb
57
+ - lib/rcodetools/xmpfilter.rb
58
+ - CHANGES
59
+ - rcodetools.vim
60
+ - rcodetools.el
61
+ - icicles-rcodetools.el
62
+ - README
63
+ - README.emacs
64
+ - README.vim
65
+ - README.xmpfilter
66
+ - README.method_analysis
67
+ - THANKS
68
+ - Rakefile
69
+ - Rakefile.method_analysis
70
+ - setup.rb
71
+ - test/test_functional.rb
72
+ - test/test_xmpfilter.rb
73
+ - test/test_xmptestunitfilter.rb
74
+ - test/test_doc.rb
75
+ - test/test_completion.rb
76
+ - test/test_method_args.rb
77
+ - test/test_method_analyzer.rb
78
+ - test/test_run.rb
79
+ - test/data/simple_annotation-input.rb
80
+ - test/data/unit_test-input.rb
81
+ - test/data/rspec-input.rb
82
+ - test/data/simple_annotation-output.rb
83
+ - test/data/unit_test-output.rb
84
+ - test/data/no_warnings-input.rb
85
+ - test/data/no_warnings-output.rb
86
+ - test/data/rspec-output.rb
87
+ - test/data/bindings-input.rb
88
+ - test/data/bindings-output.rb
89
+ - test/data/method_analyzer-data.rb
90
+ - test/data/add_markers-input.rb
91
+ - test/data/add_markers-output.rb
92
+ - test/data/completion-input.rb
93
+ - test/data/completion-output.rb
94
+ - test/data/completion_emacs-input.rb
95
+ - test/data/completion_emacs-output.rb
96
+ - test/data/doc-input.rb
97
+ - test/data/doc-output.rb
98
+ - test/data/refe-input.rb
99
+ - test/data/refe-output.rb
100
+ - test/data/ri-input.rb
101
+ - test/data/ri-output.rb
102
+ - test/data/ri_emacs-input.rb
103
+ - test/data/ri_emacs-output.rb
104
+ - test/data/ri_vim-input.rb
105
+ - test/data/ri_vim-output.rb
106
+ - test/data/rspec_poetry-input.rb
107
+ - test/data/rspec_poetry-output.rb
108
+ - test/data/unit_test_poetry-input.rb
109
+ - test/data/unit_test_poetry-output.rb
110
+ - test/data/method_args.data.rb
111
+ - test/data/completion_emacs_icicles-input.rb
112
+ - test/data/completion_emacs_icicles-output.rb
113
+ test_files:
114
+ - test/test_functional.rb
115
+ - test/test_xmpfilter.rb
116
+ - test/test_xmptestunitfilter.rb
117
+ - test/test_doc.rb
118
+ - test/test_completion.rb
119
+ - test/test_method_args.rb
120
+ - test/test_method_analyzer.rb
121
+ - test/test_run.rb
122
+ rdoc_options:
123
+ - --main
124
+ - README
125
+ - --title
126
+ - rcodetools
127
+ extra_rdoc_files:
128
+ - README
129
+ executables:
130
+ - rct-complete
131
+ - rct-doc
132
+ - xmpfilter
133
+ - rct-meth-args
134
+ extensions: []
135
+
136
+ requirements: []
137
+
138
+ dependencies: []
139
+