pvn 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/README.markdown +38 -0
  2. data/bin/pvn +12 -0
  3. data/bin/pvndiff +10 -0
  4. data/lib/pvn/app.rb +144 -0
  5. data/lib/pvn/base/textlines.rb +35 -0
  6. data/lib/pvn/base/util.rb +14 -0
  7. data/lib/pvn/cmddoc.rb +77 -0
  8. data/lib/pvn/config.rb +65 -0
  9. data/lib/pvn/describe.rb +40 -0
  10. data/lib/pvn/diff/diffcmd.rb +49 -0
  11. data/lib/pvn/diff/differ.rb +67 -0
  12. data/lib/pvn/diff/diffopts.rb +58 -0
  13. data/lib/pvn/doc.rb +34 -0
  14. data/lib/pvn/io/element.rb +113 -0
  15. data/lib/pvn/io/fselement.rb +22 -0
  16. data/lib/pvn/log/formatter/color_formatter.rb +29 -0
  17. data/lib/pvn/log/formatter/entries_formatter.rb +33 -0
  18. data/lib/pvn/log/formatter/entry_formatter.rb +57 -0
  19. data/lib/pvn/log/formatter/log_formatter.rb +59 -0
  20. data/lib/pvn/log/formatter/message_formatter.rb +19 -0
  21. data/lib/pvn/log/formatter/path_formatter.rb +41 -0
  22. data/lib/pvn/log/formatter/summary_formatter.rb +49 -0
  23. data/lib/pvn/log/logcmd.rb +136 -0
  24. data/lib/pvn/log/logentry.rb +116 -0
  25. data/lib/pvn/log/logfactory.rb +101 -0
  26. data/lib/pvn/log/logoptions.rb +43 -0
  27. data/lib/pvn/pct/linecount.rb +33 -0
  28. data/lib/pvn/pct/pctcmd.rb +204 -0
  29. data/lib/pvn/pct/statcmd.rb +13 -0
  30. data/lib/pvn/revision/entry.rb +94 -0
  31. data/lib/pvn/revision.rb +119 -0
  32. data/lib/pvn/subcommands/base/clargs.rb +53 -0
  33. data/lib/pvn/subcommands/base/command.rb +60 -0
  34. data/lib/pvn/subcommands/base/doc.rb +94 -0
  35. data/lib/pvn/subcommands/base/options.rb +22 -0
  36. data/lib/pvn/subcommands/log/command.rb +70 -0
  37. data/lib/pvn/subcommands/log/options.rb +43 -0
  38. data/lib/pvn/subcommands/pct/clargs.rb +33 -0
  39. data/lib/pvn/subcommands/pct/command.rb +57 -0
  40. data/lib/pvn/subcommands/revision/multiple_revisions_option.rb +43 -0
  41. data/lib/pvn/subcommands/revision/revision_option.rb +74 -0
  42. data/lib/pvn/subcommands/revision/revision_regexp_option.rb +39 -0
  43. data/lib/pvn/svn/command/svncmd.rb +39 -0
  44. data/lib/pvn/svn/environment.rb +23 -0
  45. data/lib/pvn/svn/svnelement.rb +89 -0
  46. data/lib/pvn/svn/svninfo.rb +42 -0
  47. data/lib/pvn/svn/svnroot.rb +29 -0
  48. data/lib/pvn/upp/uppcmd.rb +112 -0
  49. data/lib/pvn/wherecmd.rb +55 -0
  50. data/lib/pvn.rb +8 -0
  51. data/lib/svnx/command.rb +60 -0
  52. data/lib/svnx/entry.rb +34 -0
  53. data/lib/svnx/info/command.rb +21 -0
  54. data/lib/svnx/info/entries.rb +27 -0
  55. data/lib/svnx/info/entry.rb +34 -0
  56. data/lib/svnx/log/command.rb +93 -0
  57. data/lib/svnx/log/entries.rb +57 -0
  58. data/lib/svnx/log/entry.rb +54 -0
  59. data/lib/svnx/status/command.rb +21 -0
  60. data/lib/svnx/status/entries.rb +22 -0
  61. data/lib/svnx/status/entry.rb +33 -0
  62. data/lib/synoption/base_option.rb +149 -0
  63. data/lib/synoption/boolean_option.rb +21 -0
  64. data/lib/synoption/doc.rb +81 -0
  65. data/lib/synoption/fixnum_option.rb +13 -0
  66. data/lib/synoption/match.rb +47 -0
  67. data/lib/synoption/option.rb +10 -0
  68. data/lib/synoption/optionable.rb +66 -0
  69. data/lib/synoption/set.rb +114 -0
  70. data/lib/system/cachecmd.rb +65 -0
  71. data/lib/system/cmdexec.rb +13 -0
  72. data/lib/system/cmdline.rb +70 -0
  73. data/lib/system/command/arg.rb +12 -0
  74. data/lib/system/command/cachefile.rb +39 -0
  75. data/lib/system/command/caching.rb +36 -0
  76. data/lib/system/command/line.rb +47 -0
  77. data/lib/system/command.rb +72 -0
  78. data/test/integration/svnx/log/test.rb +43 -0
  79. data/test/unit/pvn/app_test.rb +22 -0
  80. data/test/unit/pvn/io/element/log/log_test.rb +35 -0
  81. data/test/unit/pvn/log/formatter/entry_formatter_test.rb +90 -0
  82. data/test/unit/pvn/revision/entry_test.rb +123 -0
  83. data/test/unit/pvn/subcommands/log/command_test.rb +22 -0
  84. data/test/unit/pvn/subcommands/log/options_test.rb +85 -0
  85. data/test/unit/pvn/subcommands/revision/multiple_revisions_option_test.rb +67 -0
  86. data/test/unit/pvn/subcommands/revision/revision_option_test.rb +57 -0
  87. data/test/unit/pvn/subcommands/revision/revision_regexp_option_test.rb +69 -0
  88. data/test/unit/svnx/info/entry_test.rb +52 -0
  89. data/test/unit/svnx/log/cmargs_test.rb +22 -0
  90. data/test/unit/svnx/log/entries_test.rb +73 -0
  91. data/test/unit/svnx/log/entry_test.rb +21 -0
  92. data/test/unit/svnx/status/entry_test.rb +39 -0
  93. data/test/unit/synoption/base_option_test.rb +182 -0
  94. data/test/unit/synoption/match_test.rb +61 -0
  95. data/test/unit/synoption/option_test.rb +15 -0
  96. data/test/unit/synoption/set_test.rb +37 -0
  97. data/test/unit/system/command/caching_test.rb +97 -0
  98. data/test/unit/system/command/line_test.rb +33 -0
  99. metadata +199 -0
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'tc'
5
+ require 'pvn/subcommands/revision/revision_option'
6
+
7
+ module PVN
8
+ class RevisionOptionTestCase < PVN::TestCase
9
+ def assert_relative_to_absolute exp, val, path = '/Programs/wiquery/trunk'
10
+ ropt = PVN::RevisionOption.new
11
+ act = ropt.relative_to_absolute val, path
12
+ assert_equal exp, act, "val: #{val}; path: #{val}"
13
+ end
14
+
15
+ def test_relative_to_absolute_middling
16
+ assert_relative_to_absolute '1887', '-7'
17
+ end
18
+
19
+ def test_relative_to_absolute_latest
20
+ assert_relative_to_absolute '1950', '-1'
21
+ end
22
+
23
+ def test_relative_to_absolute_oldest
24
+ assert_relative_to_absolute '412', '-163'
25
+ end
26
+
27
+ def test_out_of_range
28
+ assert_raises(RuntimeError) do
29
+ assert_relative_to_absolute '1944', '-164'
30
+ end
31
+ end
32
+
33
+ def assert_post_process exp, val, path = '/Programs/wiquery/trunk'
34
+ ropt = PVN::RevisionOption.new
35
+ ropt.set_value val
36
+ ropt.post_process nil, [ path ]
37
+ act = ropt.value
38
+ assert_equal exp, act, "val: #{val}; path: #{path}"
39
+ end
40
+
41
+ def test_post_process_absolute_middling
42
+ assert_post_process '1887', '1887'
43
+ end
44
+
45
+ def test_post_process_middling
46
+ assert_post_process '1887', '-7'
47
+ end
48
+
49
+ def test_post_process_latest
50
+ assert_post_process '1950', '-1'
51
+ end
52
+
53
+ def test_post_process_oldest
54
+ assert_post_process '412', '-163'
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'tc'
5
+ require 'pvn/subcommands/revision/revision_regexp_option'
6
+
7
+ module PVN
8
+ class RevisionRegexpOptionTest < PVN::TestCase
9
+ def assert_tag_match str
10
+ assert_match RevisionRegexpOption::TAG_RE, str
11
+ end
12
+
13
+ def assert_tag_no_match str
14
+ assert_no_match RevisionRegexpOption::TAG_RE, str
15
+ end
16
+
17
+ def test_pattern
18
+ assert_tag_match '-r500:600'
19
+ assert_tag_match '+1'
20
+ assert_tag_match '-r 500'
21
+ assert_tag_match '-1776'
22
+
23
+ assert_tag_no_match ' -r500:600'
24
+ assert_tag_no_match '1'
25
+ assert_tag_no_match '123'
26
+ assert_tag_no_match '-x'
27
+ end
28
+
29
+ def test_out_of_range
30
+ assert_raises(RuntimeError) do
31
+ ropt = PVN::RevisionRegexpOption.new
32
+ ropt.process [ '-164' ]
33
+ ropt.post_process nil, [ '/Programs/wiquery/trunk' ]
34
+ end
35
+ end
36
+
37
+ def assert_post_process exp, val, path = '/Programs/wiquery/trunk'
38
+ ropt = PVN::RevisionRegexpOption.new
39
+ ropt.set_value val
40
+ ropt.post_process nil, [ path ]
41
+ act = ropt.value
42
+ assert_equal exp, act, "val: #{val}; path: #{path}"
43
+ end
44
+
45
+ def test_post_process_middling
46
+ assert_post_process '1887', '-7'
47
+ end
48
+
49
+ def test_post_process_latest
50
+ assert_post_process '1950', '-1'
51
+ end
52
+
53
+ def test_post_process_oldest
54
+ assert_post_process '412', '-163'
55
+ end
56
+
57
+ def test_post_process_tagval
58
+ assert_post_process '7', '-r7'
59
+ end
60
+
61
+ def test_post_process_tagrange
62
+ assert_post_process '7:177', '-r7:177'
63
+ end
64
+
65
+ def test_post_process_absolute_middling
66
+ assert_post_process '1887', '1887'
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/info/tc'
5
+ require 'svnx/info/entry'
6
+
7
+ module SVNx::Info
8
+ class EntryTestCase < SVNx::Info::TestCase
9
+ include Loggable
10
+
11
+ def test_entry_from_xml
12
+ # svn info --xml ./wiquery-core/pom.xml
13
+ xml = Array.new
14
+ xml << '<?xml version="1.0"?>'
15
+ xml << '<info>'
16
+ xml << '<entry'
17
+ xml << ' kind="file"'
18
+ xml << ' path="wiquery-core/pom.xml"'
19
+ xml << ' revision="1950">'
20
+ xml << '<url>file:///home/jpace/Programs/Subversion/Repositories/wiquery/trunk/wiquery-core/pom.xml</url>'
21
+ xml << '<repository>'
22
+ xml << '<root>file:///home/jpace/Programs/Subversion/Repositories/wiquery</root>'
23
+ xml << '<uuid>9d44104b-4b85-4781-9eca-83ed02b512a0</uuid>'
24
+ xml << '</repository>'
25
+ xml << '<wc-info>'
26
+ xml << '<schedule>normal</schedule>'
27
+ xml << '<depth>infinity</depth>'
28
+ xml << '<text-updated>2011-11-28T11:26:07.772551Z</text-updated>'
29
+ xml << '<checksum>3b2a51d21a9517a4d3dc5865c4b56db9</checksum>'
30
+ xml << '</wc-info>'
31
+ xml << '<commit'
32
+ xml << ' revision="1907">'
33
+ xml << '<author>hielke.hoeve@gmail.com</author>'
34
+ xml << '<date>2011-11-14T10:50:38.389281Z</date>'
35
+ xml << '</commit>'
36
+ xml << '</entry>'
37
+ xml << '</info>'
38
+
39
+ xmllines = xml.collect { |line| line + "\n" }
40
+
41
+ expdata = {
42
+ :url => 'file:///home/jpace/Programs/Subversion/Repositories/wiquery/trunk/wiquery-core/pom.xml',
43
+ :kind => 'file',
44
+ :path => 'wiquery-core/pom.xml',
45
+ :root => 'file:///home/jpace/Programs/Subversion/Repositories/wiquery'
46
+ }
47
+
48
+ entry = Entry.new :xmllines => xmllines.join('')
49
+ assert_entry_equals entry, expdata
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/log/tc'
5
+ require 'svnx/log/command'
6
+
7
+ module SVNx::Log
8
+ class CommandArgsTestCase ###$$$ < SVNx::Log::TestCase
9
+
10
+ def test_options_log_limit
11
+ cmdargs = LogCommandArgs.new :limit => 6
12
+ cmd = LogCommand.new :use_cache => true, :cmdargs => cmdargs
13
+ assert_equal 'svn log --xml --limit 6', cmd.command_line.to_command
14
+ end
15
+
16
+ def test_options_verbose
17
+ cmdargs = LogCommandArgs.new :verbose => true
18
+ cmd = LogCommand.new :use_cache => true, :cmdargs => cmdargs
19
+ assert_equal 'svn log --xml -v', cmd.command_line.to_command
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/log/tc'
5
+ require 'svnx/log/entries'
6
+
7
+ module SVNx::Log
8
+ class EntriesTestCase < SVNx::Log::TestCase
9
+ include Loggable
10
+
11
+ def assert_entry_fields_not_nil entry
12
+ # these are occasionally missing or blank, which REXML considers nil:
13
+ assert entry.message
14
+ assert entry.author
15
+ end
16
+
17
+ def test_create_from_xml
18
+ expdata = '1947', 'reiern70', '2011-11-14T12:24:45.757124Z', 'added a convenience method to set the range'
19
+ expdata << { :kind => 'file',
20
+ :action => 'M',
21
+ :name => '/trunk/wiquery-jquery-ui/src/test/java/org/odlabs/wiquery/ui/slider/SliderTestCase.java'
22
+ }
23
+
24
+ entries = Entries.new :xmllines => get_test_lines_limit_15
25
+
26
+ assert_log_entry_equals entries[2], expdata
27
+ end
28
+
29
+ def test_no_author_field
30
+ entries = Entries.new :xmllines => get_test_lines_no_author
31
+ nentries = entries.size
32
+
33
+ # revision 1 has no author ... wtf?
34
+ assert_entry_fields_not_nil entries[0]
35
+ end
36
+
37
+ def test_empty_message_element
38
+ entries = Entries.new :xmllines => get_test_lines_empty_message
39
+ nentries = entries.size
40
+
41
+ # empty message here:
42
+ assert_entry_fields_not_nil entries[0]
43
+ end
44
+
45
+ def test_create_on_demand
46
+ # although entries now supports xmllines as an Array, we need the size for the assertion:
47
+ xmllines = get_test_lines_no_limit.join ''
48
+
49
+ # quite a big file ...
50
+ assert_equal 324827, xmllines.size
51
+
52
+ entries = Entries.new :xmllines => xmllines
53
+
54
+ nentries = entries.size
55
+ assert_equal 1949, nentries
56
+
57
+ # the power of Ruby, effortlessly getting instance variables ...
58
+
59
+ real_entries = entries.instance_eval '@entries'
60
+
61
+ # nothing processed yet ...
62
+ assert_nil real_entries[16]
63
+ assert_nil real_entries[17]
64
+ assert_nil real_entries[18]
65
+
66
+ assert_entry_fields_not_nil entries[17]
67
+
68
+ # and these still aren't processed:
69
+ assert_nil real_entries[16]
70
+ assert_nil real_entries[18]
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/log/tc'
5
+ require 'svnx/log/entry'
6
+
7
+ module SVNx::Log
8
+ class EntryTestCase < SVNx::Log::TestCase
9
+ include Loggable
10
+
11
+ def test_entry_from_xml
12
+ expdata = '1947', 'reiern70', '2011-11-14T12:24:45.757124Z', 'added a convenience method to set the range'
13
+ expdata << { :kind => 'file', :action => 'M', :name => '/trunk/wiquery-jquery-ui/src/test/java/org/odlabs/wiquery/ui/slider/SliderTestCase.java' }
14
+
15
+ doc = REXML::Document.new get_test_lines_limit_15.join('')
16
+
17
+ entry = Entry.new :xmlelement => doc.elements[1].elements[3]
18
+ assert_log_entry_equals entry, expdata
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/status/tc'
5
+ require 'svnx/status/entry'
6
+
7
+ module SVNx::Status
8
+ class EntryTestCase < SVNx::Status::TestCase
9
+ include Loggable
10
+
11
+ def test_entry_from_xml
12
+ xml = Array.new
13
+ xml << "<?xml version=\"1.0\"?>\n"
14
+ xml << "<status>\n"
15
+ xml << "<target\n"
16
+ xml << " path=\"LICENSE\">\n"
17
+ xml << "<entry\n"
18
+ xml << " path=\"LICENSE\">\n"
19
+ xml << "<wc-status\n"
20
+ xml << " props=\"none\"\n"
21
+ xml << " item=\"deleted\"\n"
22
+ xml << " revision=\"1950\">\n"
23
+ xml << "<commit\n"
24
+ xml << " revision=\"412\">\n"
25
+ xml << "<author>lionel.armanet</author>\n"
26
+ xml << "<date>2010-09-17T21:23:25.763385Z</date>\n"
27
+ xml << "</commit>\n"
28
+ xml << "</wc-status>\n"
29
+ xml << "</entry>\n"
30
+ xml << "</target>\n"
31
+ xml << "</status>\n"
32
+
33
+ expdata = { :path => 'LICENSE', :status => 'deleted' }
34
+
35
+ entry = Entry.new :xmllines => xml.join('')
36
+ assert_entry_equals entry, expdata
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'tc'
5
+ require 'synoption/base_option'
6
+ require 'stringio'
7
+
8
+ module PVN
9
+ class BaseOptionTestCase < Test::Unit::TestCase
10
+ include Loggable
11
+
12
+ def test_init_minimal
13
+ opt = BaseOption.new :limit, '-l', "the number of log entries", nil
14
+ assert_equal :limit, opt.name
15
+ assert_equal '-l', opt.tag
16
+ assert_equal "the number of log entries", opt.description
17
+ end
18
+
19
+ def test_init_default_value
20
+ opt = BaseOption.new :nombre, '-x', " one two three", 133
21
+ assert_equal 133, opt.value
22
+ end
23
+
24
+ def test_init_negate
25
+ opt = BaseOption.new :limit, '-l', "the number of log entries", nil, :negate => [ %r{^--no-?limit} ]
26
+ assert_equal [ %r{^--no-?limit} ], opt.negate
27
+ end
28
+
29
+ def test_to_doc
30
+ opt = BaseOption.new :limit, '-l', "the number of log entries", 777, :negate => [ %r{^--no-?limit} ]
31
+ sio = StringIO.new
32
+ opt.to_doc sio
33
+ exp = String.new
34
+ exp << " -l [--limit] ARG : the number of log entries\n"
35
+ exp << " default: 777\n"
36
+ exp << " --no-limit \n"
37
+ assert_equal exp, sio.string
38
+ end
39
+
40
+ def assert_exact_match exp, opt, val
41
+ assert_equal exp, opt.exact_match?(val), "value: '" + val + "'"
42
+ end
43
+
44
+ def test_exact_match
45
+ opt = BaseOption.new :limit, '-l', "the number of log entries", 3
46
+ [ '-l', '--limit' ].each do |val|
47
+ assert_exact_match true, opt, val
48
+ end
49
+
50
+ [ '-L', '-x', '--lim', '--liMit' ].each do |val|
51
+ assert_exact_match false, opt, val
52
+ end
53
+ end
54
+
55
+ def assert_negative_match exp, opt, val
56
+ md = opt.negative_match? val
57
+ assert_equal exp, !!md, "value: '" + val + "'"
58
+ end
59
+
60
+ def test_negative_match
61
+ opt = BaseOption.new :limit, '-l', "the number of log entries", 777, :negate => [ '-L', %r{^--no-?limit} ]
62
+ [ '-L', '--no-limit', '--nolimit' ].each do |val|
63
+ assert_negative_match true, opt, val
64
+ end
65
+
66
+ [ '-l', '-x', '-nolimit', ' --nolimit' ].each do |val|
67
+ assert_negative_match false, opt, val
68
+ end
69
+ end
70
+
71
+ def assert_regexp_match exp, opt, val
72
+ md = opt.regexp_match? val
73
+ assert_equal exp, !!md, "value: '" + val + "'"
74
+ end
75
+
76
+ def test_regexp_match
77
+ opt = BaseOption.new :revision, '-r', "the revision", nil, :regexp => Regexp.new('^[\-\+]\d+$')
78
+ [ '-1', '-123', '+99', '+443' ].each do |val|
79
+ assert_regexp_match true, opt, val
80
+ end
81
+
82
+ [ '-x', '123', '+-x', 'word' ].each do |val|
83
+ assert_regexp_match false, opt, val
84
+ end
85
+ end
86
+
87
+ def assert_to_command_line exp, opt
88
+ assert_equal exp, opt.to_command_line
89
+ end
90
+
91
+ def make_xyz_option options = Hash.new
92
+ BaseOption.new :xyz, '-x', "the blah blah blah", nil, options
93
+ end
94
+
95
+ def test_to_command_line_no_cmdline_option
96
+ opt = make_xyz_option
97
+ assert_to_command_line nil, opt
98
+ opt.set_value 1
99
+ assert_to_command_line [ '-x', 1 ], opt
100
+ end
101
+
102
+ def test_to_command_line_cmdline_option_string
103
+ opt = make_xyz_option :as_cmdline_option => '--xray'
104
+ assert_to_command_line nil, opt
105
+ opt.set_value 1
106
+ assert_to_command_line '--xray', opt
107
+ end
108
+
109
+ def test_to_command_line_cmdline_option_nil
110
+ opt = make_xyz_option :as_cmdline_option => nil
111
+ assert_to_command_line nil, opt
112
+ opt.set_value 1
113
+ assert_to_command_line nil, opt
114
+ end
115
+
116
+ def test_takes_value
117
+ opt = make_xyz_option
118
+ assert opt.takes_value?
119
+ end
120
+
121
+ def assert_process exp_process, exp_value, exp_remaining_args, opt, args
122
+ pr = opt.process args
123
+ assert_equal exp_process, pr
124
+ assert_equal exp_value, opt.value
125
+ assert_equal exp_remaining_args, args
126
+ end
127
+
128
+ def test_process_exact_no_match
129
+ opt = make_xyz_option
130
+ args = %w{ --baz foo }
131
+ assert_process false, nil, %w{ --baz foo }, opt, args
132
+ end
133
+
134
+ def test_process_exact_takes_argument
135
+ opt = make_xyz_option
136
+ args = %w{ --xyz foo }
137
+ assert_process true, 'foo', %w{ }, opt, args
138
+
139
+ opt = make_xyz_option
140
+ args = %w{ --xyz foo bar }
141
+ assert_process true, 'foo', %w{ bar }, opt, args
142
+ end
143
+
144
+ def test_process_exact_takes_missing_argument
145
+ opt = make_xyz_option
146
+ args = %w{ --xyz }
147
+ assert_raises(RuntimeError) do
148
+ assert_process true, 'foo', %w{ }, opt, args
149
+ end
150
+ end
151
+
152
+ def test_process_negative
153
+ options = { :negate => [ '-X', %r{^--no-?xyz} ] }
154
+ %w{ -X --no-xyz --noxyz }.each do |arg|
155
+ opt = make_xyz_option options
156
+ args = [ arg ]
157
+ assert_process true, false, %w{ }, opt, args
158
+ end
159
+
160
+ %w{ -X --no-xyz --noxyz }.each do |arg|
161
+ opt = make_xyz_option options
162
+ args = [ arg, '--abc' ]
163
+ assert_process true, false, %w{ --abc }, opt, args
164
+ end
165
+ end
166
+
167
+ def test_process_regexp
168
+ options = { :regexp => Regexp.new('^[\-\+]\d+$') }
169
+ %w{ -1 +123 }.each do |arg|
170
+ opt = make_xyz_option options
171
+ args = [ arg ]
172
+ assert_process true, arg, %w{ }, opt, args
173
+ end
174
+
175
+ %w{ -1 +123 }.each do |arg|
176
+ opt = make_xyz_option options
177
+ args = [ arg, '--foo' ]
178
+ assert_process true, arg, %w{ --foo }, opt, args
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'tc'
5
+ require 'synoption/match'
6
+
7
+ module PVN
8
+ class MatchTestCase < Test::Unit::TestCase
9
+ include Loggable
10
+
11
+ def assert_match exp, matcher, arg
12
+ assert_equal exp, matcher.match?(arg), "arg: #{arg}"
13
+ end
14
+
15
+ def assert_matches exp, matcher, *args
16
+ args.each do |arg|
17
+ assert_match exp, matcher, arg
18
+ end
19
+ end
20
+
21
+ def test_exact
22
+ matcher = OptionExactMatch.new '-t', 'tagname'
23
+ assert_matches true, matcher, '-t', '--tagname'
24
+ assert_matches false, matcher, '-T', '--tag-name', '--no-tagname', '--notagname'
25
+ end
26
+
27
+ def test_negative_string
28
+ matcher = OptionNegativeMatch.new '-T'
29
+ assert_matches true, matcher, '-T'
30
+ assert_matches false, matcher, '-t'
31
+ end
32
+
33
+ def test_negative_regexp
34
+ matcher = OptionNegativeMatch.new %r{^\-\-no\-?tagname$}
35
+ assert_matches true, matcher, '--no-tagname', '--notagname'
36
+ assert_matches false, matcher, '-t', '--non-tagname' '--nontagname'
37
+ end
38
+
39
+ def test_negative_multiple
40
+ matcher = OptionNegativeMatch.new %r{^\-\-no\-?tagname$}, '-T'
41
+ assert_matches true, matcher, '-T', '--no-tagname', '--notagname'
42
+ assert_matches false, matcher, '-t', '--tagname'
43
+ end
44
+
45
+ def assert_match_not_nil matcher, arg
46
+ assert_not_nil matcher.match?(arg), "arg: #{arg}"
47
+ end
48
+
49
+ def assert_matches_not_nil matcher, *args
50
+ args.each do |arg|
51
+ assert_match_not_nil matcher, arg
52
+ end
53
+ end
54
+
55
+ def test_regexp_match
56
+ matcher = OptionRegexpMatch.new %r{^--tag-?name$}
57
+ assert_matches_not_nil matcher, '--tagname', '--tag-name'
58
+ assert_matches nil, matcher, '--tagnames' '--tag--name'
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'tc'
5
+ require 'synoption/option'
6
+ require 'stringio'
7
+
8
+ module PVN
9
+ class OptionTestCase < Test::Unit::TestCase
10
+ include Loggable
11
+
12
+ def test_nothing_yet
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'tc'
5
+ require 'synoption/set'
6
+ require 'synoption/base_option'
7
+ require 'stringio'
8
+
9
+ module PVN
10
+ class SetTestCase < Test::Unit::TestCase
11
+ include Loggable
12
+
13
+ def test_find_by_name
14
+ xyz = BaseOption.new :xyz, '-x', "blah blah xyz", nil
15
+ abc = BaseOption.new :abc, '-a', "abc yadda yadda", nil
16
+ tnt = BaseOption.new :tnt, '-t', "tnt and so forth", nil
17
+
18
+ os = OptionSet.new [ xyz, abc, tnt ]
19
+
20
+ assert_not_nil os.find_by_name(:xyz)
21
+ assert_nil os.find_by_name(:bfd)
22
+ end
23
+
24
+ def test_
25
+ xyz = BaseOption.new :xyz, '-x', "blah blah xyz", nil
26
+ abc = BaseOption.new :abc, '-a', "abc yadda yadda", nil
27
+ tnt = BaseOption.new :tnt, '-t', "tnt and so forth", nil
28
+
29
+ os = OptionSet.new [ xyz, abc, tnt ]
30
+
31
+ assert_not_nil os.find_by_name(:xyz)
32
+ assert_nil os.find_by_name(:bfd)
33
+
34
+ assert_equal xyz, os.find_by_name(:xyz)
35
+ end
36
+ end
37
+ end