pry-theme 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +8 -1
  4. data/CHANGELOG.md +40 -0
  5. data/Gemfile +1 -1
  6. data/README.md +26 -48
  7. data/Rakefile +10 -1
  8. data/VERSION +1 -0
  9. data/lib/pry-theme/basic_editor.rb +116 -0
  10. data/lib/pry-theme/color.rb +431 -0
  11. data/lib/pry-theme/color_table.rb +39 -0
  12. data/lib/pry-theme/colors/color16.rb +35 -0
  13. data/lib/pry-theme/colors/color256.rb +30 -0
  14. data/lib/pry-theme/colors/color8.rb +31 -0
  15. data/lib/pry-theme/commands.rb +237 -275
  16. data/lib/pry-theme/declaration.rb +120 -0
  17. data/lib/pry-theme/definition.rb +111 -0
  18. data/lib/pry-theme/formattable.rb +26 -0
  19. data/lib/pry-theme/hex.rb +76 -0
  20. data/lib/pry-theme/preview.rb +74 -0
  21. data/lib/pry-theme/rgb.rb +238 -13
  22. data/lib/pry-theme/term.rb +66 -0
  23. data/lib/pry-theme/theme.rb +116 -26
  24. data/lib/pry-theme/theme_list.rb +52 -0
  25. data/lib/pry-theme/when_started_hook.rb +25 -27
  26. data/lib/pry-theme.rb +84 -158
  27. data/pry-theme.gemspec +14 -18
  28. data/spec/color_table.rb +53 -0
  29. data/spec/colors/color16_spec.rb +255 -0
  30. data/spec/colors/color256_spec.rb +323 -0
  31. data/spec/colors/color8_spec.rb +254 -0
  32. data/spec/commands_spec.rb +203 -0
  33. data/spec/helper.rb +16 -0
  34. data/spec/hex_spec.rb +52 -0
  35. data/spec/rgb_spec.rb +81 -0
  36. data/spec/term_spec.rb +23 -0
  37. data/spec/theme_spec.rb +486 -0
  38. data/themes/github.prytheme.rb +49 -0
  39. data/themes/monokai.prytheme.rb +48 -0
  40. data/themes/pry-classic-16.prytheme.rb +48 -0
  41. data/themes/pry-classic-256.prytheme.rb +48 -0
  42. data/themes/pry-classic-8.prytheme.rb +48 -0
  43. data/themes/pry-cold.prytheme.rb +49 -0
  44. data/themes/pry-love-16.prytheme.rb +48 -0
  45. data/themes/pry-love-8.prytheme.rb +48 -0
  46. data/themes/pry-modern-16.prytheme.rb +48 -0
  47. data/themes/pry-modern-256.prytheme.rb +48 -0
  48. data/themes/pry-modern-8.prytheme.rb +48 -0
  49. data/themes/pry-monochrome.prytheme.rb +32 -0
  50. data/themes/pry-siberia-16.prytheme.rb +48 -0
  51. data/themes/pry-siberia-8.prytheme.rb +48 -0
  52. data/themes/pry-tepid-16.prytheme.rb +48 -0
  53. data/themes/pry-tepid-8.prytheme.rb +48 -0
  54. data/themes/pry-zealand-16.prytheme.rb +48 -0
  55. data/themes/pry-zealand-8.prytheme.rb +49 -0
  56. data/themes/railscasts.prytheme.rb +50 -0
  57. data/themes/solarized.prytheme.rb +48 -0
  58. data/themes/tomorrow.prytheme.rb +48 -0
  59. data/themes/twilight.prytheme.rb +48 -0
  60. data/themes/vim-default.prytheme.rb +50 -0
  61. data/themes/vim-detailed.prytheme.rb +50 -0
  62. data/themes/zenburn.prytheme.rb +48 -0
  63. metadata +56 -41
  64. data/lib/pry-theme/color_converter.rb +0 -55
  65. data/lib/pry-theme/helper.rb +0 -87
  66. data/lib/pry-theme/palette.rb +0 -85
  67. data/lib/pry-theme/term_notation.rb +0 -17
  68. data/lib/pry-theme/version.rb +0 -3
  69. data/test/fixtures/pry-classic.prytheme +0 -38
  70. data/test/helper.rb +0 -56
  71. data/test/test_color_converter.rb +0 -38
  72. data/test/test_commands.rb +0 -55
  73. data/test/test_helper.rb +0 -45
  74. data/test/test_palette.rb +0 -11
  75. data/themes/github.prytheme +0 -43
  76. data/themes/monokai.prytheme +0 -42
  77. data/themes/pry-classic.prytheme +0 -43
  78. data/themes/pry-cold.prytheme +0 -43
  79. data/themes/pry-modern.prytheme +0 -42
  80. data/themes/railscasts.prytheme +0 -44
  81. data/themes/saturday.prytheme +0 -42
  82. data/themes/solarized.prytheme +0 -43
  83. data/themes/tomorrow.prytheme +0 -43
  84. data/themes/twilight.prytheme +0 -42
  85. data/themes/vim-default.prytheme +0 -42
  86. data/themes/vim-detailed.prytheme +0 -42
  87. data/themes/zenburn.prytheme +0 -43
@@ -0,0 +1,254 @@
1
+ require 'helper'
2
+
3
+ describe PryTheme::Color8 do
4
+ Color8 = PryTheme::Color8
5
+
6
+ describe "foreground" do
7
+ it "can be set" do
8
+ color = Color8.new(:foreground => 'red')
9
+ color.foreground(true).should == 'red'
10
+ color.to_ansi.should == '31'
11
+ end
12
+
13
+ it "defaults to no colour at all" do
14
+ color = Color8.new
15
+ color.foreground(true).should == false
16
+ color.to_ansi.should == '39;49'
17
+ end
18
+
19
+ it "raises error on invalid value" do
20
+ lambda { Color8.new(:foreground => 'blah') }.
21
+ should.raise(ArgumentError).
22
+ message.should.match /invalid foreground value "blah"/
23
+ end
24
+ end
25
+
26
+ describe "background" do
27
+ it "can be set" do
28
+ color = Color8.new(:background => 'blue')
29
+ color.background(true).should == 'blue'
30
+ color.to_ansi.should == '44'
31
+ end
32
+
33
+ it "defaults to no colour at all" do
34
+ color = Color8.new
35
+ color.background(true).should == false
36
+ color.to_ansi.should == '39;49'
37
+ end
38
+
39
+ it "raises error on invalid value" do
40
+ lambda { Color8.new(:background => 'BLACK') }.
41
+ should.raise(ArgumentError).
42
+ message.should.match /invalid background value "BLACK"/
43
+ end
44
+ end
45
+
46
+ describe "foreground combined with background" do
47
+ it "can be set" do
48
+ color = Color8.new(:foreground => 'green', :background => 'red')
49
+ color.foreground(true).should == 'green'
50
+ color.background(true).should == 'red'
51
+ color.to_ansi.should == '32;41'
52
+ end
53
+ end
54
+
55
+ describe "effects" do
56
+ it "can't be bold" do
57
+ lambda { Color8.new(:bold => true).bold? }.should.raise(NoMethodError)
58
+ end
59
+
60
+ it "can't be italic" do
61
+ lambda { Color8.new(:italic => true).italic?
62
+ }.should.raise(NoMethodError)
63
+ end
64
+
65
+ it "can't be underlined" do
66
+ lambda { Color8.new(:underline => true).underline?
67
+ }.should.raise(NoMethodError)
68
+ end
69
+ end
70
+
71
+ describe "argument types" do
72
+ describe "readable" do
73
+ it "works" do
74
+ lambda {
75
+ Color8.new(
76
+ :from => :readable,
77
+ :foreground => 'black',
78
+ :background => 'white')
79
+ }.should.not.raise
80
+ end
81
+
82
+ it "doesn't work with incorrect input" do
83
+ lambda {
84
+ Color8.new(
85
+ :from => :readable,
86
+ :foreground => '#222222',
87
+ :background => [123, 11, 44])
88
+ }.should.raise(ArgumentError)
89
+ end
90
+
91
+ it "sets background and foreground properly" do
92
+ color = Color8.new(:from => :readable,
93
+ :foreground => 'black',
94
+ :background => 'green')
95
+ color.foreground.should == 30
96
+ color.foreground(true).should == 'black'
97
+ color.background.should == 42
98
+ color.background(true).should == 'green'
99
+ end
100
+
101
+ it "sets foreground properly" do
102
+ color = Color8.new(:from => :readable, :foreground => 'black')
103
+ color.foreground.should == 30
104
+ color.foreground(true).should == 'black'
105
+ color.background.should == false
106
+ color.background(true).should == false
107
+ end
108
+
109
+ it "sets background properly" do
110
+ color = Color8.new(:from => :readable, :background => 'green')
111
+ color.foreground.should == false
112
+ color.foreground(true).should == false
113
+ color.background.should == 42
114
+ color.background(true).should == 'green'
115
+ end
116
+ end
117
+
118
+ describe "hex" do
119
+ it "works" do
120
+ lambda {
121
+ Color8.new(
122
+ :from => :hex,
123
+ :foreground => '#afaf11',
124
+ :background => '#eaeaea')
125
+ }.should.not.raise
126
+ end
127
+
128
+ it "doesn't work with incorrect input" do
129
+ lambda {
130
+ Color8.new(
131
+ :from => :hex,
132
+ :foreground => '#222222',
133
+ :background => [123, 11, 44])
134
+ }.should.raise(TypeError)
135
+ end
136
+
137
+ it "sets background and foreground properly" do
138
+ color = Color8.new(:from => :hex,
139
+ :foreground => '#afaf11',
140
+ :background => '#eaeaea')
141
+ color.foreground.should == 34
142
+ color.foreground(true).should == 'blue'
143
+ color.background.should == 45
144
+ color.background(true).should == 'magenta'
145
+ end
146
+
147
+ it "sets foreground properly" do
148
+ color = Color8.new(:from => :hex, :foreground => '#afaf11')
149
+ color.foreground.should == 34
150
+ color.foreground(true).should == 'blue'
151
+ color.background.should == false
152
+ color.background(true).should == false
153
+ end
154
+
155
+ it "sets background properly" do
156
+ color = Color8.new(:from => :hex, :background => '#eaeaea')
157
+ color.foreground.should == false
158
+ color.foreground(true).should == false
159
+ color.background.should == 45
160
+ color.background(true).should == 'magenta'
161
+ end
162
+ end
163
+
164
+ describe "rgb" do
165
+ it "works" do
166
+ lambda {
167
+ Color8.new(
168
+ :from => :rgb,
169
+ :foreground => '31, 125, 88',
170
+ :background => [123, 11, 44])
171
+ }.should.not.raise(ArgumentError)
172
+ end
173
+
174
+ it "doesn't work with incorrect input" do
175
+ lambda {
176
+ Color8.new(
177
+ :from => :rgb,
178
+ :foreground => '#222222',
179
+ :background => [123, 11, 44])
180
+ }.should.raise(ArgumentError)
181
+ end
182
+
183
+ it "sets background and foreground properly" do
184
+ color = Color8.new(:from => :rgb,
185
+ :foreground => '31, 31, 101',
186
+ :background => '125, 101, 255')
187
+ color.foreground.should == 30
188
+ color.foreground(true).should == 'black'
189
+ color.background.should == 43
190
+ color.background(true).should == 'yellow'
191
+ end
192
+
193
+ it "sets foreground properly" do
194
+ color = Color8.new(:from => :rgb, :foreground => '31, 31, 101')
195
+ color.foreground.should == 30
196
+ color.foreground(true).should == 'black'
197
+ color.background.should == false
198
+ color.background(true).should == false
199
+ end
200
+
201
+ it "sets background properly" do
202
+ color = Color8.new(:from => :rgb, :background => '125, 101, 255')
203
+ color.foreground.should == false
204
+ color.foreground(true).should == false
205
+ color.background.should == 43
206
+ color.background(true).should == 'yellow'
207
+ end
208
+ end
209
+
210
+ describe "term" do
211
+ it "works" do
212
+ lambda {
213
+ Color8.new(
214
+ :from => :term,
215
+ :foreground => 1,
216
+ :background => 7)
217
+ }.should.not.raise(ArgumentError)
218
+ end
219
+
220
+ it "doesn't work with incorrect input" do
221
+ lambda {
222
+ Color8.new(
223
+ :from => :term,
224
+ :foreground => 33,
225
+ :background => 42)
226
+ }.should.raise(ArgumentError)
227
+ end
228
+
229
+ it "sets background and foreground properly" do
230
+ color = Color8.new(:from => :term, :foreground => 0, :background => 7)
231
+ color.foreground.should == 30
232
+ color.foreground(true).should == 'black'
233
+ color.background.should == 47
234
+ color.background(true).should == 'white'
235
+ end
236
+
237
+ it "sets foreground properly" do
238
+ color = Color8.new(:from => :term, :foreground => 0)
239
+ color.foreground.should == 30
240
+ color.foreground(true).should == 'black'
241
+ color.background.should == false
242
+ color.background(true).should == false
243
+ end
244
+
245
+ it "sets background properly" do
246
+ color = Color8.new(:from => :term, :background => 7)
247
+ color.foreground.should == false
248
+ color.foreground(true).should == false
249
+ color.background.should == 47
250
+ color.background(true).should == 'white'
251
+ end
252
+ end
253
+ end
254
+ end
@@ -0,0 +1,203 @@
1
+ require 'helper'
2
+
3
+ describe PryTheme::Command::PryTheme do
4
+ before do
5
+ theme = PryTheme.create(:name => 'wholesome'){}
6
+ PryTheme::ThemeList.add_theme(theme)
7
+
8
+ other_theme = PryTheme.create(:name => 'sick'){}
9
+ PryTheme::ThemeList.add_theme(other_theme)
10
+ end
11
+
12
+ describe "empty callback" do
13
+ it "outputs help" do
14
+ pry_eval('pry-theme').should =~ /Usage: pry-theme/
15
+ end
16
+ end
17
+
18
+ describe "'current' subcommand" do
19
+ it "displays current theme name" do
20
+ PryTheme::ThemeList.activate_theme('wholesome')
21
+ pry_eval('pry-theme current').should == "wholesome\n"
22
+ end
23
+
24
+ it "displays the short summary about current theme" do
25
+ PryTheme::ThemeList.activate_theme('wholesome')
26
+
27
+ pry_eval('pry-theme current --colors').should ==
28
+ Pry::Helpers::CommandHelpers.unindent(<<-'OUT')
29
+ # "wholesome" theme.
30
+ class PryTheme::ThisIsAClass
31
+ def this_is_a_method
32
+ THIS_IS_A_CONSTANT = :this_is_a_symbol
33
+ this_is_a_local_var = "#{this} #@is a string.\n"
34
+ this_is_a_float = 10_000.00
35
+ this_is_an_integer = 10_000
36
+
37
+ # TRUE and FALSE are predefined constants.
38
+ $this_is_a_global_variable = TRUE or FALSE
39
+
40
+ @this_is_an_instance_variable = `echo '#@hi #{system} call\n'`
41
+ @@this_is_a_class_variable = @@@\\$ # An error.
42
+
43
+ /[0-9]{1,3}this #{is} a regexp\w+/xi
44
+ end
45
+ end
46
+ OUT
47
+ end
48
+
49
+ it "doesn't display anything" do
50
+ pry_eval('pry-theme current --foo-bar').should == ''
51
+ end
52
+ end
53
+
54
+ describe "'try' subcommand" do
55
+ it "temporary switches to a theme" do
56
+ pry_eval('pry-theme try sick').should == "Using \"sick\" theme\n"
57
+ PryTheme::ThemeList.current_theme.name.should == 'sick'
58
+
59
+ pry_eval('pry-theme try wholesome').should == "Using \"wholesome\" theme\n"
60
+ PryTheme::ThemeList.current_theme.name.should == 'wholesome'
61
+ end
62
+
63
+ it "displays error message if can't find the given theme" do
64
+ cur = PryTheme::ThemeList.current_theme.name
65
+ pry_eval('pry-theme try g-system').
66
+ should == %|Cannot find "g-system" amongst themes in #{PryTheme::USER_THEMES_DIR}\n|
67
+ PryTheme::ThemeList.current_theme.name.should == cur
68
+ end
69
+ end
70
+
71
+ describe "'list' subcommand" do
72
+ it "lists currently installed themes" do
73
+ pry_eval('pry-theme list').should =~ /class Theme/
74
+ pry_eval('pry-theme list').should =~ /sick/
75
+ end
76
+
77
+ it "doesn't mangle current theme" do
78
+ cur = PryTheme::ThemeList.current_theme
79
+ pry_eval('pry-theme list')
80
+ PryTheme::ThemeList.current_theme.should == cur
81
+ end
82
+ end
83
+
84
+ describe "'colors' subcommand" do
85
+ if ENV['TERM'] =~ /256color/
86
+ it "displays colours accordingly to the terminal color support" do
87
+ table = pry_eval('pry-theme colors')
88
+ table.should =~ /silver01/
89
+ table.should =~ /7;38;5;105/
90
+ end
91
+ end
92
+
93
+ describe "colours according to the chosen model" do
94
+ it "displays the table of 256 colours" do
95
+ table = pry_eval('pry-theme colors -m 256')
96
+ table.should =~ /silver01/
97
+ table.should =~ /7;38;5;105/
98
+ table.should.not =~ /bright_red/
99
+ end
100
+
101
+ it "displays the table of 16 colours" do
102
+ table = pry_eval('pry-theme colors -m 16')
103
+ table.should =~ /bright_red/
104
+ table.should =~ /7;31;1/
105
+ table.should.not =~ /silver01/
106
+ end
107
+
108
+ it "displays the table of 8 colours" do
109
+ table = pry_eval('pry-theme colors -m 8')
110
+ table.should =~ /red/
111
+ table.should =~ /7;36/
112
+ table.should.not =~ /silver01/
113
+ table.should.not =~ /bright_red/
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "'convert' subcommand" do
119
+ if ENV['TERM'] =~ /256color/
120
+ it "converts colours accordingly to the terminal color support" do
121
+ pry_eval('pry-theme convert -t 124').should =~ /bismarck_furious/
122
+ end
123
+ end
124
+
125
+ it "warns when no switches given" do
126
+ pry_eval('pry-theme convert').should =~ /You must provide the `-m`/
127
+ end
128
+
129
+ it "warns on incorrect usage" do
130
+ pry_eval('pry-theme convert dqwdwq').should =~ /You must provide the `-m`/
131
+ end
132
+
133
+ describe "conversion from term" do
134
+ if PryTheme.tput_colors == 256
135
+ it "with implicit model" do
136
+ pry_eval('pry-theme convert -t 124').should =~ /bismarck_furious/
137
+ end
138
+ end
139
+
140
+ it "with explicit color model 8" do
141
+ pry_eval('pry-theme convert -m 8 -t 7').should =~ /white/
142
+ end
143
+
144
+ it "with explicit color model 16" do
145
+ pry_eval('pry-theme convert -m 16 -t 10').should =~ /bright_green/
146
+ end
147
+
148
+ it "with explicit color model 256" do
149
+ pry_eval('pry-theme convert -m 256 -t 124').should =~ /bismarck_furious/
150
+ end
151
+ end
152
+
153
+ describe "conversion from rgb" do
154
+ if PryTheme.tput_colors == 256
155
+ it "with implicit model" do
156
+ pry_eval('pry-theme convert -r 124,0,11').should =~ /maroon01/
157
+ end
158
+ end
159
+
160
+ it "with explicit color model 8" do
161
+ pry_eval('pry-theme convert -m 8 -r 124,0,11').should =~ /green/
162
+ end
163
+
164
+ it "with explicit color model 16" do
165
+ pry_eval('pry-theme convert -m 16 -r 124,0,11').should =~ /magenta/
166
+ end
167
+
168
+ it "with explicit color model 256" do
169
+ pry_eval('pry-theme convert -m 256 -r 124,0,11').should =~ /maroon01/
170
+ end
171
+ end
172
+
173
+ describe "conversion from hex" do
174
+ if PryTheme.tput_colors == 256
175
+ it "with implicit model" do
176
+ pry_eval('pry-theme convert -h #ae3aff').should =~ /heliotrope02/
177
+ end
178
+ end
179
+
180
+ it "with explicit color model 8" do
181
+ pry_eval('pry-theme convert -m 8 -h #ae3aff').should =~ /blue/
182
+ end
183
+
184
+ it "with explicit color model 16" do
185
+ pry_eval('pry-theme convert -m 16 -h #ae3aff').should =~ /bright_black/
186
+ end
187
+
188
+ it "with explicit color model 256" do
189
+ pry_eval('pry-theme convert -m 256 -h #ae3aff').should =~ /heliotrope02/
190
+ end
191
+ end
192
+
193
+ describe "error handling" do
194
+ it "outputs the error message if colour model was specified without a colour" do
195
+ pry_eval('pry-theme convert -m 8').should =~ /Provide a color value/
196
+ end
197
+
198
+ it "outputs the error message if colour model is invalid" do
199
+ pry_eval('pry-theme convert -m 23 -t 32').should =~ /Unknown color model/
200
+ end
201
+ end
202
+ end
203
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'pry'
3
+ require 'pry/test/helper'
4
+
5
+ Pry.config.theme = nil
6
+ Pry.config.pager = false
7
+
8
+ unless Object.const_defined? 'PryTheme'
9
+ $:.unshift File.expand_path '../../lib', __FILE__
10
+ require 'pry-theme'
11
+ end
12
+
13
+ require 'bacon'
14
+
15
+ puts "Ruby: #{ RUBY_VERSION }; Ruby Engine: #{ defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby' }; " \
16
+ "Pry Theme: #{ PryTheme::VERSION }"
data/spec/hex_spec.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'helper'
2
+
3
+ describe PryTheme::HEX do
4
+ HEX = PryTheme::HEX
5
+
6
+ it "accepts String with an octothorp as an argument" do
7
+ lambda { HEX.new('#ffffff') }.should.not.raise
8
+ lambda { HEX.new('#FFFFFF') }.should.not.raise
9
+ end
10
+
11
+ it "doesn't accept malformed arguments" do
12
+ lambda { HEX.new('#fffffff') }.should.raise ArgumentError
13
+ lambda { HEX.new('ffffff') }.should.raise ArgumentError
14
+ lambda { HEX.new('dqwdqw') }.should.raise ArgumentError
15
+ lambda { HEX.new(:boom) }.should.raise TypeError
16
+ end
17
+
18
+ it "converts itself to rgb" do
19
+ HEX.new('#ffffff').to_rgb.to_a.should == [255, 255, 255]
20
+ end
21
+
22
+ it "converts itself to term 256" do
23
+ HEX.new('#ffffff').to_term.to_i.should == 15
24
+ HEX.new('#ffffff').to_term(256).to_i.should == 15
25
+ end
26
+
27
+ it "converts itself to term 256 and determines the nearest term colour" do
28
+ HEX.new('#fefefe').to_term.to_i.should == 15
29
+ HEX.new('#cecece').to_term.to_i.should == 189
30
+ end
31
+
32
+ it "converts itself to term 16" do
33
+ HEX.new('#ffffff').to_term(16).to_i.should == 15
34
+ end
35
+
36
+ it "converts itself to term 16 and determines the nearest term colour" do
37
+ HEX.new('#fefefe').to_term(16).to_i.should == 15
38
+ HEX.new('#cecece').to_term(16).to_i.should == 11
39
+ end
40
+
41
+ it "converts itself to term 8" do
42
+ HEX.new('#ffffff').to_term(8).to_i.should == 0
43
+ end
44
+
45
+ it "converts itself to term 8 and determines the nearest term colour" do
46
+ HEX.new('#3a6e9c').to_term(8).to_i.should == 1
47
+ end
48
+
49
+ it "represents itself as String" do
50
+ HEX.new('#ffffff').to_s.should == '#ffffff'
51
+ end
52
+ end
data/spec/rgb_spec.rb ADDED
@@ -0,0 +1,81 @@
1
+ require 'helper'
2
+
3
+ describe PryTheme::RGB do
4
+ RGB = PryTheme::RGB
5
+
6
+ it "accepts Array as an argument" do
7
+ lambda { RGB.new([0, 0, 0]) }.should.not.raise
8
+ end
9
+
10
+ it "doesn't accept malformed Arrays" do
11
+ lambda { RGB.new([0, 0, 0, 0]) }.should.raise ArgumentError
12
+ lambda { RGB.new([256, 256, 256]) }.should.raise ArgumentError
13
+ lambda { RGB.new([:one, 256, 256]) }.should.raise ArgumentError
14
+ end
15
+
16
+ it "accepts String as an argument" do
17
+ lambda { RGB.new('0, 0, 0') }.should.not.raise
18
+ end
19
+
20
+ it "doesn't accept malformed Strings" do
21
+ lambda { RGB.new('0, 0, 0, 0') }.should.raise ArgumentError
22
+ lambda { RGB.new('256, 256, 256') }.should.raise ArgumentError
23
+ lambda { RGB.new('256, heaven, 256') }.should.raise ArgumentError
24
+ end
25
+
26
+ it "raises error if gibberish is given as an argument" do
27
+ lambda { RGB.new('jeyenne') }.should.raise ArgumentError
28
+ lambda { RGB.new(:jeyenne) }.should.raise TypeError
29
+ end
30
+
31
+ it "converts itself to term 256" do
32
+ RGB.new([0, 0, 0]).to_term.to_i.should == 0
33
+ RGB.new('255, 255, 255').to_term.to_i.should == 15
34
+ end
35
+
36
+ it "converts itself to term 256 and determines the nearest term colour" do
37
+ RGB.new('21, 24, 205').to_term.to_i.should == 20
38
+ RGB.new('210, 240, 20').to_term.to_i.should == 191
39
+ end
40
+
41
+ it "converts itself to term 16" do
42
+ RGB.new([0, 0, 0]).to_term(16).to_i.should == 0
43
+ RGB.new([255, 255, 255]).to_term(16).to_i.should == 15
44
+ RGB.new([255, 0, 255]).to_term(16).to_i.should == 13
45
+ end
46
+
47
+ it "converts itself to and determines the nearest term colour" do
48
+ RGB.new([0, 101, 69]).to_term(16).to_i.should == 1
49
+ end
50
+
51
+ it "converts itself to term 8" do
52
+ RGB.new([0, 0, 0]).to_term(8).to_i.should == 0
53
+ RGB.new([255, 255, 255]).to_term(8).to_i.should == 0
54
+ RGB.new([255, 0, 255]).to_term(8).to_i.should == 0
55
+ end
56
+
57
+ it "converts itself to and determines the nearest term colour" do
58
+ RGB.new([0, 101, 69]).to_term(16).to_i.should == 1
59
+ RGB.new([122, 122, 122]).to_term(8).to_i.should == 3
60
+ RGB.new([176, 127, 30]).to_term(8).to_i.should == 4
61
+ end
62
+
63
+ it "converts itself to hex" do
64
+ RGB.new([0, 0, 0]).to_hex.to_s.should == '#000000'
65
+ RGB.new([255, 255, 255]).to_hex.to_s.should == '#ffffff'
66
+ end
67
+
68
+ it "represents itself as a String" do
69
+ RGB.new([0, 0, 0]).to_s.should == '0, 0, 0'
70
+ RGB.new('0, 0, 0').to_s.should == '0, 0, 0'
71
+ end
72
+
73
+ it "represents itself as an Array" do
74
+ RGB.new([0, 0, 0]).to_a.should == [0, 0, 0]
75
+ RGB.new('0, 0, 0').to_a.should == [0, 0, 0]
76
+ end
77
+
78
+ it "represents itself in CSS format" do
79
+ RGB.new([0, 0, 0]).to_css.should == 'rgb(0, 0, 0)'
80
+ end
81
+ end
data/spec/term_spec.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ describe PryTheme::TERM do
4
+ TERM = PryTheme::TERM
5
+
6
+ it "represents itself as Fixnum" do
7
+ TERM.new(23).to_i.should == 23
8
+ end
9
+
10
+ it "has color model parameter" do
11
+ TERM.new(1).color_model.should == 256
12
+ TERM.new(1, 16).color_model.should == 16
13
+ end
14
+
15
+ it "doesn't accept malformed arguments" do
16
+ lambda { TERM.new(-23) }.should.raise ArgumentError
17
+ lambda { TERM.new(256) }.should.raise ArgumentError
18
+ lambda { TERM.new(25, 16) }.should.raise ArgumentError
19
+ lambda { TERM.new(25, '16') }.should.raise TypeError
20
+ lambda { TERM.new(:one) }.should.raise TypeError
21
+ lambda { TERM.new('25') }.should.raise TypeError
22
+ end
23
+ end