rroonga 0.9.2-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. data/AUTHORS +5 -0
  2. data/NEWS.ja.rdoc +114 -0
  3. data/NEWS.rdoc +116 -0
  4. data/README.ja.rdoc +65 -0
  5. data/README.rdoc +66 -0
  6. data/Rakefile +217 -0
  7. data/benchmark/common.rb +49 -0
  8. data/benchmark/read-write-many-small-items.rb +144 -0
  9. data/benchmark/write-many-small-items.rb +135 -0
  10. data/example/bookmark.rb +161 -0
  11. data/example/index-html.rb +89 -0
  12. data/example/search/config.ru +211 -0
  13. data/example/search/public/css/groonga.css +122 -0
  14. data/ext/.gitignore +2 -0
  15. data/ext/libruby-groonga.a +0 -0
  16. data/ext/rb-grn-accessor.c +52 -0
  17. data/ext/rb-grn-array-cursor.c +36 -0
  18. data/ext/rb-grn-array.c +210 -0
  19. data/ext/rb-grn-column.c +573 -0
  20. data/ext/rb-grn-context.c +655 -0
  21. data/ext/rb-grn-database.c +472 -0
  22. data/ext/rb-grn-encoding-support.c +64 -0
  23. data/ext/rb-grn-encoding.c +257 -0
  24. data/ext/rb-grn-exception.c +1110 -0
  25. data/ext/rb-grn-expression-builder.c +75 -0
  26. data/ext/rb-grn-expression.c +735 -0
  27. data/ext/rb-grn-fix-size-column.c +166 -0
  28. data/ext/rb-grn-hash-cursor.c +38 -0
  29. data/ext/rb-grn-hash.c +294 -0
  30. data/ext/rb-grn-index-column.c +488 -0
  31. data/ext/rb-grn-logger.c +504 -0
  32. data/ext/rb-grn-object.c +1369 -0
  33. data/ext/rb-grn-operation.c +198 -0
  34. data/ext/rb-grn-patricia-trie-cursor.c +39 -0
  35. data/ext/rb-grn-patricia-trie.c +488 -0
  36. data/ext/rb-grn-procedure.c +52 -0
  37. data/ext/rb-grn-query.c +260 -0
  38. data/ext/rb-grn-record.c +40 -0
  39. data/ext/rb-grn-snippet.c +334 -0
  40. data/ext/rb-grn-table-cursor-key-support.c +69 -0
  41. data/ext/rb-grn-table-cursor.c +247 -0
  42. data/ext/rb-grn-table-key-support.c +731 -0
  43. data/ext/rb-grn-table.c +2141 -0
  44. data/ext/rb-grn-type.c +181 -0
  45. data/ext/rb-grn-utils.c +769 -0
  46. data/ext/rb-grn-variable-size-column.c +36 -0
  47. data/ext/rb-grn-variable.c +108 -0
  48. data/ext/rb-grn-view-accessor.c +53 -0
  49. data/ext/rb-grn-view-cursor.c +35 -0
  50. data/ext/rb-grn-view-record.c +41 -0
  51. data/ext/rb-grn-view.c +421 -0
  52. data/ext/rb-grn.h +700 -0
  53. data/ext/rb-groonga.c +117 -0
  54. data/extconf.rb +266 -0
  55. data/html/bar.svg +153 -0
  56. data/html/developer.html +117 -0
  57. data/html/developer.svg +469 -0
  58. data/html/download.svg +253 -0
  59. data/html/favicon.ico +0 -0
  60. data/html/favicon.xcf +0 -0
  61. data/html/footer.html.erb +28 -0
  62. data/html/head.html.erb +4 -0
  63. data/html/header.html.erb +17 -0
  64. data/html/index.html +147 -0
  65. data/html/install.svg +636 -0
  66. data/html/logo.xcf +0 -0
  67. data/html/ranguba.css +250 -0
  68. data/html/tutorial.svg +559 -0
  69. data/lib/groonga.rb +90 -0
  70. data/lib/groonga/context.rb +184 -0
  71. data/lib/groonga/expression-builder.rb +285 -0
  72. data/lib/groonga/patricia-trie.rb +53 -0
  73. data/lib/groonga/record.rb +311 -0
  74. data/lib/groonga/schema.rb +1191 -0
  75. data/lib/groonga/view-record.rb +56 -0
  76. data/license/GPL +340 -0
  77. data/license/LGPL +504 -0
  78. data/license/RUBY +59 -0
  79. data/misc/grnop2ruby.rb +49 -0
  80. data/pkg-config.rb +333 -0
  81. data/test-unit/Rakefile +40 -0
  82. data/test-unit/TODO +5 -0
  83. data/test-unit/bin/testrb +5 -0
  84. data/test-unit/html/classic.html +15 -0
  85. data/test-unit/html/index.html +25 -0
  86. data/test-unit/html/index.html.ja +27 -0
  87. data/test-unit/lib/test/unit.rb +323 -0
  88. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  89. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  90. data/test-unit/lib/test/unit/attribute.rb +125 -0
  91. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  92. data/test-unit/lib/test/unit/collector.rb +36 -0
  93. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  94. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  95. data/test-unit/lib/test/unit/collector/load.rb +136 -0
  96. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  97. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  98. data/test-unit/lib/test/unit/color.rb +96 -0
  99. data/test-unit/lib/test/unit/diff.rb +724 -0
  100. data/test-unit/lib/test/unit/error.rb +130 -0
  101. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  102. data/test-unit/lib/test/unit/failure.rb +136 -0
  103. data/test-unit/lib/test/unit/fixture.rb +176 -0
  104. data/test-unit/lib/test/unit/notification.rb +129 -0
  105. data/test-unit/lib/test/unit/omission.rb +191 -0
  106. data/test-unit/lib/test/unit/pending.rb +150 -0
  107. data/test-unit/lib/test/unit/priority.rb +180 -0
  108. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  109. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  110. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  111. data/test-unit/lib/test/unit/testcase.rb +476 -0
  112. data/test-unit/lib/test/unit/testresult.rb +89 -0
  113. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  114. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  115. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  116. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  117. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  118. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  119. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  120. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  121. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  122. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  123. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  124. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  125. data/test-unit/lib/test/unit/version.rb +7 -0
  126. data/test-unit/sample/adder.rb +13 -0
  127. data/test-unit/sample/subtracter.rb +12 -0
  128. data/test-unit/sample/test_adder.rb +20 -0
  129. data/test-unit/sample/test_subtracter.rb +20 -0
  130. data/test-unit/sample/test_user.rb +23 -0
  131. data/test-unit/test/collector/test-descendant.rb +133 -0
  132. data/test-unit/test/collector/test-load.rb +348 -0
  133. data/test-unit/test/collector/test_dir.rb +406 -0
  134. data/test-unit/test/collector/test_objectspace.rb +100 -0
  135. data/test-unit/test/run-test.rb +15 -0
  136. data/test-unit/test/test-attribute.rb +86 -0
  137. data/test-unit/test/test-color-scheme.rb +67 -0
  138. data/test-unit/test/test-color.rb +47 -0
  139. data/test-unit/test/test-diff.rb +518 -0
  140. data/test-unit/test/test-emacs-runner.rb +60 -0
  141. data/test-unit/test/test-fixture.rb +287 -0
  142. data/test-unit/test/test-notification.rb +33 -0
  143. data/test-unit/test/test-omission.rb +81 -0
  144. data/test-unit/test/test-pending.rb +70 -0
  145. data/test-unit/test/test-priority.rb +119 -0
  146. data/test-unit/test/test-testcase.rb +544 -0
  147. data/test-unit/test/test_assertions.rb +1151 -0
  148. data/test-unit/test/test_error.rb +26 -0
  149. data/test-unit/test/test_failure.rb +33 -0
  150. data/test-unit/test/test_testresult.rb +113 -0
  151. data/test-unit/test/test_testsuite.rb +129 -0
  152. data/test-unit/test/testunit-test-util.rb +14 -0
  153. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  154. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  155. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  156. data/test-unit/test/util/test_observable.rb +102 -0
  157. data/test-unit/test/util/test_procwrapper.rb +36 -0
  158. data/test/.gitignore +1 -0
  159. data/test/groonga-test-utils.rb +133 -0
  160. data/test/run-test.rb +58 -0
  161. data/test/test-array.rb +97 -0
  162. data/test/test-column.rb +316 -0
  163. data/test/test-context-select.rb +93 -0
  164. data/test/test-context.rb +73 -0
  165. data/test/test-database.rb +113 -0
  166. data/test/test-encoding.rb +33 -0
  167. data/test/test-exception.rb +93 -0
  168. data/test/test-expression-builder.rb +156 -0
  169. data/test/test-expression.rb +134 -0
  170. data/test/test-fix-size-column.rb +65 -0
  171. data/test/test-gqtp.rb +72 -0
  172. data/test/test-hash.rb +312 -0
  173. data/test/test-index-column.rb +81 -0
  174. data/test/test-logger.rb +37 -0
  175. data/test/test-patricia-trie.rb +189 -0
  176. data/test/test-procedure.rb +37 -0
  177. data/test/test-query.rb +22 -0
  178. data/test/test-record.rb +279 -0
  179. data/test/test-remote.rb +54 -0
  180. data/test/test-schema-view.rb +90 -0
  181. data/test/test-schema.rb +459 -0
  182. data/test/test-snippet.rb +130 -0
  183. data/test/test-table-cursor.rb +153 -0
  184. data/test/test-table-offset-and-limit.rb +102 -0
  185. data/test/test-table-select-normalize.rb +53 -0
  186. data/test/test-table-select.rb +150 -0
  187. data/test/test-table.rb +690 -0
  188. data/test/test-type.rb +71 -0
  189. data/test/test-variable-size-column.rb +98 -0
  190. data/test/test-variable.rb +28 -0
  191. data/test/test-vector-column.rb +76 -0
  192. data/test/test-version.rb +31 -0
  193. data/test/test-view.rb +72 -0
  194. data/text/TUTORIAL.ja.rdoc +392 -0
  195. data/text/expression.rdoc +284 -0
  196. data/vendor/local/bin/grntest.exe +0 -0
  197. data/vendor/local/bin/groonga.exe +0 -0
  198. data/vendor/local/bin/libgroonga.dll +0 -0
  199. data/vendor/local/bin/libmecab.dll +0 -0
  200. data/vendor/local/include/groonga.h +2285 -0
  201. data/vendor/local/lib/libgroonga.lib +0 -0
  202. metadata +280 -0
@@ -0,0 +1,36 @@
1
+ module Test
2
+ module Unit
3
+ module Collector
4
+ def initialize
5
+ @filters = []
6
+ end
7
+
8
+ def filter=(filters)
9
+ @filters = case(filters)
10
+ when Proc
11
+ [filters]
12
+ when Array
13
+ filters
14
+ end
15
+ end
16
+
17
+ def add_suite(destination, suite)
18
+ to_delete = suite.tests.find_all{|t| !include?(t)}
19
+ to_delete.each{|t| suite.delete(t)}
20
+ destination << suite unless(suite.size == 0)
21
+ end
22
+
23
+ def include?(test)
24
+ return true if(@filters.empty?)
25
+ @filters.each do |filter|
26
+ return false if filter[test] == false
27
+ end
28
+ true
29
+ end
30
+
31
+ def sort(suites)
32
+ suites.sort_by {|suite| suite.name || suite.to_s}
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ require 'test/unit/collector'
2
+
3
+ module Test
4
+ module Unit
5
+ module Collector
6
+ class Descendant
7
+ include Collector
8
+
9
+ NAME = 'collected from the subclasses of TestCase'
10
+
11
+ def collect(name=NAME)
12
+ suite = TestSuite.new(name)
13
+ sub_suites = []
14
+ TestCase::DESCENDANTS.each do |descendant_test_case|
15
+ add_suite(sub_suites, descendant_test_case.suite)
16
+ end
17
+ sort(sub_suites).each {|s| suite << s}
18
+ suite
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,108 @@
1
+ require 'test/unit/testsuite'
2
+ require 'test/unit/collector'
3
+
4
+ module Test
5
+ module Unit
6
+ module Collector
7
+ class Dir
8
+ include Collector
9
+
10
+ attr_reader :pattern, :exclude
11
+ attr_accessor :base
12
+
13
+ def initialize(dir=::Dir, file=::File, object_space=::ObjectSpace, req=nil)
14
+ super()
15
+ @dir = dir
16
+ @file = file
17
+ @object_space = object_space
18
+ @req = req
19
+ @pattern = [/\btest_.*\.rb\Z/m]
20
+ @exclude = []
21
+ @base = nil
22
+ end
23
+
24
+ def collect(*from)
25
+ basedir = @base
26
+ $:.push(basedir) if basedir
27
+ if(from.empty?)
28
+ recursive_collect('.', find_test_cases)
29
+ elsif(from.size == 1)
30
+ recursive_collect(from.first, find_test_cases)
31
+ else
32
+ suites = []
33
+ from.each do |f|
34
+ suite = recursive_collect(f, find_test_cases)
35
+ suites << suite unless(suite.tests.empty?)
36
+ end
37
+ suite = TestSuite.new("[#{from.join(', ')}]")
38
+ sort(suites).each{|s| suite << s}
39
+ suite
40
+ end
41
+ ensure
42
+ $:.delete_at($:.rindex(basedir)) if basedir
43
+ end
44
+
45
+ def find_test_cases(ignore=[])
46
+ cases = []
47
+ @object_space.each_object(Class) do |c|
48
+ cases << c if(c < TestCase && !ignore.include?(c))
49
+ end
50
+ ignore.concat(cases)
51
+ cases
52
+ end
53
+
54
+ def recursive_collect(name, already_gathered)
55
+ sub_suites = []
56
+ path = realdir(name)
57
+ if @file.directory?(path)
58
+ dir_name = name unless name == '.'
59
+ @dir.entries(path).each do |e|
60
+ next if(e == '.' || e == '..')
61
+ e_name = dir_name ? @file.join(dir_name, e) : e
62
+ if @file.directory?(realdir(e_name))
63
+ next if /\A(?:CVS|\.svn|\.git)\z/ =~ e
64
+ sub_suite = recursive_collect(e_name, already_gathered)
65
+ sub_suites << sub_suite unless(sub_suite.empty?)
66
+ else
67
+ next if /~\z/ =~ e_name or /\A\.\#/ =~ e
68
+ if @pattern and !@pattern.empty?
69
+ next unless @pattern.any? {|pat| pat =~ e_name}
70
+ end
71
+ if @exclude and !@exclude.empty?
72
+ next if @exclude.any? {|pat| pat =~ e_name}
73
+ end
74
+ collect_file(e_name, sub_suites, already_gathered)
75
+ end
76
+ end
77
+ else
78
+ collect_file(name, sub_suites, already_gathered)
79
+ end
80
+ suite = TestSuite.new(@file.basename(name))
81
+ sort(sub_suites).each{|s| suite << s}
82
+ suite
83
+ end
84
+
85
+ def collect_file(name, suites, already_gathered)
86
+ dir = @file.dirname(@file.expand_path(name, @base))
87
+ $:.unshift(dir)
88
+ if(@req)
89
+ @req.require(name)
90
+ else
91
+ require(name)
92
+ end
93
+ find_test_cases(already_gathered).each{|t| add_suite(suites, t.suite)}
94
+ ensure
95
+ $:.delete_at($:.rindex(dir)) if(dir)
96
+ end
97
+
98
+ def realdir(path)
99
+ if @base
100
+ @file.join(@base, path)
101
+ else
102
+ path
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,136 @@
1
+ require 'pathname'
2
+
3
+ require 'test/unit/testsuite'
4
+ require 'test/unit/collector'
5
+
6
+ module Test
7
+ module Unit
8
+ module Collector
9
+ class Load
10
+ include Collector
11
+
12
+ attr_reader :patterns, :excludes, :base
13
+
14
+ def initialize
15
+ super
16
+ @system_excludes = [/~\z/, /\A\.\#/]
17
+ @system_directory_excludes = [/\A(?:CVS|\.svn|\.git)\z/]
18
+ @patterns = [/\Atest[_\-].+\.rb\z/m]
19
+ @excludes = []
20
+ @base = nil
21
+ end
22
+
23
+ def base=(base)
24
+ base = Pathname(base) unless base.nil?
25
+ @base = base
26
+ end
27
+
28
+ def collect(*froms)
29
+ add_load_path(@base) do
30
+ froms = ["."] if froms.empty?
31
+ test_suites = froms.collect do |from|
32
+ test_suite = collect_recursive(resolve_path(from), find_test_cases)
33
+ test_suite = nil if test_suite.tests.empty?
34
+ test_suite
35
+ end.compact
36
+
37
+ if test_suites.size > 1
38
+ test_suite = TestSuite.new("[#{froms.join(', ')}]")
39
+ sort(test_suites).each do |sub_test_suite|
40
+ test_suite << sub_test_suite
41
+ end
42
+ test_suite
43
+ else
44
+ test_suites.first
45
+ end
46
+ end
47
+ end
48
+
49
+ def find_test_cases(ignore=[])
50
+ test_cases = []
51
+ TestCase::DESCENDANTS.each do |test_case|
52
+ test_cases << test_case unless ignore.include?(test_case)
53
+ end
54
+ ignore.concat(test_cases)
55
+ test_cases
56
+ end
57
+
58
+ private
59
+ def collect_recursive(path, already_gathered)
60
+ sub_test_suites = []
61
+
62
+ if path.directory?
63
+ directories, files = path.children.partition do |child|
64
+ child.directory?
65
+ end
66
+
67
+ files.each do |child|
68
+ next if excluded_file?(child.basename.to_s)
69
+ collect_file(child, sub_test_suites, already_gathered)
70
+ end
71
+
72
+ directories.each do |child|
73
+ next if excluded_directory?(child.basename.to_s)
74
+ sub_test_suite = collect_recursive(child, already_gathered)
75
+ sub_test_suites << sub_test_suite unless sub_test_suite.empty?
76
+ end
77
+ else
78
+ unless excluded_file?(path.basename.to_s)
79
+ collect_file(path, sub_test_suites, already_gathered)
80
+ end
81
+ end
82
+
83
+ test_suite = TestSuite.new(path.basename.to_s)
84
+ sort(sub_test_suites).each do |sub_test_suite|
85
+ test_suite << sub_test_suite
86
+ end
87
+ test_suite
88
+ end
89
+
90
+ def collect_file(path, test_suites, already_gathered)
91
+ add_load_path(path.expand_path.dirname) do
92
+ require(path.to_s)
93
+ find_test_cases(already_gathered).each do |test_case|
94
+ add_suite(test_suites, test_case.suite)
95
+ end
96
+ end
97
+ end
98
+
99
+ def resolve_path(path)
100
+ if @base
101
+ @base + path
102
+ else
103
+ Pathname(path)
104
+ end
105
+ end
106
+
107
+ def add_load_path(path)
108
+ $LOAD_PATH.push(path.to_s) if path
109
+ yield
110
+ ensure
111
+ $LOAD_PATH.delete_at($LOAD_PATH.rindex(path.to_s)) if path
112
+ end
113
+
114
+ def excluded_directory?(base)
115
+ @system_directory_excludes.any? {|pattern| pattern =~ base}
116
+ end
117
+
118
+ def excluded_file?(base)
119
+ return true if @system_excludes.any? {|pattern| pattern =~ base}
120
+
121
+ patterns = @patterns || []
122
+ unless patterns.empty?
123
+ return true unless patterns.any? {|pattern| pattern =~ base}
124
+ end
125
+
126
+ excludes = @excludes || []
127
+ unless excludes.empty?
128
+ return true if excludes.any? {|pattern| pattern =~ base}
129
+ end
130
+
131
+ false
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,34 @@
1
+ # Author:: Nathaniel Talbott.
2
+ # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
3
+ # License:: Ruby license.
4
+
5
+ require 'test/unit/collector'
6
+
7
+ module Test
8
+ module Unit
9
+ module Collector
10
+ class ObjectSpace
11
+ include Collector
12
+
13
+ NAME = 'collected from the ObjectSpace'
14
+
15
+ def initialize(source=::ObjectSpace)
16
+ super()
17
+ @source = source
18
+ end
19
+
20
+ def collect(name=NAME)
21
+ suite = TestSuite.new(name)
22
+ sub_suites = []
23
+ @source.each_object(Class) do |klass|
24
+ if(Test::Unit::TestCase > klass)
25
+ add_suite(sub_suites, klass.suite)
26
+ end
27
+ end
28
+ sort(sub_suites).each{|s| suite << s}
29
+ suite
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,102 @@
1
+ require 'test/unit/color'
2
+
3
+ module Test
4
+ module Unit
5
+ class ColorScheme
6
+ include Enumerable
7
+
8
+ class << self
9
+ @@default = nil
10
+ def default
11
+ @@default ||= new("success" => Color.new("green", :bold => true),
12
+ "failure" => Color.new("red", :bold => true),
13
+ "pending" => Color.new("magenta", :bold => true),
14
+ "omission" => Color.new("blue", :bold => true),
15
+ "notification" => Color.new("cyan", :bold => true),
16
+ "error" => Color.new("yellow", :bold => true) +
17
+ Color.new("black", :foreground => false),
18
+ "case" => Color.new("white", :bold => true) +
19
+ Color.new("blue", :foreground => false),
20
+ "suite" => Color.new("white", :bold => true) +
21
+ Color.new("green", :foreground => false),
22
+ "diff-inserted-tag" =>
23
+ Color.new("red", :bold => true),
24
+ "diff-deleted-tag" =>
25
+ Color.new("green", :bold => true),
26
+ "diff-difference-tag" =>
27
+ Color.new("cyan", :bold => true),
28
+ "diff-inserted" =>
29
+ Color.new("red", :foreground => false) +
30
+ Color.new("white", :bold => true),
31
+ "diff-deleted" =>
32
+ Color.new("green", :foreground => false) +
33
+ Color.new("white", :bold => true))
34
+ end
35
+
36
+ @@schemes = {}
37
+ def all
38
+ @@schemes.merge("default" => default)
39
+ end
40
+
41
+ def [](id)
42
+ @@schemes[id.to_s]
43
+ end
44
+
45
+ def []=(id, scheme_or_spec)
46
+ if scheme_or_spec.is_a?(self)
47
+ scheme = scheme_or_spec
48
+ else
49
+ scheme = new(scheme_or_spec)
50
+ end
51
+ @@schemes[id.to_s] = scheme
52
+ end
53
+ end
54
+
55
+ def initialize(scheme_spec)
56
+ @scheme = {}
57
+ scheme_spec.each do |key, color_spec|
58
+ self[key] = color_spec
59
+ end
60
+ end
61
+
62
+ def [](name)
63
+ @scheme[name.to_s]
64
+ end
65
+
66
+ def []=(name, color_spec)
67
+ @scheme[name.to_s] = make_color(color_spec)
68
+ end
69
+
70
+ def each(&block)
71
+ @scheme.each(&block)
72
+ end
73
+
74
+ def to_hash
75
+ hash = {}
76
+ @scheme.each do |key, color|
77
+ hash[key] = color
78
+ end
79
+ hash
80
+ end
81
+
82
+ private
83
+ def make_color(color_spec)
84
+ if color_spec.is_a?(Color) or color_spec.is_a?(MixColor)
85
+ color_spec
86
+ else
87
+ color_name = nil
88
+ normalized_color_spec = {}
89
+ color_spec.each do |key, value|
90
+ key = key.to_sym
91
+ if key == :name
92
+ color_name = value
93
+ else
94
+ normalized_color_spec[key] = value
95
+ end
96
+ end
97
+ Color.new(color_name, normalized_color_spec)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,96 @@
1
+ module Test
2
+ module Unit
3
+ class Color
4
+ NAMES = ["black", "red", "green", "yellow",
5
+ "blue", "magenta", "cyan", "white"]
6
+
7
+ attr_reader :name
8
+ def initialize(name, options={})
9
+ @name = name
10
+ @foreground = options[:foreground]
11
+ @foreground = true if @foreground.nil?
12
+ @intensity = options[:intensity]
13
+ @bold = options[:bold]
14
+ @italic = options[:italic]
15
+ @underline = options[:underline]
16
+ end
17
+
18
+ def foreground?
19
+ @foreground
20
+ end
21
+
22
+ def intensity?
23
+ @intensity
24
+ end
25
+
26
+ def bold?
27
+ @bold
28
+ end
29
+
30
+ def italic?
31
+ @italic
32
+ end
33
+
34
+ def underline?
35
+ @underline
36
+ end
37
+
38
+ def ==(other)
39
+ self.class === other and
40
+ [name, foreground?, intensity?,
41
+ bold?, italic?, underline?] ==
42
+ [other.name, other.foreground?, other.intensity?,
43
+ other.bold?, other.italic?, other.underline?]
44
+ end
45
+
46
+ def sequence
47
+ sequence = []
48
+ if @name == "none"
49
+ elsif @name == "reset"
50
+ sequence << "0"
51
+ else
52
+ foreground_parameter = foreground? ? 3 : 4
53
+ foreground_parameter += 6 if intensity?
54
+ sequence << "#{foreground_parameter}#{NAMES.index(@name)}"
55
+ end
56
+ sequence << "1" if bold?
57
+ sequence << "3" if italic?
58
+ sequence << "4" if underline?
59
+ sequence
60
+ end
61
+
62
+ def escape_sequence
63
+ "\e[#{sequence.join(';')}m"
64
+ end
65
+
66
+ def +(other)
67
+ MixColor.new([self, other])
68
+ end
69
+ end
70
+
71
+ class MixColor
72
+ attr_reader :colors
73
+ def initialize(colors)
74
+ @colors = colors
75
+ end
76
+
77
+ def sequence
78
+ @colors.inject([]) do |result, color|
79
+ result + color.sequence
80
+ end
81
+ end
82
+
83
+ def escape_sequence
84
+ "\e[#{sequence.join(';')}m"
85
+ end
86
+
87
+ def +(other)
88
+ self.class.new([self, other])
89
+ end
90
+
91
+ def ==(other)
92
+ self.class === other and colors == other.colors
93
+ end
94
+ end
95
+ end
96
+ end