rcodetools 0.5.0.0 → 0.7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/CHANGES +14 -0
  2. data/README +63 -0
  3. data/README.TDC +158 -0
  4. data/README.ja +84 -0
  5. data/README.vim +11 -0
  6. data/Rakefile +15 -2
  7. data/THANKS +5 -0
  8. data/bin/rct-complete +4 -2
  9. data/bin/rct-doc +4 -2
  10. data/bin/rct-meth-args +1 -1
  11. data/bin/xmpfilter +7 -1
  12. data/icicles-rcodetools.el +2 -1
  13. data/lib/rcodetools/completion.rb +36 -18
  14. data/lib/rcodetools/doc.rb +3 -0
  15. data/lib/rcodetools/fork.rb +222 -0
  16. data/lib/rcodetools/fork_config.rb +26 -0
  17. data/lib/rcodetools/options.rb +34 -1
  18. data/lib/rcodetools/xmpfilter.rb +106 -18
  19. data/lib/rcodetools/xmptestunitfilter.rb +116 -55
  20. data/lib/ruby_toggle_file.rb +99 -0
  21. data/rcodetools.el +64 -9
  22. data/rcodetools.vim +41 -6
  23. data/test/data/completion_class_info-input.rb +1 -0
  24. data/test/data/completion_class_info-output.rb +10 -0
  25. data/test/data/completion_class_info_no_candidates-input.rb +1 -0
  26. data/test/data/completion_class_info_no_candidates-output.rb +1 -0
  27. data/test/data/completion_detect_rbtest-input.rb +7 -0
  28. data/test/data/completion_detect_rbtest-output.rb +2 -0
  29. data/test/data/completion_detect_rbtest2-input.rb +1 -0
  30. data/test/data/completion_detect_rbtest2-output.rb +2 -0
  31. data/test/data/completion_in_method-input.rb +3 -0
  32. data/test/data/completion_in_method-output.rb +1 -0
  33. data/test/data/completion_in_method-test.rb +6 -0
  34. data/test/data/completion_rbtest-input.rb +7 -0
  35. data/test/data/completion_rbtest-output.rb +2 -0
  36. data/test/data/doc_detect_rbtest-input.rb +1 -0
  37. data/test/data/doc_detect_rbtest-output.rb +1 -0
  38. data/test/data/doc_detect_rbtest2-input.rb +7 -0
  39. data/test/data/doc_detect_rbtest2-output.rb +1 -0
  40. data/test/data/doc_rbtest-input.rb +7 -0
  41. data/test/data/doc_rbtest-output.rb +1 -0
  42. data/test/data/rspec-input.rb +9 -9
  43. data/test/data/rspec-output.rb +21 -21
  44. data/test/data/rspec_poetry-input.rb +9 -9
  45. data/test/data/rspec_poetry-output.rb +21 -21
  46. data/test/data/sample_test_script.rb +9 -0
  47. data/test/data/unit_test_detect_rbtest-input.rb +50 -0
  48. data/test/data/unit_test_detect_rbtest-output.rb +52 -0
  49. data/test/data/unit_test_detect_rbtest2-input.rb +6 -0
  50. data/test/data/unit_test_detect_rbtest2-output.rb +6 -0
  51. data/test/data/unit_test_rbtest-input.rb +6 -0
  52. data/test/data/unit_test_rbtest-output.rb +6 -0
  53. data/test/test_completion.rb +37 -3
  54. data/test/test_doc.rb +2 -0
  55. data/test/test_functional.rb +75 -14
  56. data/test/test_options.rb +1 -0
  57. data/test/test_ruby_toggle_file.rb +125 -0
  58. data/test/test_run.rb +7 -3
  59. data/test/test_xmpfilter.rb +132 -5
  60. data/test/test_xmptestunitfilter.rb +1 -0
  61. metadata +76 -43
@@ -11,42 +11,42 @@ class X
11
11
  end
12
12
 
13
13
 
14
- context "Testing xmpfilter's expectation expansion" do
15
- setup do
14
+ describe "xmpfilter's expectation expansion" do
15
+ before do
16
16
  @o = X.new
17
17
  end
18
18
 
19
- specify "Should expand should_equal expectations" do
20
- @o.foo(true).should_be_a_kind_of X::Y
21
- @o.foo(true).inspect.should_equal "#<struct X::Y a=2>"
22
- @o.foo(true).a.should_equal 2
23
- @o.foo(false).should_equal 2
19
+ it "should expand should == expectations" do
20
+ @o.foo(true).should be_a_kind_of(X::Y)
21
+ @o.foo(true).inspect.should == "#<struct X::Y a=2>"
22
+ @o.foo(true).a.should == 2
23
+ @o.foo(false).should == 2
24
24
  end
25
25
 
26
- specify "Should expand should_raise expectations" do
27
- lambda{@o.bar}.should_raise RuntimeError
26
+ it "should expand should raise_error expectations" do
27
+ lambda{@o.bar}.should raise_error(RuntimeError)
28
28
  end
29
29
 
30
- specify "Should expand should_be_nil expectations" do
31
- @o.baz.should_be_nil
30
+ it "should expand should be_nil expectations" do
31
+ @o.baz.should be_nil
32
32
  end
33
33
 
34
- specify "Should expand correct expectations for complex values" do
35
- @o.babar.should_equal [1, 2]
34
+ it "should expand correct expectations for complex values" do
35
+ @o.babar.should == [1, 2]
36
36
  end
37
37
 
38
- specify "Should expand should_be_close expectations" do
39
- @o.fubar(10).should_be_close 101.0, 0.0001
38
+ it "should expand should be_close expectations" do
39
+ @o.fubar(10).should be_close(101.0, 0.0001)
40
40
  end
41
41
  end
42
42
 
43
- context "Testing binding" do
44
- specify "Should expand should_equal expectations" do
43
+ describe "xmpfilter's automagic binding detection" do
44
+ it "should expand should == expectations" do
45
45
  a = b = c = 1
46
46
  d = a
47
- d.should_equal a
48
- d.should_equal b
49
- d.should_equal c
50
- d.should_equal 1
47
+ d.should == a
48
+ d.should == b
49
+ d.should == c
50
+ d.should == 1
51
51
  end
52
52
  end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+ class TestSample < Test::Unit::TestCase
3
+ def test_sample0
4
+ assert(true)
5
+ end
6
+
7
+ def test_sample1
8
+ end
9
+ end
@@ -0,0 +1,50 @@
1
+
2
+ class X
3
+ Y = Struct.new(:a)
4
+ def foo(b); b ? Y.new(2) : 2 end
5
+ def bar; raise "No good" end
6
+ def baz; nil end
7
+ def fubar(x); x ** 2.0 + 1 end
8
+ def babar; [1,2] end
9
+ A = 1
10
+ A = 1
11
+ def difftype() [1, "s"] end
12
+ end
13
+
14
+
15
+ require 'test/unit'
16
+ class Test_X < Test::Unit::TestCase
17
+ def setup
18
+ @o = X.new
19
+ end
20
+
21
+ def test_foo
22
+ @o.foo(true) # =>
23
+ @o.foo(true).a # =>
24
+ @o.foo(false) # =>
25
+ end
26
+
27
+ def test_bar
28
+ @o.bar # =>
29
+ end
30
+
31
+ def test_baz
32
+ @o.baz # =>
33
+ end
34
+
35
+ def test_babar
36
+ @o.babar # =>
37
+ end
38
+
39
+ def test_fubar
40
+ @o.fubar(10) # =>
41
+ end
42
+
43
+ def test_difftype
44
+ for x in @o.difftype
45
+ x # =>
46
+ end
47
+ end
48
+
49
+ end
50
+
@@ -0,0 +1,52 @@
1
+
2
+ class X
3
+ Y = Struct.new(:a)
4
+ def foo(b); b ? Y.new(2) : 2 end
5
+ def bar; raise "No good" end
6
+ def baz; nil end
7
+ def fubar(x); x ** 2.0 + 1 end
8
+ def babar; [1,2] end
9
+ A = 1
10
+ A = 1 # !> already initialized constant A
11
+ def difftype() [1, "s"] end
12
+ end
13
+
14
+
15
+ require 'test/unit'
16
+ class Test_X < Test::Unit::TestCase
17
+ def setup
18
+ @o = X.new
19
+ end
20
+
21
+ def test_foo
22
+ assert_kind_of(X::Y, @o.foo(true))
23
+ assert_equal("#<struct X::Y a=2>", @o.foo(true).inspect)
24
+ assert_equal(2, @o.foo(true).a)
25
+ assert_equal(2, @o.foo(false))
26
+ end
27
+
28
+ def test_bar
29
+ assert_raise(RuntimeError){@o.bar}
30
+ end
31
+
32
+ def test_baz
33
+ assert_nil(@o.baz)
34
+ end
35
+
36
+ def test_babar
37
+ assert_equal([1, 2], @o.babar)
38
+ end
39
+
40
+ def test_fubar
41
+ assert_in_delta(101.0, @o.fubar(10), 0.0001)
42
+ end
43
+
44
+ def test_difftype
45
+ for x in @o.difftype
46
+ #xmpfilter: WARNING!! extra values ignored
47
+ assert_equal(1, x)
48
+ end
49
+ end
50
+
51
+ end
52
+
@@ -0,0 +1,6 @@
1
+ =begin test_bar
2
+ bar("bar") # =>
3
+ =end
4
+ def bar(s)
5
+ s.upcase
6
+ end
@@ -0,0 +1,6 @@
1
+ =begin test_bar
2
+ assert_equal("BAR", bar("bar"))
3
+ =end
4
+ def bar(s)
5
+ s.upcase
6
+ end
@@ -0,0 +1,6 @@
1
+ =begin test_bar
2
+ bar("bar") # =>
3
+ =end
4
+ def bar(s)
5
+ s.upcase
6
+ end
@@ -0,0 +1,6 @@
1
+ =begin test_bar
2
+ assert_equal("BAR", bar("bar"))
3
+ =end
4
+ def bar(s)
5
+ s.upcase
6
+ end
@@ -3,6 +3,7 @@ require 'rcodetools/completion'
3
3
  require 'test/unit'
4
4
 
5
5
  class TestXMPCompletionFilter < Test::Unit::TestCase
6
+ include Rcodetools
6
7
  def doit(code, lineno, column=nil, options={})
7
8
  xmp = XMPCompletionFilter.new options
8
9
  xmp.candidates(code, lineno, column).sort
@@ -29,12 +30,13 @@ EOC
29
30
  end
30
31
 
31
32
  def test_complete_method__in_not_passing_method
32
- ## FIXME I do not know how to handle not-passing method!!
33
- assert_equal([], doit(<<EOC, 2))
33
+ assert_raises(XMPCompletionFilter::NoCandidates) do
34
+ doit(<<EOC, 2)
34
35
  def hoge
35
36
  "a".lengt
36
37
  end
37
38
  EOC
39
+ end
38
40
  end
39
41
 
40
42
  def test_complete_singleton_method
@@ -55,6 +57,16 @@ EOC
55
57
  EOC
56
58
  end
57
59
 
60
+ def test_complete_global_variable__list
61
+ gvars = doit(<<EOC, 3)
62
+ $foo = 3
63
+ $hoge = 100
64
+ $
65
+ EOC
66
+ assert gvars.include?("$foo")
67
+ assert gvars.include?("$hoge")
68
+ end
69
+
58
70
  def test_complete_global_variable__with_class
59
71
  assert_equal(["open"], doit(<<EOC, 2))
60
72
  $hoge = File
@@ -107,6 +119,15 @@ EOC
107
119
  EOC
108
120
  end
109
121
 
122
+ def test_complete_class_variable__list
123
+ assert_equal(%w[@@foo @@hoge], doit(<<EOC, 3))
124
+ @@hoge = 100
125
+ @@foo = 2
126
+ @@
127
+ EOC
128
+ end
129
+
130
+
110
131
  def test_complete_constant__nested
111
132
  assert_equal(["Stat"], doit('File::Sta',1))
112
133
  end
@@ -435,7 +456,9 @@ x = a[1][0] rescue "aaa"
435
456
  x.lengt
436
457
  EOC
437
458
  assert_equal(["length"], doit(code, 3))
438
- assert_equal([], doit(code, 3, nil, :ignore_NoMethodError=>true))
459
+ assert_raises(XMPCompletionFilter::NoCandidates) do
460
+ doit(code, 3, nil, :ignore_NoMethodError=>true)
461
+ end
439
462
  end
440
463
 
441
464
  def test__syntax_error
@@ -496,6 +519,7 @@ end
496
519
 
497
520
 
498
521
  class TestXMPCompletionVerboseFilter < Test::Unit::TestCase
522
+ include Rcodetools
499
523
  def doit(code, lineno, column=nil, options={})
500
524
  xmp = XMPCompletionVerboseFilter.new options
501
525
  xmp.candidates(code, lineno, column).sort
@@ -515,6 +539,16 @@ EOC
515
539
  EOC
516
540
  end
517
541
 
542
+ def test_complete_list_instance_variable
543
+ assert_equal(%w[@bar @baz @foo @hoge], doit(<<EOC, 5))
544
+ @foo = 1
545
+ @bar = 2
546
+ @baz = 3
547
+ @hoge = 100
548
+ @
549
+ EOC
550
+ end
551
+
518
552
  def test_complete_class_variable_module
519
553
  assert_equal(["@@hoge"], doit(<<EOC, 3))
520
554
  module X
@@ -3,6 +3,7 @@ require 'rcodetools/doc'
3
3
  require 'test/unit'
4
4
 
5
5
  class TestXMPDocFilter < Test::Unit::TestCase
6
+ include Rcodetools
6
7
  def doit(code, lineno, column=nil, options={})
7
8
  xmp = XMPDocFilter.new options
8
9
  xmp.doc(code, lineno, column)
@@ -428,6 +429,7 @@ EOC
428
429
  end
429
430
 
430
431
  class TestXMPRiFilter < Test::Unit::TestCase
432
+ include Rcodetools
431
433
  def doit(code, lineno, column=nil, options={})
432
434
  xmp = XMPRiFilter.new options
433
435
  xmp.doc(code, lineno, column)
@@ -1,18 +1,79 @@
1
1
  require 'test/unit'
2
2
 
3
- class TestFunctional < Test::Unit::TestCase
4
- tests = {:simple_annotation => [], :unit_test => ["-u"], :rspec => ["-s"],
5
- :no_warnings => ["--no-warnings"], :bindings => ["--poetry", "-u"],
6
- :add_markers => ["-m"]
7
- }
8
- tests.each_pair do |test, opts|
9
- define_method("test_#{test}") do
10
- dir = File.expand_path(File.dirname(__FILE__))
11
- libdir = File.expand_path(dir + '/../lib')
12
- exec = File.expand_path(dir + '/../bin/xmpfilter')
13
- output = `ruby -I#{libdir} #{exec} #{opts.join(" ")} #{dir}/data/#{test}-input.rb`
14
- outputfile = "#{dir}/data/#{test}-output.rb"
15
- assert_equal(File.read(outputfile), output)
3
+ module TestFunctional
4
+ DIR = File.expand_path(File.dirname(__FILE__))
5
+ LIBDIR = File.expand_path(DIR + '/../lib')
6
+
7
+ module DefineFunctionalTests
8
+ def define_functional_tests(exec, tests)
9
+ tests.each_pair do |test, opts|
10
+ define_method("test_#{test}") do
11
+
12
+ output = `ruby -I#{LIBDIR} #{exec} #{opts.join(" ")} #{DIR}/data/#{test}-input.rb`
13
+ outputfile = "#{DIR}/data/#{test}-output.rb"
14
+ assert_equal(File.read(outputfile), output)
15
+ end
16
+ end
16
17
  end
17
- end
18
+ end
19
+
20
+ class TestXmpfilter < Test::Unit::TestCase
21
+ extend DefineFunctionalTests
22
+ tests = {
23
+ :simple_annotation => [], :unit_test => ["-u"], :rspec => ["-s"],
24
+ :no_warnings => ["--no-warnings"], :bindings => ["--poetry", "-u"],
25
+ :add_markers => ["-m"], :unit_test_rbtest => ["-u", "--rbtest"],
26
+ :unit_test_detect_rbtest => ["-u", "--detect-rbtest"],
27
+ :unit_test_detect_rbtest2 => ["--detect-rbtest"],
28
+ }
29
+ define_functional_tests File.expand_path(DIR + '/../bin/xmpfilter'), tests
30
+ end
31
+
32
+ class TestRctComplete < Test::Unit::TestCase
33
+ extend DefineFunctionalTests
34
+ tests = {
35
+ :completion_rbtest => [ "--rbtest", "--line=6" ],
36
+ :completion_detect_rbtest => [ "--detect-rbtest", "--line=6" ],
37
+ :completion_detect_rbtest2 => [ "--detect-rbtest", "--line=1" ],
38
+ }
39
+ define_functional_tests File.expand_path(DIR + '/../bin/rct-complete'), tests
40
+ end
41
+
42
+ class TestRctDoc < Test::Unit::TestCase
43
+ extend DefineFunctionalTests
44
+ tests = {
45
+ :doc_rbtest => [ "--rbtest", "--line=6" ],
46
+ :doc_detect_rbtest => [ "--detect-rbtest", "--line=1" ],
47
+ :doc_detect_rbtest2 => [ "--detect-rbtest", "--line=6" ],
48
+ }
49
+ define_functional_tests File.expand_path(DIR + '/../bin/rct-doc'), tests
50
+ end
51
+
52
+
53
+ # Other tests are in test_run.rb
54
+ class TestRctCompleteTDC < Test::Unit::TestCase
55
+ test = :completion_in_method
56
+ inputfile = "#{DIR}/data/#{test}-input.rb"
57
+ outputfile = "#{DIR}/data/#{test}-output.rb"
58
+ test_script = "#{DIR}/data/#{test}-test.rb"
59
+ common_opts = ["--filename #{inputfile}", "--line 2"]
60
+ right_output = File.read(outputfile)
61
+ wrong_output = "\n"
62
+
63
+ tests = {
64
+ :completion_in_method__testscript =>
65
+ [ common_opts + ["-t #{test_script}"], right_output ],
66
+ :completion_in_method__testmethod =>
67
+ [ common_opts + ["-t #{test_script}@test_fooz"], right_output ],
68
+ :completion_in_method__wrong_testmethod =>
69
+ [ common_opts + ["-t #{test_script}@test_NOT_FOUND"], wrong_output ],
70
+ }
71
+ exec = File.expand_path(DIR + '/../bin/rct-complete')
72
+ tests.each_pair do |test, (opts, expected)|
73
+ define_method("test_#{test}") do
74
+ output = `ruby -I#{LIBDIR} #{exec} #{opts.join(" ")} #{inputfile}`
75
+ assert_equal(expected, output)
76
+ end
77
+ end
78
+ end
18
79
  end
@@ -5,6 +5,7 @@ require 'tmpdir'
5
5
  require 'fileutils'
6
6
 
7
7
  class TestOptionHandler < Test::Unit::TestCase
8
+ include Rcodetools
8
9
  include OptionHandler
9
10
 
10
11
  def include_paths_check
@@ -0,0 +1,125 @@
1
+ require 'fileutils'
2
+ require 'test/unit'
3
+ require 'ruby_toggle_file'
4
+ require 'tmpdir'
5
+
6
+ class TestRubyToggleFile < Test::Unit::TestCase
7
+ WORK_DIR = "#{Dir.tmpdir}/zdsfwfwejiotest".freeze
8
+ FileUtils.rm_rf WORK_DIR
9
+
10
+ FILE_MAP = {
11
+ :zero => %w[lib/zero.rb test/test_zero.rb],
12
+ :one => %w[lib/one/one.rb test/one/test_one.rb],
13
+ :two => %w[lib/two/two.rb test/test_two.rb],
14
+ :three => %w[three.rb test_three.rb],
15
+ :four => %w[four.rb],
16
+ :five => %w[lib/five.rb],
17
+ :six => %w[lib/six/six/six.rb],
18
+ :seven => %w[ test_seven.rb],
19
+ :eight => %w[ test/test_eight.rb],
20
+ :nine => %w[ test/nine/nine/nine.rb],
21
+
22
+ # Rails
23
+ :rcontrollers => %w[app/controllers/c.rb test/functional/c_test.rb],
24
+ :rmodels => %w[app/models/m.rb test/unit/m_test.rb],
25
+ :rlib => %w[lib/l.rb test/unit/test_l.rb app/models/m.rb],
26
+ }
27
+
28
+ def use_file_map(key, &block)
29
+ Dir.mkdir(WORK_DIR)
30
+ Dir.chdir(WORK_DIR) do
31
+ FILE_MAP[key].each do |file|
32
+ FileUtils.mkpath(File.dirname(file))
33
+ open(file, "w"){}
34
+ end
35
+ end
36
+
37
+ begin
38
+ yield
39
+ ensure
40
+ FileUtils.rm_rf WORK_DIR
41
+ end
42
+ end
43
+
44
+ def setup
45
+ @x = RubyToggleFile.new
46
+ end
47
+
48
+ def _(path)
49
+ WORK_DIR + "/" + path
50
+ end
51
+
52
+ def check(after, before)
53
+ assert_equal _(after), @x.ruby_toggle_file(_(before))
54
+ end
55
+
56
+ def test_test_file_file_exist
57
+ use_file_map(:zero) { check "test/test_zero.rb", "lib/zero.rb" }
58
+ use_file_map(:one) { check "test/one/test_one.rb", "lib/one/one.rb" }
59
+ use_file_map(:two) { check "test/test_two.rb", "lib/two/two.rb" }
60
+ use_file_map(:three) { check "test_three.rb", "three.rb" }
61
+ end
62
+
63
+ def test_test_file_file_not_exist
64
+ use_file_map(:four) { check "test_four.rb", "four.rb" }
65
+ use_file_map(:five) { check "test/test_five.rb", "lib/five.rb" }
66
+ use_file_map(:six) { check "test/six/six/test_six.rb", "lib/six/six/six.rb" }
67
+ end
68
+
69
+ def test_implementation_file_file_exist
70
+ use_file_map(:zero) { check "lib/zero.rb", "test/test_zero.rb" }
71
+ use_file_map(:one) { check "lib/one/one.rb", "test/one/test_one.rb" }
72
+ use_file_map(:two) { check "lib/two/two.rb", "test/test_two.rb" }
73
+ use_file_map(:three) { check "three.rb", "test_three.rb" }
74
+ end
75
+
76
+ def test_implementation_file_file_not_exist
77
+ use_file_map(:seven) { check "seven.rb", "test_seven.rb" }
78
+ use_file_map(:eight) { check "lib/eight.rb", "test/test_eight.rb" }
79
+ use_file_map(:nine) { check "lib/nine/nine/nine.rb", "test/nine/nine/test_nine.rb" }
80
+ end
81
+
82
+ # Rails test
83
+ def test_test_file_rails_controllers
84
+ use_file_map(:rcontrollers) { check "test/functional/c_test.rb", "app/controllers/c.rb" }
85
+ end
86
+
87
+ def test_test_file_rails_models
88
+ use_file_map(:rmodels) { check "test/unit/m_test.rb", "app/models/m.rb" }
89
+ end
90
+
91
+ def test_test_file_rails_lib
92
+ use_file_map(:rlib) { check "test/unit/test_l.rb", "lib/l.rb" }
93
+ end
94
+
95
+
96
+ def test_implementation_file_rails_controllers
97
+ use_file_map(:rcontrollers) { check "app/controllers/c.rb", "test/functional/c_test.rb" }
98
+ end
99
+
100
+ def test_implementation_file_rails_models
101
+ use_file_map(:rmodels) { check "app/models/m.rb", "test/unit/m_test.rb" }
102
+ end
103
+
104
+ def test_implementation_file_rails_lib
105
+ use_file_map(:rlib) { check "lib/l.rb", "test/unit/test_l.rb" }
106
+ end
107
+
108
+
109
+ end
110
+
111
+
112
+ class TestRunHooksWithArgsUntilSuccess < Test::Unit::TestCase
113
+ def m001(x) nil end
114
+ private
115
+ def m002(x) false end
116
+ def m003(x) 100*x end
117
+ def m004(x) 200 end
118
+
119
+ public
120
+ def test_run_hooks_with_args_until_success
121
+ assert_equal 1000, run_hooks_with_args_until_success(/^m\d+$/, 10)
122
+ assert_nil run_hooks_with_args_until_success(/^m001$/, 10)
123
+ assert_equal 200, run_hooks_with_args_until_success(/^m004$/, 10)
124
+ end
125
+ end