Permalink
Browse files

refine tests

  • Loading branch information...
1 parent 627130d commit da7d6b96abaff43f344e4fd85e47a8fd585c5ad9 @melborne committed Dec 17, 2010
Showing with 110 additions and 43 deletions.
  1. +24 −28 test/tc_month.rb
  2. +86 −15 test/tc_year.rb
View
@@ -69,15 +69,16 @@ def test_monochrome_format
"27 28 29 30 31 "
]
f2010_12_from0_line = [
- " 2010 ",
- " December ",
+ "2010",
+ "December",
" S M T W T F S S M T W T F S S M T W T F S S M T W T F S S M T W T F S ",
- " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31"
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31"
]
assert_equal(f2010_12_from0, @m.format)
assert_equal(f2010_12_from0, @m.format(:block, 0))
assert_equal(f2010_12_from1, @m.format(:block, 1))
- assert_equal(f2010_12_from0_line, @m.format(:line))
+ format = @m.format(:line).join
+ f2010_12_from0_line.each { |line| assert_match(/#{line}/, format) }
end
def test_color_format
@@ -86,42 +87,36 @@ def test_color_format
" \e[32mDecember\e[0m ",
" S M T W T F S",
" 1 2 3 \e[36m 4\e[0m",
- "\e[35m 5\e[0m 6 7 8 9 10 \e[36m11\e[0m",
- "\e[35m12\e[0m 13 14 15 \e[4m\e[32m16\e[0m\e[0m 17 \e[36m18\e[0m",
- "\e[35m19\e[0m 20 21 22 23 24 \e[36m25\e[0m",
- "\e[35m26\e[0m 27 28 29 30 31 "
+ "\e[35m 5\e[0m 6 7 8 9 10 \e[36m11\e[0m"
]
f2010_12_from1_block = [
" \e[33m2010\e[0m ",
" \e[32mDecember\e[0m ",
" M T W T F S S",
" 1 2 3 \e[36m 4\e[0m \e[35m 5\e[0m",
- " 6 7 8 9 10 \e[36m11\e[0m \e[35m12\e[0m",
- "13 14 15 \e[4m\e[32m16\e[0m\e[0m 17 \e[36m18\e[0m \e[35m19\e[0m",
- "20 21 22 23 24 \e[36m25\e[0m \e[35m26\e[0m",
- "27 28 29 30 31 "
+ " 6 7 8 9 10 \e[36m11\e[0m \e[35m12\e[0m"
]
f2010_12_from1_line = [
" \e[33m2010\e[0m ",
" \e[32mDecember\e[0m ",
" M T W T F S S M T W T F S S M T W T F S S M T W T F S S M T W T F S S ",
- " 1 2 3 \e[36m 4\e[0m \e[35m 5\e[0m 6 7 8 9 10 \e[36m11\e[0m \e[35m12\e[0m 13 14 15 \e[4m\e[32m16\e[0m\e[0m 17 \e[36m18\e[0m \e[35m19\e[0m 20 21 22 23 24 \e[36m25\e[0m \e[35m26\e[0m 27 28 29 30 31"
- ]
+ " 1 2 3 \e[36m 4\e[0m \e[35m 5\e[0m 6 7 8 9 10 \e[36m11\e[0m \e[35m12\e[0m"
+ ]
f2010_12_from0_block3 =[
" \e[33m \e[0m \e[33m2010\e[0m \e[33m \e[0m ",
- [" \e[32mNovember\e[0m \e[32mDecember\e[0m \e[32mJanuary\e[0m ",
+ " \e[32mNovember\e[0m \e[32mDecember\e[0m \e[32mJanuary\e[0m ",
" S M T W T F S S M T W T F S S M T W T F S",
" 1 2 3 4 5 \e[36m 6\e[0m 1 2 3 \e[36m 4\e[0m \e[36m 1\e[0m",
- "\e[35m 7\e[0m 8 9 10 11 12 \e[36m13\e[0m \e[35m 5\e[0m 6 7 8 9 10 \e[36m11\e[0m \e[35m 2\e[0m 3 4 5 6 7 \e[36m 8\e[0m",
- "\e[35m14\e[0m 15 16 17 18 19 \e[36m20\e[0m \e[35m12\e[0m 13 14 15 \e[4m\e[32m16\e[0m\e[0m 17 \e[36m18\e[0m \e[35m 9\e[0m 10 11 12 13 14 \e[36m15\e[0m",
- "\e[35m21\e[0m 22 23 24 25 26 \e[36m27\e[0m \e[35m19\e[0m 20 21 22 23 24 \e[36m25\e[0m \e[35m16\e[0m 17 18 19 20 21 \e[36m22\e[0m",
- "\e[35m28\e[0m 29 30 \e[35m26\e[0m 27 28 29 30 31 \e[35m23\e[0m 24 25 26 27 28 \e[36m29\e[0m",
- " \e[35m30\e[0m 31 "]
+ "\e[35m 7\e[0m 8 9 10 11 12 \e[36m13\e[0m \e[35m 5\e[0m 6 7 8 9 10 \e[36m11\e[0m \e[35m 2\e[0m 3 4 5 6 7 \e[36m 8\e[0m"
]
- assert_equal(f2010_12_from0_block, @m.color_format(:block, 0))
- assert_equal(f2010_12_from1_block, @m.color_format(:block, 1))
- assert_equal(f2010_12_from1_line, @m.color_format(:line, 1))
- assert_equal(f2010_12_from0_block3, @m.color_format(:block3))
+ format = @m.color_format(:block, 0).join
+ f2010_12_from0_block.each { |line| assert_match(/#{Regexp.escape line}/, format) }
+ format = @m.color_format(:block, 1).join
+ f2010_12_from1_block.each { |line| assert_match(/#{Regexp.escape line}/, format) }
+ format = @m.color_format(:line, 1).join
+ f2010_12_from1_line.each { |line| assert_match(/#{Regexp.escape line}/, format) }
+ format = @m.color_format(:block3).join
+ f2010_12_from0_block3.each { |line| assert_match(/#{Regexp.escape line}/, format) }
end
def test_holidays
@@ -131,11 +126,11 @@ def test_holidays
@m.holidays = :ja_ja
assert_match(day23, @m.color_format.join )
day3_23_1_10.each { |d| assert_match(d, @m.color_format(:block3).join) }
- titles.each { |t| assert_match(/#{t}/, @m.color_format(:block3).join) }
+ titles.each { |t| assert_match(/#{t}/, @m.color_format(:block3, 0, true).join) }
titles.each { |t| refute_match(/#{t}/, @m.color_format(:block3, 0, false).join) }
au_titles = ['Melbourne Cup Day', 'Christmas Day', 'Boxing Day', 'Public Holiday', 'Public Holiday', 'New Year\'s Day', 'Australia Day']
@m.holidays = :au
- au_titles.each { |t| assert_match(/#{t}/, @m.color_format(:block3).join) }
+ au_titles.each { |t| assert_match(/#{t}/, @m.color_format(:block3, 0 , true).join) }
end
def test_color_format_with_color_changes
@@ -148,8 +143,9 @@ def test_color_format_with_color_changes
colors = { year: :cyan, month: :red, today: [:blue, :on_yellow],
saturday: :white, sunday: :black, holiday: :blue, neighbor: :black }
m.colors = colors
+ format = m.color_format(:line).join
colors = {25 => 37, 26 => 30, 2010 => 36, 'December' => 31,
- 16 => '43m\e\[34', 23 => 34, 30 => 30}.map { |d, c| /\e\[#{c}m#{d}\e\[0m/ }
- colors.each { |c| assert_match(c, m.color_format(:line).join) }
+ Time.now.day => '43m\e\[34', 23 => 34, 30 => 30}.map { |d, c| /\e\[#{c}m#{d}\e\[0m/ }
+ colors.each { |c| assert_match(c, format) }
end
end
View
@@ -7,28 +7,99 @@ def setup
@y2010 = Caline::Year.new(2010)
end
- def test_format_with_weekline
- puts @y2010.format(:block, 1)
- puts @y2010.color_format(:block)
- end
+ def test_format_with_block_style
+ y2010_from_monday = [
+ " 2010 ",
+ [" January February March ",
+ " M T W T F S S M T W T F S S M T W T F S S",
+ " 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7",
+ " 4 5 6 7 8 9 10 8 9 10 11 12 13 14 8 9 10 11 12 13 14",
+ "11 12 13 14 15 16 17 15 16 17 18 19 20 21 15 16 17 18 19 20 21",
+ "18 19 20 21 22 23 24 22 23 24 25 26 27 28 22 23 24 25 26 27 28",
+ "25 26 27 28 29 30 31 29 30 31 "],
+ [" April May June ",
+ " M T W T F S S M T W T F S S M T W T F S S",
+ " 1 2 3 4 1 2 1 2 3 4 5 6",
+ " 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13",
+ "12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20",
+ "19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27",
+ "26 27 28 29 30 24 25 26 27 28 29 30 28 29 30 ",
+ " 31 "],
+ [" July August September ",
+ " M T W T F S S M T W T F S S M T W T F S S",
+ " 1 2 3 4 1 1 2 3 4 5",
+ " 5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12",
+ "12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19",
+ "19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26",
+ "26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30 ",
+ " 30 31 "],
+ [" October November December ",
+ " M T W T F S S M T W T F S S M T W T F S S",
+ " 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5",
+ " 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12",
+ "11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19",
+ "18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26",
+ "25 26 27 28 29 30 31 29 30 27 28 29 30 31 "]
+ ]
- def test_fromat_with_monthline
- puts @y2010.format(:line)
- puts @y2010.color_format(:line, 1)
+ y2010_from_sunday_with_color = [
+ " \e[33m \e[0m \e[33m2010\e[0m \e[33m \e[0m ",
+ " \e[32mJanuary\e[0m \e[32mFebruary\e[0m \e[32mMarch\e[0m ",
+ " S M T W T F S S M T W T F S S M T W T F S",
+ " 1 \e[36m 2\e[0m 1 2 3 4 5 \e[36m 6\e[0m 1 2 3 4 5 \e[36m 6\e[0m",
+"\e[35m 3\e[0m 4 5 6 7 8 \e[36m 9\e[0m \e[35m 7\e[0m 8 9 10 11 12 \e[36m13\e[0m \e[35m 7\e[0m 8 9 10 11 12 \e[36m13\e[0m",
+"\e[35m10\e[0m 11 12 13 14 15 \e[36m16\e[0m \e[35m14\e[0m 15 16 17 18 19 \e[36m20\e[0m \e[35m14\e[0m 15 16 17 18 19 \e[36m20\e[0m",
+"\e[35m17\e[0m 18 19 20 21 22 \e[36m23\e[0m \e[35m21\e[0m 22 23 24 25 26 \e[36m27\e[0m \e[35m21\e[0m 22 23 24 25 26 \e[36m27\e[0m",
+"\e[35m24\e[0m 25 26 27 28 29 \e[36m30\e[0m \e[35m28\e[0m \e[35m28\e[0m 29 30 31 ",
+"\e[35m31\e[0m "
+ ]
+ assert_equal(y2010_from_monday, @y2010.format(:block, 1))
+ y2010_color = @y2010.color_format(:block).join
+ y2010_from_sunday_with_color.each { |line| assert_match(/#{Regexp.escape line}/, y2010_color) }
end
- def test_color_options
- cal = Caline::Year.new(2010, today:[:red, :blink, :on_blue], year: :magenta)
- puts cal.color_format
+ def test_fromat_with_line_style
+ y2010_monochrome_line = ["2010",
+ "January",
+ " S M T W T F S S M T W T F S S M T W T F S S M T W T F S S M T W T F S ",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31",
+ "February",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28",
+ "March",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31",
+ "April",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30",
+ "May",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31",
+ "June",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30",
+ "July",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31",
+ "August",
+ " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31",
+ "September",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30",
+ "October",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31",
+ "November",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30",
+ "December",
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31"]
+ format = @y2010.format(:line).join
+ y2010_monochrome_line.each { |line| assert_match(/#{line}/, format) }
end
def test_neighbor_option
- cal = Caline::Year.new(2009, neighbor: :black)
- puts cal.color_format
+ y2009 = [
+ "\e[30m28\e[0m \e[30m29\e[0m \e[30m30\e[0m \e[30m31\e[0m 1 2 \e[36m 3\e[0m \e[35m 1\e[0m 2 3 4 5 6 \e[36m 7\e[0m \e[35m 1\e[0m 2 3 4 5 6 \e[36m 7\e[0m",
+ "\e[35m18\e[0m 19 20 21 22 23 \e[36m24\e[0m \e[35m22\e[0m 23 24 25 26 27 \e[36m28\e[0m \e[35m22\e[0m 23 24 25 26 27 \e[36m28\e[0m", "\e[35m25\e[0m 26 27 28 29 30 \e[36m31\e[0m \e[35m29\e[0m 30 31 \e[30m 1\e[0m \e[30m 2\e[0m \e[30m 3\e[0m \e[30m 4\e[0m"
+ ]
+ format = Caline::Year.new(2009, neighbor: :black).color_format.join
+ y2009.each { |line| assert_match(/#{Regexp.escape line}/, format) }
end
- def test_holidays_option
- cal = Caline::Year.new(2012, holidays: :us)
- puts cal.color_format
+ def test_holidays_names
+ y = Caline::Year.new(2010, holidays: :ja_ja)
+ puts y.color_format
end
end

0 comments on commit da7d6b9

Please sign in to comment.