malysz87-highline 1.5.9 → 1.5.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ # tc_color_scheme.rb
4
+ #
5
+ # Created by Jeremy Hinegardner on 2007-01-24.
6
+ # Copyright 2007 Jeremy Hinegardner. All rights reserved.
7
+ #
8
+ # This is Free Software. See LICENSE and COPYING for details.
9
+
10
+ require "test/unit"
11
+
12
+ require "highline"
13
+ require "stringio"
14
+
15
+ class TestColorScheme < Test::Unit::TestCase
16
+ def setup
17
+ @input = StringIO.new
18
+ @output = StringIO.new
19
+ @terminal = HighLine.new(@input, @output)
20
+
21
+ @old_color_scheme = HighLine.color_scheme
22
+ end
23
+
24
+ def teardown
25
+ HighLine.color_scheme = @old_color_scheme
26
+ end
27
+
28
+ def test_using_color_scheme
29
+ assert_equal(false,HighLine.using_color_scheme?)
30
+
31
+ HighLine.color_scheme = HighLine::ColorScheme.new
32
+ assert_equal(true,HighLine.using_color_scheme?)
33
+ end
34
+
35
+ def test_scheme
36
+ HighLine.color_scheme = HighLine::SampleColorScheme.new
37
+
38
+ @terminal.say("This should be <%= color('warning yellow', :warning) %>.")
39
+ assert_equal("This should be \e[1m\e[33mwarning yellow\e[0m.\n",@output.string)
40
+ @output.rewind
41
+
42
+ @terminal.say("This should be <%= color('warning yellow', 'warning') %>.")
43
+ assert_equal("This should be \e[1m\e[33mwarning yellow\e[0m.\n",@output.string)
44
+ @output.rewind
45
+
46
+ @terminal.say("This should be <%= color('warning yellow', 'WarNing') %>.")
47
+ assert_equal("This should be \e[1m\e[33mwarning yellow\e[0m.\n",@output.string)
48
+ @output.rewind
49
+
50
+ # turn it back off, should raise an exception
51
+ HighLine.color_scheme = @old_color_scheme
52
+ assert_raises(NameError) {
53
+ @terminal.say("This should be <%= color('nothing at all', :error) %>.")
54
+ }
55
+ end
56
+ end