color-japanese 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "../lib")
5
+ require "color/rgb/jp"
6
+
7
+ module Fixture
8
+ module UTF_8
9
+ SakuraIroKanji = "\xe6\xa1\x9c\xe8\x89\xb2"
10
+ SakuraIroHiragana = "\xe3\x81\x95\xe3\x81\x8f\xe3\x82\x89\xe3\x81\x84\xe3\x82\x8d"
11
+ SakuraIroKatakana = "\xe3\x82\xb5\xe3\x82\xaf\xe3\x83\xa9\xe3\x82\xa4\xe3\x83\xad"
12
+ end
13
+
14
+ module Shift_JIS
15
+ SakuraIroKanji = "\x8d\xf7\x90F"
16
+ SakuraIroHiragana = "\x82\xb3\x82\xad\x82\xe7\x82\xa2\x82\xeb"
17
+ SakuraIroKatakana = "\x83T\x83N\x83\x89\x83C\x83\x8d"
18
+ end
19
+
20
+ module EUC_JP
21
+ SakuraIroKanji = "\xba\xf9\xbf\xa7"
22
+ SakuraIroHiragana = "\xa4\xb5\xa4\xaf\xa4\xe9\xa4\xa4\xa4\xed"
23
+ SakuraIroKatakana = "\xa5\xb5\xa5\xaf\xa5\xe9\xa5\xa4\xa5\xed"
24
+ end
25
+ end
@@ -0,0 +1,77 @@
1
+ # -*- encoding: utf8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/helper.rb'
4
+
5
+ class TestColorName < Test::Unit::TestCase
6
+
7
+ ColorName = Color::RGB::JP::Base::ColorName
8
+
9
+ def test_new_and_accessor
10
+ c = ColorName.new("const", "漢字", "ひらがな", "カタカナ", "romaji")
11
+ assert_equal("const", c.const_name)
12
+ assert_equal("漢字", c.kanji)
13
+ assert_equal("ひらがな", c.hiragana)
14
+ assert_equal("カタカナ", c.katakana)
15
+ assert_equal("romaji", c.romaji)
16
+ end
17
+
18
+ def test_encoding
19
+ c = ColorName.new("SakuraIro", "桜色", "さくらいろ", "サクライロ", "sakura-iro")
20
+ assert_equal("SakuraIro", c.const_name)
21
+ assert_equal(Fixture::UTF_8::SakuraIroKanji, c.kanji)
22
+ assert_equal(Fixture::UTF_8::SakuraIroHiragana, c.hiragana)
23
+ assert_equal(Fixture::UTF_8::SakuraIroKatakana, c.katakana)
24
+ assert_equal("sakura-iro", c.romaji)
25
+
26
+ assert_equal(Fixture::Shift_JIS::SakuraIroKanji, c.kanji("Shift_JIS"))
27
+ assert_equal(Fixture::Shift_JIS::SakuraIroHiragana, c.hiragana("Shift_JIS"))
28
+ assert_equal(Fixture::Shift_JIS::SakuraIroKatakana, c.katakana("Shift_JIS"))
29
+
30
+ assert_equal(Fixture::EUC_JP::SakuraIroKanji, c.kanji("EUC-JP"))
31
+ assert_equal(Fixture::EUC_JP::SakuraIroHiragana, c.hiragana("EUC-JP"))
32
+ assert_equal(Fixture::EUC_JP::SakuraIroKatakana, c.katakana("EUC-JP"))
33
+ end
34
+
35
+ def test_to_s
36
+ c = ColorName.new("SakuraIro", "桜色", "さくらいろ", "サクライロ", "sakura-iro")
37
+ assert_equal("sakura-iro", c.to_s)
38
+
39
+ c = ColorName.new("", "", "", "", "kuro")
40
+ assert_equal("kuro", c.to_s)
41
+ end
42
+
43
+ def test_names_and_to_a
44
+ c = ColorName.new("SakuraIro", "桜色", "さくらいろ", "サクライロ", "sakura-iro")
45
+
46
+ assert_equal([Fixture::UTF_8::SakuraIroKanji,
47
+ Fixture::UTF_8::SakuraIroHiragana,
48
+ Fixture::UTF_8::SakuraIroKatakana,
49
+ "sakura-iro"],
50
+ c.names)
51
+
52
+ assert_equal([Fixture::Shift_JIS::SakuraIroKanji,
53
+ Fixture::Shift_JIS::SakuraIroHiragana,
54
+ Fixture::Shift_JIS::SakuraIroKatakana,
55
+ "sakura-iro"],
56
+ c.names("Shift_JIS"))
57
+
58
+ assert_equal([Fixture::EUC_JP::SakuraIroKanji,
59
+ Fixture::EUC_JP::SakuraIroHiragana,
60
+ Fixture::EUC_JP::SakuraIroKatakana,
61
+ "sakura-iro"],
62
+ c.names("EUC-JP"))
63
+
64
+ assert_equal([Fixture::UTF_8::SakuraIroKanji,
65
+ Fixture::UTF_8::SakuraIroHiragana,
66
+ Fixture::UTF_8::SakuraIroKatakana,
67
+ "sakura-iro"],
68
+ c.to_a)
69
+
70
+ assert_equal([Fixture::UTF_8::SakuraIroKanji,
71
+ Fixture::UTF_8::SakuraIroHiragana,
72
+ Fixture::UTF_8::SakuraIroKatakana,
73
+ "sakura-iro"],
74
+ c.to_a("UTF-8"))
75
+ end
76
+
77
+ end
@@ -0,0 +1,181 @@
1
+ # -*- encoding: utf8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/helper.rb'
4
+ require "color/rgb/jp/compiler/compiler"
5
+
6
+ class TestCompiler < Test::Unit::TestCase
7
+
8
+ def trad(encoding = "UTF-8", prefix = "##")
9
+ Color::RGB::JP::Compiler::Compiler.new(
10
+ Color::RGB::JP::Traditional,
11
+ encoding, prefix, "test generator")
12
+ end
13
+
14
+ def test_execute
15
+ r = ""
16
+ trad.execute(StringIO.new(<<-SRC), StringIO.new(r), true)
17
+ [##sakura-iro]
18
+ SRC
19
+
20
+ assert_equal(<<-EXPECTED, r)
21
+ [#fef4f4]
22
+ EXPECTED
23
+ end
24
+
25
+ def test_execute_sjis
26
+ $KCODE = "s"
27
+ c = trad("Shift_JIS")
28
+ r = ""
29
+ c.execute(StringIO.new(<<-SRC), StringIO.new(r), true)
30
+ color: ###{Fixture::Shift_JIS::SakuraIroKanji};
31
+ background-color: ###{Fixture::Shift_JIS::SakuraIroHiragana};
32
+ bgcolor="###{Fixture::Shift_JIS::SakuraIroKatakana}"
33
+ SRC
34
+
35
+ assert_equal(<<-EXPECTED, r)
36
+ color: #fef4f4;
37
+ background-color: #fef4f4;
38
+ bgcolor="#fef4f4"
39
+ EXPECTED
40
+ end
41
+
42
+ def test_execute_utf8
43
+ $KCODE = "e"
44
+ c = trad("EUC-JP")
45
+ r = ""
46
+ c.execute(StringIO.new(<<-SRC), StringIO.new(r), true)
47
+ color: ###{Fixture::EUC_JP::SakuraIroKanji};
48
+ background-color: ###{Fixture::EUC_JP::SakuraIroHiragana};
49
+ bgcolor="###{Fixture::EUC_JP::SakuraIroKatakana}"
50
+ SRC
51
+
52
+ assert_equal(<<-EXPECTED, r)
53
+ color: #fef4f4;
54
+ background-color: #fef4f4;
55
+ bgcolor="#fef4f4"
56
+ EXPECTED
57
+ end
58
+
59
+ def test_execute_prefix
60
+ $KCODE = "u"
61
+ c = trad("UTF-8", "@@")
62
+ r = ""
63
+ c.execute(StringIO.new(<<-SRC), StringIO.new(r), true)
64
+ [##sakura-iro]
65
+ [@ @sakura-iro]
66
+ [@@ sakura-iro]
67
+ [@@sakura-iro]
68
+ SRC
69
+
70
+ assert_equal(<<-EXPECTED, r)
71
+ [##sakura-iro]
72
+ [@ @sakura-iro]
73
+ [@@ sakura-iro]
74
+ [#fef4f4]
75
+ EXPECTED
76
+ end
77
+
78
+ def test_execute_alias
79
+ $KCODE = "u"
80
+ c = trad("UTF-8", "##")
81
+ r = ""
82
+ c.execute(StringIO.new(<<-SRC), StringIO.new(r), true)
83
+ ##alias myred sakura-iro
84
+ ##alias mywarn myred
85
+ [##myred]
86
+ [##mywarn]
87
+ SRC
88
+
89
+ assert_equal(<<-EXPECTED, r)
90
+ [#fef4f4]
91
+ [#fef4f4]
92
+ EXPECTED
93
+ end
94
+
95
+ def test_execute_trim_mode
96
+ $KCODE = "u"
97
+ c = trad("UTF-8", "##")
98
+ r = ""
99
+ c.execute(StringIO.new(<<-SRC.gsub(/^ /, "")), StringIO.new(r), true)
100
+ ##sakura-iro
101
+ ##sakura-iro
102
+ ##sakura-iro
103
+ SRC
104
+
105
+ assert_equal("#fef4f4#fef4f4#fef4f4", r)
106
+ end
107
+
108
+ def test_execute_trim_mode2
109
+ $KCODE = "u"
110
+ c = trad("UTF-8", "##")
111
+ c.trim_mode = ""
112
+ r = ""
113
+ c.execute(StringIO.new(<<-SRC.gsub(/^ /, "")), StringIO.new(r), true)
114
+ ##sakura-iro
115
+ ##sakura-iro
116
+ ##sakura-iro
117
+ SRC
118
+
119
+ assert_equal("\n#fef4f4\n#fef4f4\n#fef4f4\n", r)
120
+ end
121
+
122
+ def test_execute_unknown_color
123
+ $KCODE = "u"
124
+ c = trad("UTF-8", "##")
125
+ r = ""
126
+ c.execute(StringIO.new(<<-SRC.gsub(/^ /, "")), StringIO.new(r), true)
127
+ ##alias baz bazzz
128
+ ##foobar
129
+ ##baz
130
+ SRC
131
+
132
+ assert_equal("##foobar##baz", r)
133
+ end
134
+
135
+ def test_execute_erb
136
+ $KCODE = "u"
137
+ c = trad("UTF-8", "##")
138
+ r = ""
139
+ c.execute(StringIO.new(<<-SRC.gsub(/^ /, "")), StringIO.new(r), true)
140
+ <%= ##sakura-iro %>
141
+ SRC
142
+
143
+ assert_equal("#fef4f4", r)
144
+ end
145
+
146
+ def test_execute_erb_include_util
147
+ $KCODE = "u"
148
+ c = trad("UTF-8", "##")
149
+ r = ""
150
+ c.execute(StringIO.new(<<-SRC.gsub(/^ /, "")), StringIO.new(r), true)
151
+ % include Color::RGB::JP::ERBUtil
152
+ <%= lookup("sakura-iro").name.kanji %>
153
+ SRC
154
+
155
+ assert_equal(Fixture::UTF_8::SakuraIroKanji, r)
156
+ end
157
+
158
+ def test_execute_color_name_in_erb
159
+ $KCODE = "u"
160
+ c = trad("UTF-8", "##")
161
+ r = ""
162
+ c.execute(StringIO.new(<<-SRC.gsub(/^ /, "")), StringIO.new(r), true)
163
+ <%= ##sakura-iro.class %>
164
+ <%= ##sakura-iro.html %>
165
+ SRC
166
+
167
+ assert_equal("Color::RGB#fef4f4", r)
168
+ end
169
+
170
+ def test_execute_invalid_erb
171
+ $KCODE = "u"
172
+ c = trad("UTF-8", "##")
173
+ r = ""
174
+ c.execute(StringIO.new(<<-SRC.gsub(/^ /, "")), StringIO.new(r), true)
175
+ <%
176
+ ##sakura-iro
177
+ SRC
178
+
179
+ assert_equal("\nColor::RGB::JP::ERBUtil.to_rgb(%q{sakura-iro})\n", r)
180
+ end
181
+ end
@@ -0,0 +1,42 @@
1
+ # -*- encoding: utf8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/helper.rb'
4
+
5
+ class TestEncode < Test::Unit::TestCase
6
+
7
+ include Color::RGB::JP::Base::Encode
8
+
9
+ def test_internal_encoding
10
+ assert_kind_of(String, Color::RGB::JP::Base::Encode::INTERNAL_ENCODING)
11
+ end
12
+
13
+ def test_encode_to_nil
14
+ assert_nil(encode_to(nil, nil, nil))
15
+ assert_nil(encode_to("Shift_JIS", "UTF-8", nil))
16
+
17
+ assert_equal("あいう", encode_to(nil, nil, "あいう"))
18
+ assert_equal("あいう", encode_to(nil, "UTF-8", "あいう"))
19
+ assert_equal("あいう", encode_to("UTF-8", nil, "あいう"))
20
+ assert_equal("あいう", encode_to("UTF-8", "UTF-8", "あいう"))
21
+ end
22
+
23
+ def test_encode_to
24
+ assert_equal("あいう", encode_to("UTF-8", "Shift_JIS", "\x82\xa0\x82\xa2\x82\xa4"))
25
+ assert_equal("あいう", encode_to("UTF-8", "EUC-JP", "\xa4\xa2\xa4\xa4\xa4\xa6"))
26
+ end
27
+
28
+ def test_with_internal_encoding
29
+ with_internal_encoding(nil, nil) {|v|
30
+ assert_nil(v)
31
+ }
32
+ with_internal_encoding(nil, "Shift_JIS") {|v|
33
+ assert_nil(v)
34
+ }
35
+ with_internal_encoding("\x82\xa0\x82\xa2\x82\xa4", "Shift_JIS") {|v|
36
+ assert_equal("あいう", v)
37
+ }
38
+ with_internal_encoding("あいう", "UTF-8") {|v|
39
+ assert_equal("あいう", v)
40
+ }
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/helper.rb'
4
+
5
+ class TestJISZ8102 < Test::Unit::TestCase
6
+
7
+ T = Color::RGB::JP::JISZ8102
8
+
9
+ def test_alias
10
+ assert_same(Color::RGB::JP::JISZ8102, Color::RGB::JP::JIS)
11
+ end
12
+
13
+ def test_bracket_utf8
14
+ assert_equal(T::SakuraIro, T["sakurairo"])
15
+ assert_equal(T::SakuraIro, T["SakuraIro"])
16
+ assert_equal(T::SakuraIro, T["Sakura-Iro"])
17
+
18
+ assert_equal(T::SakuraIro, T[Fixture::UTF_8::SakuraIroKanji])
19
+ assert_equal(T::SakuraIro, T[Fixture::UTF_8::SakuraIroHiragana])
20
+ assert_equal(T::SakuraIro, T[Fixture::UTF_8::SakuraIroKatakana])
21
+
22
+ assert_equal(T::SakuraIro, T[Fixture::UTF_8::SakuraIroKanji, "UTF-8"])
23
+ assert_equal(T::SakuraIro, T[Fixture::UTF_8::SakuraIroHiragana, "UTF-8"])
24
+ assert_equal(T::SakuraIro, T[Fixture::UTF_8::SakuraIroKatakana, "UTF-8"])
25
+ end
26
+
27
+ def test_bracket_sjis
28
+ assert_equal(T::SakuraIro, T[Fixture::Shift_JIS::SakuraIroKanji, "Shift_JIS"])
29
+ assert_equal(T::SakuraIro, T[Fixture::Shift_JIS::SakuraIroHiragana, "Shift_JIS"])
30
+ assert_equal(T::SakuraIro, T[Fixture::Shift_JIS::SakuraIroKatakana, "Shift_JIS"])
31
+ end
32
+
33
+ def test_bracket_eucjp
34
+ assert_equal(T::SakuraIro, T[Fixture::EUC_JP::SakuraIroKanji, "EUC-JP"])
35
+ assert_equal(T::SakuraIro, T[Fixture::EUC_JP::SakuraIroHiragana, "EUC-JP"])
36
+ assert_equal(T::SakuraIro, T[Fixture::EUC_JP::SakuraIroKatakana, "EUC-JP"])
37
+ end
38
+
39
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/helper.rb'
4
+
5
+ class TestNamedRGB < Test::Unit::TestCase
6
+
7
+ ColorName = Color::RGB::JP::Base::ColorName
8
+ NamedRGB = Color::RGB::JP::Base::NamedRGB
9
+
10
+ def setup
11
+ @name = ColorName.new("SakuraIro", "桜色", "さくらいろ", "サクライロ", "sakura-iro")
12
+ @rgb = Color::RGB.from_html("abcABC")
13
+ @named_rgb = NamedRGB.new(@name, @rgb)
14
+ end
15
+
16
+ def test_new_and_accessor
17
+ assert_same(@name, @named_rgb.name)
18
+ assert_same(@rgb, @named_rgb.rgb)
19
+ end
20
+
21
+ def test_to_s
22
+ assert_equal("sakura-iro (#abcabc)", @named_rgb.to_s)
23
+ end
24
+
25
+ end
@@ -0,0 +1,78 @@
1
+ # -*- encoding: utf8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/helper.rb'
4
+
5
+ class TestPallet < Test::Unit::TestCase
6
+
7
+ module MyPallet
8
+ extend Color::RGB::JP::Base::Pallet
9
+
10
+ Foo = define_color("Foo", "abcdef", "風雨", "ふー", "フー", "foo")
11
+ Bar_A = define_color("Bar_A", "ff00bb", "馬嗚呼", "ばー", "バー", "ba-r")
12
+ Bar_B = define_color("Bar_B", "ff00bb", "葉嗚呼", "ばー", "バー", "ba-r")
13
+ end
14
+
15
+ module MySakura
16
+ extend Color::RGB::JP::Base::Pallet
17
+
18
+ SakuraIro = c("SakuraIro",
19
+ "aabbcc",
20
+ Fixture::UTF_8::SakuraIroKanji,
21
+ Fixture::UTF_8::SakuraIroHiragana,
22
+ Fixture::UTF_8::SakuraIroKatakana,
23
+ "sakura-iro")
24
+ end
25
+
26
+ def test_colors
27
+ assert_equal(3, MyPallet.colors.size)
28
+ assert_equal("Foo", MyPallet.colors[0].name.const_name)
29
+ assert_equal("Bar_A", MyPallet.colors[1].name.const_name)
30
+ assert_equal("Bar_B", MyPallet.colors[2].name.const_name)
31
+ end
32
+
33
+ def test_each
34
+ t = %W(Foo Bar_A Bar_B)
35
+ MyPallet.each do |c|
36
+ assert_equal(t.first ,c.name.const_name)
37
+ t.shift
38
+ end
39
+ end
40
+
41
+ def test_enumerable
42
+ r = MyPallet.find_all {|e| e.name.romaji =~ /f/}
43
+ assert_equal(1, r.length)
44
+ assert_equal(MyPallet::Foo, r.first)
45
+ end
46
+
47
+ def test_bracket
48
+ assert_equal(MyPallet::Foo, MyPallet["foo"])
49
+
50
+ assert_equal(MyPallet::Bar_A, MyPallet["ba-r"])
51
+ assert_equal(MyPallet::Bar_A, MyPallet["ばー"])
52
+ assert_equal(MyPallet::Bar_A, MyPallet["バー"])
53
+
54
+ assert_equal(MyPallet::Bar_A, MyPallet["Bar_A"])
55
+ assert_equal(MyPallet::Bar_B, MyPallet["Bar_B"])
56
+
57
+ assert_equal(MyPallet::Bar_A, MyPallet["馬嗚呼"])
58
+ assert_equal(MyPallet::Bar_B, MyPallet["葉嗚呼"])
59
+ end
60
+
61
+ def test_bracket_2
62
+ assert_equal(MyPallet::Bar_A, MyPallet["BAR"])
63
+ assert_equal(MyPallet::Bar_A, MyPallet["b-a-r-----"])
64
+ end
65
+
66
+ def test_bracket_sjis
67
+ assert_equal(MySakura::SakuraIro, MySakura[Fixture::Shift_JIS::SakuraIroKanji, "Shift_JIS"])
68
+ assert_equal(MySakura::SakuraIro, MySakura[Fixture::Shift_JIS::SakuraIroHiragana, "Shift_JIS"])
69
+ assert_equal(MySakura::SakuraIro, MySakura[Fixture::Shift_JIS::SakuraIroKatakana, "Shift_JIS"])
70
+ end
71
+
72
+ def test_bracket_eucjp
73
+ assert_equal(MySakura::SakuraIro, MySakura[Fixture::EUC_JP::SakuraIroKanji, "EUC-JP"])
74
+ assert_equal(MySakura::SakuraIro, MySakura[Fixture::EUC_JP::SakuraIroHiragana, "EUC-JP"])
75
+ assert_equal(MySakura::SakuraIro, MySakura[Fixture::EUC_JP::SakuraIroKatakana, "EUC-JP"])
76
+ end
77
+
78
+ end