bitclust-core 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,123 @@
1
+ require 'pathname'
2
+ require 'erb'
3
+ require 'find'
4
+ require 'pp'
5
+ require 'optparse'
6
+ require 'yaml'
7
+
8
+ require 'bitclust'
9
+ require 'bitclust/subcommand'
10
+
11
+ module BitClust::Subcommands
12
+ class SetupCommand < BitClust::Subcommand
13
+
14
+ REPOSITORY_PATH = "http://jp.rubyist.net/svn/rurema/doctree/trunk"
15
+
16
+ def initialize
17
+ @prepare = nil
18
+ @cleanup = nil
19
+ @versions = ["1.8.7", "1.9.3"]
20
+ @parser = OptionParser.new {|opt|
21
+ opt.banner = "Usage: #{File.basename($0, '.*')} setup [options]"
22
+ opt.on('--prepare', 'Prepare config file and checkout repository. Do not create database.') {
23
+ @prepare = true
24
+ }
25
+ opt.on('--cleanup', 'Cleanup datebase before create database.') {
26
+ @cleanup = true
27
+ }
28
+ opt.on('--versions=V1,V2,...', "Specify versions. [#{@versions.join(',')}]") {|versions|
29
+ @versions = versions.split(",")
30
+ }
31
+ opt.on('--help', 'Prints this message and quit.') {
32
+ puts opt.help
33
+ exit 0
34
+ }
35
+ }
36
+ end
37
+
38
+ def exec(db, argv)
39
+ prepare
40
+ return if @prepare
41
+ @config[:versions].each do |version|
42
+ puts "Generating database for Ruby#{version}..."
43
+ prefix = "#{@config[:database_prefix]}-#{version}"
44
+ FileUtils.rm_rf(prefix) if @cleanup
45
+ init_argv = ["version=#{version}", "encoding=#{@config[:encoding]}"]
46
+ db = BitClust::MethodDatabase.new(prefix)
47
+ InitCommand.new.exec(db, init_argv)
48
+ update_method_database(prefix, ["--stdlibtree=#{@config[:stdlibtree]}"])
49
+ argv = Pathname(@config[:capi_src]).children.select(&:file?).map{|v| v.realpath.to_s }
50
+ update_function_database(prefix, argv)
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def prepare
57
+ home_directory = Pathname(ENV["HOME"])
58
+ config_dir = home_directory + ".bitclust"
59
+ config_dir.mkpath
60
+ config_path = config_dir + "config"
61
+ rubydoc_dir = config_dir + "rubydoc"
62
+ @config = {
63
+ :database_prefix => (config_dir + "db").to_s,
64
+ :encoding => "utf-8",
65
+ :versions => @versions,
66
+ :default_version => @versions.max,
67
+ :stdlibtree => (rubydoc_dir + "refm/api/src").to_s,
68
+ :capi_src => (rubydoc_dir + "refm/capi/src/").to_s,
69
+ :baseurl => "http://localhost:10080",
70
+ :port => "10080",
71
+ :pid_file => "/tmp/bitclust.pid",
72
+ }
73
+ if config_path.exist?
74
+ @config = YAML.load_file(config_path)
75
+ unless @config[:versions].sort == @versions.sort
76
+ print("overwrite config file? > [y/N]")
77
+ if /\Ay\z/i =~ $stdin.gets.chomp
78
+ @config[:versions] = @versions
79
+ @config[:default_version] = @versions.max
80
+ generate_config(config_path, @config)
81
+ end
82
+ end
83
+ else
84
+ generate_config(config_path, @config)
85
+ end
86
+ checkout(rubydoc_dir)
87
+ end
88
+
89
+ def generate_config(path, config)
90
+ path.open("w+", 0644) do |file|
91
+ file.puts config.to_yaml
92
+ end
93
+ end
94
+
95
+ def checkout(rubydoc_dir)
96
+ case RUBY_PLATFORM
97
+ when /mswin(?!ce)|mingw|cygwin|bccwin/
98
+ cmd = "svn help > NUL 2> NUL"
99
+ else
100
+ cmd = "svn help > /dev/null 2> /dev/null"
101
+ end
102
+ unless system(cmd)
103
+ warn "svn command is not found. Please install Subversion."
104
+ exit 1
105
+ end
106
+ system("svn", "co", REPOSITORY_PATH, rubydoc_dir.to_s)
107
+ end
108
+
109
+ def update_method_database(prefix, argv)
110
+ db = BitClust::MethodDatabase.new(prefix)
111
+ cmd = UpdateCommand.new
112
+ cmd.parse(argv)
113
+ cmd.exec(db, argv)
114
+ end
115
+
116
+ def update_function_database(prefix, argv)
117
+ db = BitClust::FunctionDatabase.new(prefix)
118
+ cmd = UpdateCommand.new
119
+ cmd.parse(argv)
120
+ cmd.exec(db, argv)
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,65 @@
1
+ require 'pathname'
2
+ require 'erb'
3
+ require 'find'
4
+ require 'pp'
5
+ require 'optparse'
6
+ require 'yaml'
7
+
8
+ require 'bitclust'
9
+ require 'bitclust/subcommand'
10
+
11
+ module BitClust::Subcommands
12
+ class UpdateCommand < BitClust::Subcommand
13
+
14
+ def initialize
15
+ @root = nil
16
+ @library = nil
17
+ @parser = OptionParser.new {|opt|
18
+ opt.banner = "Usage: #{File.basename($0, '.*')} update [<file>...]"
19
+ opt.on('--stdlibtree=ROOT', 'Process stdlib source directory tree.') {|path|
20
+ @root = path
21
+ }
22
+ opt.on('--library-name=NAME', 'Use NAME for library name in file mode.') {|name|
23
+ @library = name
24
+ }
25
+ opt.on('--help', 'Prints this message and quit.') {
26
+ puts opt.help
27
+ exit 0
28
+ }
29
+ }
30
+ end
31
+
32
+ def parse(argv)
33
+ super
34
+ if not @root and argv.empty?
35
+ error "no input file given"
36
+ end
37
+ end
38
+
39
+ def exec(db, argv)
40
+ db.transaction {
41
+ if @root
42
+ db.update_by_stdlibtree @root
43
+ end
44
+ argv.each do |path|
45
+ db.update_by_file path, @library || guess_library_name(path)
46
+ end
47
+ }
48
+ end
49
+
50
+ private
51
+
52
+ def guess_library_name(path)
53
+ if %r<(\A|/)src/> =~ path
54
+ path.sub(%r<.*(\A|/)src/>, '').sub(/\.rd\z/, '')
55
+ else
56
+ path
57
+ end
58
+ end
59
+
60
+ def get_c_filename(path)
61
+ File.basename(path, '.rd')
62
+ end
63
+
64
+ end
65
+ end
@@ -1,3 +1,3 @@
1
1
  module BitClust
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
@@ -34,9 +34,9 @@ HERE
34
34
  db = BitClust::FunctionDatabase.new(@tmpdir)
35
35
  cmd = case command
36
36
  when "lookup"
37
- BitClust::LookupCommand.new
37
+ BitClust::Subcommands::LookupCommand.new
38
38
  when "list"
39
- BitClust::ListCommand.new
39
+ BitClust::Subcommands::ListCommand.new
40
40
  else
41
41
  raise "must not happen! command=#{command}"
42
42
  end
data/test/test_entry.rb CHANGED
@@ -38,7 +38,7 @@ HERE
38
38
  assert_equal('Hoge', @lib.fetch_class("HogeHoge").realname)
39
39
  end
40
40
 
41
- def test_error_class_p
41
+ def test_error_class?
42
42
  assert(!@lib.fetch_class("Hoge").error_class?)
43
43
  assert(@lib.fetch_class("Err").error_class?)
44
44
  assert(!@lib.fetch_class("HogeHoge").error_class?)
@@ -3,12 +3,10 @@ require 'bitclust/methodsignature'
3
3
 
4
4
  class TestMethodSignature < Test::Unit::TestCase
5
5
 
6
- def test_friendlyname
7
- [
8
- ["$_ -> String | nil", "--- $_ -> String | nil"],
9
- ["`command` -> String", "--- `(command) -> String"],
10
- ].each do |friendly_string, method_signature|
11
- assert_equal friendly_string, BitClust::MethodSignature.parse(method_signature).friendly_string
12
- end
6
+ data("special var" => ["$_ -> String | nil", "--- $_ -> String | nil"],
7
+ "backquote" => ["`command` -> String", "--- `(command) -> String"])
8
+ def test_friendlyname(data)
9
+ friendly_string, method_signature = data
10
+ assert_equal(friendly_string, BitClust::MethodSignature.parse(method_signature).friendly_string)
13
11
  end
14
12
  end
@@ -5,179 +5,210 @@ class TestNameUtils < Test::Unit::TestCase
5
5
 
6
6
  include BitClust::NameUtils
7
7
 
8
- def test_libname?
9
- assert_equal true, libname?("_builtin")
10
- assert_equal true, libname?("fileutils")
11
- assert_equal true, libname?("socket")
12
- assert_equal true, libname?("open-uri")
13
- assert_equal true, libname?("net/http")
14
- assert_equal true, libname?("racc/cparse")
15
- assert_equal true, libname?("test/unit/testcase")
16
- assert_equal false, libname?("")
17
- assert_equal false, libname?("fileutils ")
18
- assert_equal false, libname?(" fileutils")
19
- assert_equal false, libname?("file utils")
20
- assert_equal false, libname?("fileutils\n")
21
- assert_equal false, libname?("fileutils\t")
22
- assert_equal false, libname?("fileutils.rb")
23
- assert_equal false, libname?("English.rb")
24
- assert_equal false, libname?("socket.so")
25
- assert_equal false, libname?("net/http.rb")
26
- assert_equal false, libname?("racc/cparse.so")
8
+ data("_builtin" => [true, "_builtin"],
9
+ "fileutils" => [true, "fileutils"],
10
+ "socket" => [true, "socket"],
11
+ "open-uri" => [true, "open-uri"],
12
+ "net/http" => [true, "net/http"],
13
+ "racc/cparse" => [true, "racc/cparse"],
14
+ "test/unit/testcase" => [true, "test/unit/testcase"],
15
+ "empty string" => [false, ""],
16
+ "following space" => [false, "fileutils "],
17
+ "leading space" => [false, " fileutils"],
18
+ "split by space" => [false, "file utils"],
19
+ "following new line" => [false, "fileutils\n"],
20
+ "folowing tab" => [false, "fileutils\t"],
21
+ "with extension .rb" => [false, "fileutils.rb"],
22
+ "CamelCase with extension .rb" => [false, "English.rb"],
23
+ "with extension .so" => [false, "socket.so"],
24
+ "sub library with extension .rb" => [false, "net/http.rb"],
25
+ "sub library with extension .so" => [false, "racc/cparse.so"])
26
+ def test_libname?(data)
27
+ expected, target = data
28
+ assert_equal(expected, libname?(target))
27
29
  end
28
30
 
29
- def test_libname2id
30
- assert_equal "_builtin", libname2id("_builtin")
31
- assert_equal "fileutils", libname2id("fileutils")
32
- assert_equal "socket", libname2id("socket")
33
- assert_equal "English", libname2id("English")
34
- assert_equal "open=2duri", libname2id("open-uri")
35
- assert_equal "net.http", libname2id("net/http")
36
- assert_equal "racc.cparse", libname2id("racc/cparse")
37
- assert_equal "test.unit.testcase", libname2id("test/unit/testcase")
31
+ data("_builtin" => ["_builtin", "_builtin"],
32
+ "fileutils" => ["fileutils", "fileutils"],
33
+ "socket" => ["socket", "socket"],
34
+ "English" => ["English", "English"],
35
+ "open-uri" => ["open=2duri", "open-uri"],
36
+ "net/http" => ["net.http", "net/http"],
37
+ "racc/cparse" => ["racc.cparse", "racc/cparse"],
38
+ "test/unit/testcase" => ["test.unit.testcase", "test/unit/testcase"])
39
+ def test_libname2id(data)
40
+ expected, target = data
41
+ assert_equal(expected, libname2id(target))
38
42
  end
39
43
 
40
- def test_libid2name
41
- assert_equal "_builtin", libid2name("_builtin")
42
- assert_equal "fileutils", libid2name("fileutils")
43
- assert_equal "socket", libid2name("socket")
44
- assert_equal "English", libid2name("English")
45
- assert_equal "open-uri", libid2name("open=2duri")
46
- assert_equal "net/http", libid2name("net.http")
47
- assert_equal "racc/cparse", libid2name("racc.cparse")
48
- assert_equal "test/unit/testcase", libid2name("test.unit.testcase")
44
+ data("_builtin" => ["_builtin", "_builtin"],
45
+ "fileutils" => ["fileutils", "fileutils"],
46
+ "socket" => ["socket", "socket"],
47
+ "English" => ["English", "English"],
48
+ "open=2duri" => ["open-uri", "open=2duri"],
49
+ "net.http" => ["net/http", "net.http"],
50
+ "racc.cparse" => ["racc/cparse", "racc.cparse"],
51
+ "test.unit.testcase" => ["test/unit/testcase", "test.unit.testcase"])
52
+ def test_libid2name(data)
53
+ expected, target = data
54
+ assert_equal(expected, libid2name(target))
49
55
  end
50
56
 
51
- def test_classname?
52
- assert_equal true, classname?("fatal")
53
- assert_equal true, classname?("Array")
54
- assert_equal true, classname?("String")
55
- assert_equal true, classname?("Net::HTTP")
56
- assert_equal true, classname?("Test::Unit::TestCase")
57
- assert_equal false, classname?("")
58
- assert_equal false, classname?("Array ")
59
- assert_equal false, classname?(" Array")
60
- assert_equal false, classname?("Test Case")
61
- assert_equal false, classname?("TestCase\n")
62
- assert_equal false, classname?("\tTestCase")
63
- assert_equal false, classname?("string")
64
- assert_equal false, classname?("stringScanner")
65
- assert_equal false, classname?("net/http")
66
- assert_equal false, classname?("net.http")
67
- assert_equal false, classname?("open-uri")
57
+ data("fatal" => [true, "fatal"],
58
+ "Array" => [true, "Array"],
59
+ "String" => [true, "String"],
60
+ "Net::HTTP" => [true, "Net::HTTP"],
61
+ "Test::Unit::TestCase" => [true, "Test::Unit::TestCase"],
62
+ "ARGF.class" => [true, "ARGF.class"],
63
+ "empty string" => [false, ""],
64
+ "following space" => [false, "Array "],
65
+ "leading space" => [false, " Array"],
66
+ "split by space" => [false, "Test Case"],
67
+ "following new line" => [false, "TestCase\n"],
68
+ "leading tab" => [false, "\tTestCase"],
69
+ "small case" => [false, "string"],
70
+ "camelCase" => [false, "stringScanner"],
71
+ "libname" => [false, "net/http"],
72
+ "libid" => [false, "net.http"],
73
+ "libname with '-'" => [false, "open-uri"])
74
+ def test_classname?(data)
75
+ expected, target = data
76
+ assert_equal(expected, classname?(target))
68
77
  end
69
78
 
70
- def test_classname2id
71
- assert_equal "Array", classname2id("Array")
72
- assert_equal "String", classname2id("String")
73
- assert_equal "Net=HTTP", classname2id("Net::HTTP")
74
- assert_equal "Test=Unit=TestCase", classname2id("Test::Unit::TestCase")
79
+ data("Array" => ["Array", "Array"],
80
+ "String" => ["String", "String"],
81
+ "Net::HTTP" => ["Net=HTTP", "Net::HTTP"],
82
+ "Test::Unit::TestCase" => ["Test=Unit=TestCase", "Test::Unit::TestCase"],
83
+ "ARGF.class" => ["ARGF.class", "ARGF.class"])
84
+ def test_classname2id(data)
85
+ expected, target = data
86
+ assert_equal(expected, classname2id(target))
75
87
  end
76
88
 
77
- def test_classid2name
78
- assert_equal "Array", classid2name("Array")
79
- assert_equal "String", classid2name("String")
80
- assert_equal "Net::HTTP", classid2name("Net=HTTP")
81
- assert_equal "Test::Unit::TestCase", classid2name("Test=Unit=TestCase")
89
+ data("Array" => ["Array", "Array"],
90
+ "String" => ["String", "String"],
91
+ "Net=HTTP" => ["Net::HTTP", "Net=HTTP"],
92
+ "Test=Unit=TestCase" => ["Test::Unit::TestCase", "Test=Unit=TestCase"],
93
+ "ARGF.class" => ["ARGF.class", "ARGF.class"])
94
+ def test_classid2name(data)
95
+ expected, target = data
96
+ assert_equal(expected, classid2name(target))
82
97
  end
83
98
 
84
- def test_method_spec?
85
- assert_equal true, method_spec?("String#index")
86
- assert_equal true, method_spec?("CGI#accept")
87
- assert_equal true, method_spec?("Net::HTTP#ca_path")
88
- assert_equal true, method_spec?("FileUtils.#cp")
99
+ data("String#index" => [true, "String#index"],
100
+ "CGI#accept" => [true, "CGI#accept"],
101
+ "Net::HTTP#ca_path" => [true, "Net::HTTP#ca_path"],
102
+ "FileUtils.#cp" => [true, "FileUtils.#cp"],
103
+ "ARGF.class#path" => [true, "ARGF.class#path"],
104
+ "ARGF.class" => [false, "ARGF.class"])
105
+ def test_method_spec?(data)
106
+ expected, target = data
107
+ assert_equal(expected, method_spec?(target))
89
108
  end
90
109
 
91
- def test_methodid2spec
92
- assert_equal "String#index", methodid2specstring("String/i.index._builtin")
93
- assert_equal "CGI#accept", methodid2specstring("CGI/i.accept.cgi")
94
- assert_equal "Net::HTTP#ca_path", methodid2specstring("Net=HTTP/i.ca_path.net.http")
95
- assert_equal "FileUtils.#cp", methodid2specstring("FileUtils/m.cp.fileutils")
110
+ data("String/i.index._builtin" => ["String#index", "String/i.index._builtin"],
111
+ "CGI/i.accept.cgi" => ["CGI#accept", "CGI/i.accept.cgi"],
112
+ "Net=HTTP/i.ca_path.net.http" => ["Net::HTTP#ca_path", "Net=HTTP/i.ca_path.net.http"],
113
+ "FileUtils/m.cp.fileutils" => ["FileUtils.#cp", "FileUtils/m.cp.fileutils"],
114
+ "ARGF.class/i.filename.ARGF" => ["ARGF.class#filename", "ARGF.class/i.filename.ARGF"])
115
+ def test_methodid2spec(data)
116
+ expected, target = data
117
+ assert_equal(expected, methodid2specstring(target))
96
118
  end
97
119
 
98
- def test_methodid2libid
99
- assert_equal "_builtin", methodid2libid("String/i.index._builtin")
100
- assert_equal "cgi", methodid2libid("CGI/i.accept.cgi")
101
- assert_equal "net.http", methodid2libid("Net=HTTP/i.ca_path.net.http")
102
- assert_equal "open=2duri", methodid2libid("OpenURI/m.open.open=2duri")
120
+ data("String/i.index._builtin" => ["_builtin", "String/i.index._builtin"],
121
+ "CGI/i.accept.cgi" => ["cgi", "CGI/i.accept.cgi"],
122
+ "Net=HTTP/i.ca_path.net.http" => ["net.http", "Net=HTTP/i.ca_path.net.http"],
123
+ "OpenURI/m.open.open=2duri" => ["open=2duri", "OpenURI/m.open.open=2duri"])
124
+ def test_methodid2libid(data)
125
+ expected, target = data
126
+ assert_equal(expected, methodid2libid(target))
103
127
  end
104
128
 
105
- def test_methodid2classid
106
- assert_equal "String", methodid2classid("String/i.index._builtin")
107
- assert_equal "CGI", methodid2classid("CGI/i.accept.cgi")
108
- assert_equal "Net=HTTP", methodid2classid("Net=HTTP/i.ca_path.net.http")
129
+ data("String/i.index._builtin" => ["String", "String/i.index._builtin"],
130
+ "CGI/i.accept.cgi" => ["CGI", "CGI/i.accept.cgi"],
131
+ "Net=HTTP/i.ca_path.net.http" => ["Net=HTTP", "Net=HTTP/i.ca_path.net.http"])
132
+ def test_methodid2classid(data)
133
+ expected, target = data
134
+ assert_equal(expected, methodid2classid(target))
109
135
  end
110
136
 
111
- def test_methodid2typename
112
- assert_equal :instance_method, methodid2typename("String/i.index._builtin")
113
- assert_equal :instance_method, methodid2typename("CGI/i.accept.cgi")
114
- assert_equal :instance_method, methodid2typename("Net=HTTP/i.ca_path.net.http")
115
- assert_equal :singleton_method, methodid2typename("String/s.new._builtin")
137
+ data("String/i.index._builtin" => [:instance_method, "String/i.index._builtin"],
138
+ "CGI/i.accept.cgi" => [:instance_method, "CGI/i.accept.cgi"],
139
+ "Net=HTTP/i.ca_path.net.http" => [:instance_method, "Net=HTTP/i.ca_path.net.http"],
140
+ "String/s.new._builtin" => [:singleton_method, "String/s.new._builtin"])
141
+ def test_methodid2typename(data)
142
+ expected, target = data
143
+ assert_equal(expected, methodid2typename(target))
116
144
  end
117
145
 
118
- def test_methodid2mname
119
- assert_equal "index", methodid2mname("String/i.index._builtin")
120
- assert_equal "accept", methodid2mname("CGI/i.accept.cgi")
121
- assert_equal "ca_path", methodid2mname("Net=HTTP/i.ca_path.net.http")
146
+ data("String/i.index._builtin" => ["index", "String/i.index._builtin"],
147
+ "CGI/i.accept.cgi" => ["accept", "CGI/i.accept.cgi"],
148
+ "Net=HTTP/i.ca_path.net.http" => ["ca_path", "Net=HTTP/i.ca_path.net.http"])
149
+ def test_methodid2mname(data)
150
+ expected, target = data
151
+ assert_equal(expected, methodid2mname(target))
122
152
  end
123
153
 
124
- def test_methodname?
125
- assert_equal true, methodname?("index")
126
- assert_equal true, methodname?("accept")
127
- assert_equal true, methodname?("get")
128
- assert_equal true, methodname?("Array")
129
- assert_equal true, methodname?("getIndex")
130
- assert_equal true, methodname?("PROXY")
131
- assert_equal true, methodname?("HTTP_PROXY")
132
- assert_equal true, methodname?("gsub!")
133
- assert_equal true, methodname?("empty?")
134
- assert_equal true, methodname?("instance_eval")
135
- assert_equal true, methodname?("__send")
136
- assert_equal true, methodname?("__send__")
137
- assert_equal true, methodname?("__send!")
138
- assert_equal true, methodname?("+")
139
- assert_equal true, methodname?("-")
140
- assert_equal true, methodname?("*")
141
- assert_equal true, methodname?("/")
142
- assert_equal true, methodname?("&")
143
- assert_equal true, methodname?("|")
144
- assert_equal true, methodname?("^")
145
- assert_equal true, methodname?("`")
146
- assert_equal true, methodname?(">>")
147
- assert_equal true, methodname?("<<")
148
- assert_equal true, methodname?("+@")
149
- assert_equal true, methodname?("-@")
150
- assert_equal true, methodname?("!")
151
- assert_equal true, methodname?("!@")
152
- assert_equal true, methodname?("~")
153
- assert_equal true, methodname?("**")
154
- assert_equal true, methodname?("<")
155
- assert_equal true, methodname?(">")
156
- assert_equal true, methodname?("<=")
157
- assert_equal true, methodname?(">=")
158
- assert_equal true, methodname?("==")
159
- assert_equal true, methodname?("===")
160
- assert_equal true, methodname?("=~")
161
- assert_equal true, methodname?("[]")
162
- assert_equal true, methodname?("[]=")
163
-
164
- assert_equal false, methodname?("")
165
- assert_equal true, methodname?("!=")
166
- assert_equal true, methodname?("!~")
167
- assert_equal false, methodname?("&&")
168
- assert_equal false, methodname?("||")
169
- assert_equal false, methodname?("++")
170
- assert_equal false, methodname?(">>>")
171
- assert_equal false, methodname?("***")
172
- assert_equal false, methodname?("====")
173
- assert_equal false, methodname?("#accept")
174
- assert_equal false, methodname?(".new")
175
- assert_equal false, methodname?(".#cp")
176
- assert_equal false, methodname?("$gvar")
177
- assert_equal false, methodname?("CGI#accept")
178
- assert_equal false, methodname?("String.new")
179
- assert_equal false, methodname?("Net::HTTP.get")
180
- assert_equal false, methodname?("Net::HTTP.new")
154
+ data("index" => [true, "index"],
155
+ "accept" => [true, "accept"],
156
+ "get" => [true, "get"],
157
+ "Array" => [true, "Array"],
158
+ "getIndex" => [true, "getIndex"],
159
+ "PROXY" => [true, "PROXY"],
160
+ "HTTP_PROXY" => [true, "HTTP_PROXY"],
161
+ "gsub!" => [true, "gsub!"],
162
+ "empty? " => [true, "empty?"],
163
+ "instance_eval" => [true, "instance_eval"],
164
+ "__send" => [true, "__send"],
165
+ "__send__" => [true, "__send__"],
166
+ "__send!" => [true, "__send!"],
167
+ "+" => [true, "+"],
168
+ "-" => [true, "-"],
169
+ "*" => [true, "*"],
170
+ "/" => [true, "/"],
171
+ "&" => [true, "&"],
172
+ "|" => [true, "|"],
173
+ "^" => [true, "^"],
174
+ "`" => [true, "`"],
175
+ ">>" => [true, ">>"],
176
+ "<<" => [true, "<<"],
177
+ "+@" => [true, "+@"],
178
+ "-@" => [true, "-@"],
179
+ "!" => [true, "!"],
180
+ "!@" => [true, "!@"],
181
+ "~" => [true, "~"],
182
+ "**" => [true, "**"],
183
+ "<" => [true, "<"],
184
+ ">" => [true, ">"],
185
+ "<=" => [true, "<="],
186
+ ">=" => [true, ">="],
187
+ "==" => [true, "=="],
188
+ "===" => [true, "==="],
189
+ "=~" => [true, "=~"],
190
+ "[]" => [true, "[]"],
191
+ "[]=" => [true, "[]="],
192
+ "" => [false, ""],
193
+ "!=" => [true, "!="],
194
+ "!~" => [true, "!~"],
195
+ "&&" => [false, "&&"],
196
+ "||" => [false, "||"],
197
+ "++" => [false, "++"],
198
+ ">>>" => [false, ">>>"],
199
+ "***" => [false, "***"],
200
+ "====" => [false, "===="],
201
+ "#accept" => [false, "#accept"],
202
+ ".new" => [false, ".new"],
203
+ ".#cp" => [false, ".#cp"],
204
+ "$gvar" => [false, "$gvar"],
205
+ "CGI#accept" => [false, "CGI#accept"],
206
+ "String.new" => [false, "String.new"],
207
+ "Net::HTTP.get" => [false, "Net::HTTP.get"],
208
+ "Net::HTTP.new" => [false, "Net::HTTP.new"])
209
+ def test_methodname?(data)
210
+ expected, target = data
211
+ assert_equal(expected, methodname?(target))
181
212
  end
182
213
 
183
214
  def test_build_method_id
@@ -191,134 +222,167 @@ class TestNameUtils < Test::Unit::TestCase
191
222
  # split_method_id("String/i.index._builtin")
192
223
  #end
193
224
 
194
- def test_typename?
195
- assert_equal true, typename?(:instance_method)
196
- assert_equal true, typename?(:singleton_method)
197
- assert_equal true, typename?(:module_function)
198
- assert_equal true, typename?(:constant)
199
- assert_equal true, typename?(:special_variable)
200
- assert_equal false, typename?(:instance_eval)
201
- assert_equal false, typename?(:instance)
202
- assert_equal false, typename?(:singleton)
203
- assert_equal false, typename?("i")
204
- assert_equal false, typename?("s")
205
- assert_equal false, typename?(:i)
206
- assert_equal false, typename?(:s)
225
+ data(:instance_method => [true, :instance_method],
226
+ :singleton_method => [true, :singleton_method],
227
+ :module_function => [true, :module_function],
228
+ :constant => [true, :constant],
229
+ :special_variable => [true, :special_variable],
230
+ :instance_eval => [false, :instance_eval],
231
+ :instance => [false, :instance],
232
+ :singleton => [false, :singleton],
233
+ "i" => [false, "i"],
234
+ "s" => [false, "s"],
235
+ :i => [false, :i],
236
+ :s => [false, :s])
237
+ def test_typename?(data)
238
+ expected, target = data
239
+ assert_equal(expected, typename?(target))
207
240
  end
208
241
 
209
- def test_typemark?
210
- assert_equal true, typemark?('.')
211
- assert_equal true, typemark?('#')
212
- assert_equal true, typemark?('.#')
213
- assert_equal true, typemark?('$')
214
- assert_equal true, typemark?('::')
242
+ data do
243
+ data_set = {}
244
+ typemarks = [".", "#", ".#", "$", "::"]
245
+ typemarks.each do |mark|
246
+ data_set[mark] = [true, mark]
247
+ end
215
248
  #marks = (0..255).map {|a| (0..255).map {|b| a.chr + b.chr } }.flatten
216
249
  marks = (0..127).map {|a| (0..127).map {|b| a.chr + b.chr } }.flatten
217
- (marks - %w( . # .# $ :: )).each do |m|
218
- assert_equal false, typemark?(m)
250
+ (marks - typemarks).each do |m|
251
+ data_set[m] = [false, m]
219
252
  end
253
+ data_set
254
+ end
255
+ def test_typemark?(data)
256
+ expected, target = data
257
+ assert_equal(expected, typemark?(target))
220
258
  end
221
259
 
222
- def test_typechar?
260
+ data do
261
+ data_set = {}
223
262
  typechars = %w( i s m c v )
224
- typechars.each do |c|
225
- assert_equal true, typechar?(c)
263
+ typechars.each do |char|
264
+ data_set[char] = [true, char]
226
265
  end
227
- ((0..255).map {|b| b.chr } - typechars).each do |c|
228
- assert_equal false, typechar?(c)
266
+ ((0..255).map {|b| b.chr } - typechars).each do |char|
267
+ data_set[char] = [false, char]
229
268
  end
269
+ data_set
270
+ end
271
+ def test_typechar?(data)
272
+ expected, target = data
273
+ assert_equal(expected, typechar?(target))
230
274
  end
231
275
 
232
- def test_typename2char
233
- assert_equal 's', typename2char(:singleton_method)
234
- assert_equal 'i', typename2char(:instance_method)
235
- assert_equal 'm', typename2char(:module_function)
236
- assert_equal 'c', typename2char(:constant)
237
- assert_equal 'v', typename2char(:special_variable)
276
+ data(:singleton_method => ["s", :singleton_method],
277
+ :instance_method => ["i", :instance_method],
278
+ :module_function => ["m", :module_function],
279
+ :constant => ["c", :constant],
280
+ :special_variable => ["v", :special_variable])
281
+ def test_typename2char(data)
282
+ expected, target = data
283
+ assert_equal(expected, typename2char(target))
238
284
  end
239
285
 
240
- def test_typechar2name
241
- assert_equal :singleton_method, typechar2name('s')
242
- assert_equal :instance_method, typechar2name('i')
243
- assert_equal :module_function, typechar2name('m')
244
- assert_equal :constant, typechar2name('c')
245
- assert_equal :special_variable, typechar2name('v')
286
+ data("s" => [:singleton_method, "s"],
287
+ "i" => [:instance_method, "i"],
288
+ "m" => [:module_function, "m"],
289
+ "c" => [:constant, "c"],
290
+ "v" => [:special_variable, "v"])
291
+ def test_typechar2name(data)
292
+ expected, target = data
293
+ assert_equal(expected, typechar2name(target))
246
294
  end
247
295
 
248
- def test_typemark2char
249
- assert_equal 's', typemark2char('.')
250
- assert_equal 'i', typemark2char('#')
251
- assert_equal 'm', typemark2char('.#')
252
- assert_equal 'c', typemark2char('::')
253
- assert_equal 'v', typemark2char('$')
296
+ data("." => ["s", "."],
297
+ "#" => ["i", "#"],
298
+ ".#" => ["m", ".#"],
299
+ "::" => ["c", "::"],
300
+ "$" => ["v", "$"])
301
+ def test_typemark2char(data)
302
+ expected, target = data
303
+ assert_equal(expected, typemark2char(target))
254
304
  end
255
305
 
256
- def test_typechar2mark
257
- assert_equal '.', typechar2mark('s')
258
- assert_equal '#', typechar2mark('i')
259
- assert_equal '.#', typechar2mark('m')
260
- assert_equal '::', typechar2mark('c')
261
- assert_equal '$', typechar2mark('v')
306
+ data("s" => [".", "s"],
307
+ "i" => ["#", "i"],
308
+ "m" => [".#", "m"],
309
+ "c" => ["::", "c"],
310
+ "v" => ["$", "v"])
311
+ def test_typechar2mark(data)
312
+ expected, target = data
313
+ assert_equal(expected, typechar2mark(target))
262
314
  end
263
315
 
264
- def test_encodename_url
265
- assert_equal "Array", encodename_url("Array")
266
- assert_equal "String", encodename_url("String")
267
- assert_equal "index", encodename_url("index")
268
- assert_equal "=2a", encodename_url("*")
269
- assert_equal "=2a=2a", encodename_url("**")
270
- assert_equal "open=2duri", encodename_url("open-uri")
271
- assert_equal "net=2ehttp", encodename_url("net.http")
316
+ data("Array" => ["Array", "Array"],
317
+ "String" => ["String", "String"],
318
+ "index" => ["index", "index"],
319
+ "*" => ["=2a", "*"],
320
+ "**" => ["=2a=2a", "**"],
321
+ "open-uri" => ["open=2duri", "open-uri"],
322
+ "net.http" => ["net=2ehttp", "net.http"])
323
+ def test_encodename_url(data)
324
+ expected, target = data
325
+ assert_equal(expected, encodename_url(target))
272
326
  end
273
327
 
274
- def test_decodename_url
275
- assert_equal "Array", decodename_url("Array")
276
- assert_equal "String", decodename_url("String")
277
- assert_equal "index", decodename_url("index")
278
- assert_equal "*", decodename_url("=2a")
279
- assert_equal "**", decodename_url("=2a=2a")
280
- assert_equal "open-uri", decodename_url("open=2duri")
281
- assert_equal "net.http", decodename_url("net=2ehttp")
328
+ data("Array" => ["Array", "Array"],
329
+ "String" => ["String", "String"],
330
+ "index" => ["index", "index"],
331
+ "=2a" => ["*", "=2a"],
332
+ "=2a=2a" => ["**", "=2a=2a"],
333
+ "open=2duri" => ["open-uri", "open=2duri"],
334
+ "net=2ehttp" => ["net.http", "net=2ehttp"])
335
+ def test_decodename_url(data)
336
+ expected, target = data
337
+ assert_equal(expected, decodename_url(target))
282
338
  end
283
339
 
340
+ data("Array" => ["-array", "Array"],
341
+ "String" => ["-string", "String"],
342
+ "CGI" => ["-c-g-i", "CGI"],
343
+ "=2a" => ["=2a", "=2a"],
344
+ "=2a=2a" => ["=2a=2a", "=2a=2a"],
345
+ "open=2duri" => ["open=2duri", "open=2duri"],
346
+ "Net=HTTP" => ["-net=-h-t-t-p", "Net=HTTP"])
284
347
  def test_encodeid
285
- assert_equal "-array", encodeid("Array")
286
- assert_equal "-string", encodeid("String")
287
- assert_equal "-c-g-i", encodeid("CGI")
288
- assert_equal "=2a", encodeid("=2a")
289
- assert_equal "=2a=2a", encodeid("=2a=2a")
290
- assert_equal "open=2duri", encodeid("open=2duri")
291
- assert_equal "-net=-h-t-t-p", encodeid("Net=HTTP")
348
+ expected, target = data
349
+ assert_equal(expected, encodeid(target))
292
350
  end
293
351
 
352
+ data("-array" => ["Array", "-array"],
353
+ "-string" => ["String", "-string"],
354
+ "-c-g-i" => ["CGI", "-c-g-i"],
355
+ "=2a" => ["=2a", "=2a"],
356
+ "=2a=2a" => ["=2a=2a", "=2a=2a"],
357
+ "open=2duri" => ["open=2duri", "open=2duri"],
358
+ "-net=-h-t-t-p" => ["Net=HTTP", "-net=-h-t-t-p"])
294
359
  def test_decodeid
295
- assert_equal "Array", decodeid("-array")
296
- assert_equal "String", decodeid("-string")
297
- assert_equal "CGI", decodeid("-c-g-i")
298
- assert_equal "=2a", decodeid("=2a")
299
- assert_equal "=2a=2a", decodeid("=2a=2a")
300
- assert_equal "open=2duri", decodeid("open=2duri")
301
- assert_equal "Net=HTTP", decodeid("-net=-h-t-t-p")
360
+ expected, target = data
361
+ assert_equal(expected, decodeid(target))
302
362
  end
303
363
 
364
+ data("Array" => ["-array", "Array"],
365
+ "String" => ["-string", "String"],
366
+ "index" => ["index", "index"],
367
+ "*" => ["=2a", "*"],
368
+ "**" => ["=2a=2a", "**"],
369
+ "open-uri" => ["open=2duri", "open-uri"],
370
+ "net.http" => ["net=2ehttp", "net.http"])
304
371
  def test_encodename_fs
305
- assert_equal "-array", encodename_fs("Array")
306
- assert_equal "-string", encodename_fs("String")
307
- assert_equal "index", encodename_fs("index")
308
- assert_equal "=2a", encodename_fs("*")
309
- assert_equal "=2a=2a", encodename_fs("**")
310
- assert_equal "open=2duri", encodename_fs("open-uri")
311
- assert_equal "net=2ehttp", encodename_fs("net.http")
372
+ expected, target = data
373
+ assert_equal(expected, encodename_fs(target))
312
374
  end
313
375
 
376
+ data("-array" => ["Array", "-array"],
377
+ "-string" => ["String", "-string"],
378
+ "index" => ["index", "index"],
379
+ "=2a" => ["*", "=2a"],
380
+ "=2a=2a" => ["**", "=2a=2a"],
381
+ "open=2duri" => ["open-uri", "open=2duri"],
382
+ "net=2ehttp" => ["net.http", "net=2ehttp"])
314
383
  def test_decodename_fs
315
- assert_equal "Array", decodename_fs("-array")
316
- assert_equal "String", decodename_fs("-string")
317
- assert_equal "index", decodename_fs("index")
318
- assert_equal "*", decodename_fs("=2a")
319
- assert_equal "**", decodename_fs("=2a=2a")
320
- assert_equal "open-uri", decodename_fs("open=2duri")
321
- assert_equal "net.http", decodename_fs("net=2ehttp")
384
+ expected, target = data
385
+ assert_equal(expected, decodename_fs(target))
322
386
  end
323
387
 
324
388
  end