copy repeater tests from chronic
authorChuck Hagenbuch <chuck@horde.org>
Wed, 4 Feb 2009 22:07:12 +0000 (17:07 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Wed, 4 Feb 2009 22:07:12 +0000 (17:07 -0500)
framework/Date_Parser/test/Horde/Date/Repeater/DayNameTest.php [new file with mode: 0644]
framework/Date_Parser/test/Horde/Date/Repeater/DayTest.php
framework/Date_Parser/test/Horde/Date/Repeater/HourTest.php [new file with mode: 0644]
framework/Date_Parser/test/Horde/Date/Repeater/MonthNameTest.php [new file with mode: 0644]
framework/Date_Parser/test/Horde/Date/Repeater/MonthTest.php [new file with mode: 0644]
framework/Date_Parser/test/Horde/Date/Repeater/TimeTest.php [new file with mode: 0644]
framework/Date_Parser/test/Horde/Date/Repeater/WeekTest.php [new file with mode: 0644]
framework/Date_Parser/test/Horde/Date/Repeater/WeekendTest.php [new file with mode: 0644]
framework/Date_Parser/test/Horde/Date/Repeater/YearTest.php [new file with mode: 0644]
framework/Date_Parser/test/TODO.txt [new file with mode: 0644]

diff --git a/framework/Date_Parser/test/Horde/Date/Repeater/DayNameTest.php b/framework/Date_Parser/test/Horde/Date/Repeater/DayNameTest.php
new file mode 100644 (file)
index 0000000..5a7c61b
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+class Horde_Date_Repeater_DayNameTest extends PHPUnit_Framework_TestCase
+{
+  def setup
+    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
+  end
+
+  def test_match
+    token = Chronic::Token.new('saturday')
+    repeater = Chronic::Repeater.scan_for_day_names(token)
+    assert_equal Chronic::RepeaterDayName, repeater.class
+    assert_equal :saturday, repeater.type
+
+    token = Chronic::Token.new('sunday')
+    repeater = Chronic::Repeater.scan_for_day_names(token)
+    assert_equal Chronic::RepeaterDayName, repeater.class
+    assert_equal :sunday, repeater.type
+  end
+
+  def test_next_future
+    mondays = Chronic::RepeaterDayName.new(:monday)
+    mondays.start = @now
+
+    span = mondays.next(:future)
+
+    assert_equal Time.local(2006, 8, 21), span.begin
+    assert_equal Time.local(2006, 8, 22), span.end
+
+    span = mondays.next(:future)
+
+    assert_equal Time.local(2006, 8, 28), span.begin
+    assert_equal Time.local(2006, 8, 29), span.end
+  end
+
+  def test_next_past
+    mondays = Chronic::RepeaterDayName.new(:monday)
+    mondays.start = @now
+
+    span = mondays.next(:past)
+
+    assert_equal Time.local(2006, 8, 14), span.begin
+    assert_equal Time.local(2006, 8, 15), span.end
+
+    span = mondays.next(:past)
+
+    assert_equal Time.local(2006, 8, 7), span.begin
+    assert_equal Time.local(2006, 8, 8), span.end
+  end
+
+end
\ No newline at end of file
index 99dfd37..b3424e8 100644 (file)
@@ -17,6 +17,7 @@ class Horde_Date_Repeater_DayTest extends PHPUnit_Framework_TestCase
         $repeater = new Horde_Date_Repeater_Day();
         $repeater->now = new Horde_Date('2009-01-01');
         $this->assertEquals('(2009-01-02 00:00:00..2009-01-03 00:00:00)', (string)$repeater->next('future'));
+        $this->assertEquals('(2008-12-31 00:00:00..2009-01-01 00:00:00)', (string)$repeater->next('past'));
     }
 
 }
diff --git a/framework/Date_Parser/test/Horde/Date/Repeater/HourTest.php b/framework/Date_Parser/test/Horde/Date/Repeater/HourTest.php
new file mode 100644 (file)
index 0000000..a3a5277
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+class Horde_Date_Repeater_HourTest extends PHPUnit_Framework_TestCase
+{
+  def setup
+    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
+  end
+
+  def test_next_future
+    hours = Chronic::RepeaterHour.new(:hour)
+    hours.start = @now
+
+    next_hour = hours.next(:future)
+    assert_equal Time.local(2006, 8, 16, 15), next_hour.begin
+    assert_equal Time.local(2006, 8, 16, 16), next_hour.end
+
+    next_next_hour = hours.next(:future)
+    assert_equal Time.local(2006, 8, 16, 16), next_next_hour.begin
+    assert_equal Time.local(2006, 8, 16, 17), next_next_hour.end
+  end
+
+  def test_next_past
+    hours = Chronic::RepeaterHour.new(:hour)
+    hours.start = @now
+
+    past_hour = hours.next(:past)
+    assert_equal Time.local(2006, 8, 16, 13), past_hour.begin
+    assert_equal Time.local(2006, 8, 16, 14), past_hour.end
+
+    past_past_hour = hours.next(:past)
+    assert_equal Time.local(2006, 8, 16, 12), past_past_hour.begin
+    assert_equal Time.local(2006, 8, 16, 13), past_past_hour.end
+  end
+
+  def test_this
+    @now = Time.local(2006, 8, 16, 14, 30)
+
+    hours = Chronic::RepeaterHour.new(:hour)
+    hours.start = @now
+
+    this_hour = hours.this(:future)
+    assert_equal Time.local(2006, 8, 16, 14, 31), this_hour.begin
+    assert_equal Time.local(2006, 8, 16, 15), this_hour.end
+
+    this_hour = hours.this(:past)
+    assert_equal Time.local(2006, 8, 16, 14), this_hour.begin
+    assert_equal Time.local(2006, 8, 16, 14, 30), this_hour.end
+  end
+
+  def test_offset
+    span = Chronic::Span.new(@now, @now + 1)
+
+    offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 3, :future)
+
+    assert_equal Time.local(2006, 8, 16, 17), offset_span.begin
+    assert_equal Time.local(2006, 8, 16, 17, 0, 1), offset_span.end
+
+    offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 24, :past)
+
+    assert_equal Time.local(2006, 8, 15, 14), offset_span.begin
+    assert_equal Time.local(2006, 8, 15, 14, 0, 1), offset_span.end
+  end
+
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/test/Horde/Date/Repeater/MonthNameTest.php b/framework/Date_Parser/test/Horde/Date/Repeater/MonthNameTest.php
new file mode 100644 (file)
index 0000000..6ba3612
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+class Horde_Date_Repeater_MonthNameTest extends PHPUnit_Framework_TestCase
+{
+  def setup
+    # Wed Aug 16 14:00:00 2006
+    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
+  end
+
+  def test_next
+    # future
+
+    mays = Chronic::RepeaterMonthName.new(:may)
+    mays.start = @now
+
+    next_may = mays.next(:future)
+    assert_equal Time.local(2007, 5), next_may.begin
+    assert_equal Time.local(2007, 6), next_may.end
+
+    next_next_may = mays.next(:future)
+    assert_equal Time.local(2008, 5), next_next_may.begin
+    assert_equal Time.local(2008, 6), next_next_may.end
+
+    decembers = Chronic::RepeaterMonthName.new(:december)
+    decembers.start = @now
+
+    next_december = decembers.next(:future)
+    assert_equal Time.local(2006, 12), next_december.begin
+    assert_equal Time.local(2007, 1), next_december.end
+
+    # past
+
+    mays = Chronic::RepeaterMonthName.new(:may)
+    mays.start = @now
+
+    assert_equal Time.local(2006, 5), mays.next(:past).begin
+    assert_equal Time.local(2005, 5), mays.next(:past).begin
+  end
+
+  def test_this
+    octobers = Chronic::RepeaterMonthName.new(:october)
+    octobers.start = @now
+
+    this_october = octobers.this(:future)
+    assert_equal Time.local(2006, 10, 1), this_october.begin
+    assert_equal Time.local(2006, 11, 1), this_october.end
+
+    aprils = Chronic::RepeaterMonthName.new(:april)
+    aprils.start = @now
+
+    this_april = aprils.this(:past)
+    assert_equal Time.local(2006, 4, 1), this_april.begin
+    assert_equal Time.local(2006, 5, 1), this_april.end
+  end
+
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/test/Horde/Date/Repeater/MonthTest.php b/framework/Date_Parser/test/Horde/Date/Repeater/MonthTest.php
new file mode 100644 (file)
index 0000000..8547ace
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+class Horde_Date_Repeater_MonthTest extends PHPUnit_Framework_TestCase
+{
+  def setup
+    # Wed Aug 16 14:00:00 2006
+    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
+  end
+
+  def test_offset_by
+    # future
+
+    time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :future)
+    assert_equal Time.local(2006, 9, 16, 14), time
+
+    time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 5, :future)
+    assert_equal Time.local(2007, 1, 16, 14), time
+
+    # past
+
+    time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :past)
+    assert_equal Time.local(2006, 7, 16, 14), time
+
+    time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 10, :past)
+    assert_equal Time.local(2005, 10, 16, 14), time
+  end
+
+  def test_offset
+    # future
+
+    span = Chronic::Span.new(@now, @now + 60)
+    offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :future)
+
+    assert_equal Time.local(2006, 9, 16, 14), offset_span.begin
+    assert_equal Time.local(2006, 9, 16, 14, 1), offset_span.end
+
+   # past
+
+   span = Chronic::Span.new(@now, @now + 60)
+   offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :past)
+
+   assert_equal Time.local(2006, 7, 16, 14), offset_span.begin
+   assert_equal Time.local(2006, 7, 16, 14, 1), offset_span.end
+  end
+
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/test/Horde/Date/Repeater/TimeTest.php b/framework/Date_Parser/test/Horde/Date/Repeater/TimeTest.php
new file mode 100644 (file)
index 0000000..ccc718a
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+class Horde_Date_Repeater_TimeTest extends PHPUnit_Framework_TestCase
+{
+  def setup
+    # Wed Aug 16 14:00:00 2006
+    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
+  end
+
+  def test_next_future
+    t = Chronic::RepeaterTime.new('4:00')
+    t.start = @now
+
+    assert_equal Time.local(2006, 8, 16, 16), t.next(:future).begin
+    assert_equal Time.local(2006, 8, 17, 4), t.next(:future).begin
+
+    t = Chronic::RepeaterTime.new('13:00')
+    t.start = @now
+
+    assert_equal Time.local(2006, 8, 17, 13), t.next(:future).begin
+    assert_equal Time.local(2006, 8, 18, 13), t.next(:future).begin
+
+    t = Chronic::RepeaterTime.new('0400')
+    t.start = @now
+
+    assert_equal Time.local(2006, 8, 17, 4), t.next(:future).begin
+    assert_equal Time.local(2006, 8, 18, 4), t.next(:future).begin
+  end
+
+  def test_next_past
+    t = Chronic::RepeaterTime.new('4:00')
+    t.start = @now
+
+    assert_equal Time.local(2006, 8, 16, 4), t.next(:past).begin
+    assert_equal Time.local(2006, 8, 15, 16), t.next(:past).begin
+
+    t = Chronic::RepeaterTime.new('13:00')
+    t.start = @now
+
+    assert_equal Time.local(2006, 8, 16, 13), t.next(:past).begin
+    assert_equal Time.local(2006, 8, 15, 13), t.next(:past).begin
+  end
+
+  def test_type
+    t1 = Chronic::RepeaterTime.new('4')
+    assert_equal 14_400, t1.type.time
+
+    t1 = Chronic::RepeaterTime.new('14')
+    assert_equal 50_400, t1.type.time
+
+    t1 = Chronic::RepeaterTime.new('4:00')
+    assert_equal 14_400, t1.type.time
+
+    t1 = Chronic::RepeaterTime.new('4:30')
+    assert_equal 16_200, t1.type.time
+
+    t1 = Chronic::RepeaterTime.new('1400')
+    assert_equal 50_400, t1.type.time
+
+    t1 = Chronic::RepeaterTime.new('0400')
+    assert_equal 14_400, t1.type.time
+
+    t1 = Chronic::RepeaterTime.new('04')
+    assert_equal 14_400, t1.type.time
+
+    t1 = Chronic::RepeaterTime.new('400')
+    assert_equal 14_400, t1.type.time
+  end
+
+
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/test/Horde/Date/Repeater/WeekTest.php b/framework/Date_Parser/test/Horde/Date/Repeater/WeekTest.php
new file mode 100644 (file)
index 0000000..77fdadf
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+class Horde_Date_Repeater_WeekTest extends PHPUnit_Framework_TestCase
+{
+  def setup
+    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
+  end
+
+  def test_next_future
+    weeks = Chronic::RepeaterWeek.new(:week)
+    weeks.start = @now
+
+    next_week = weeks.next(:future)
+    assert_equal Time.local(2006, 8, 20), next_week.begin
+    assert_equal Time.local(2006, 8, 27), next_week.end
+
+    next_next_week = weeks.next(:future)
+    assert_equal Time.local(2006, 8, 27), next_next_week.begin
+    assert_equal Time.local(2006, 9, 3), next_next_week.end
+  end
+
+  def test_next_past
+    weeks = Chronic::RepeaterWeek.new(:week)
+    weeks.start = @now
+
+    last_week = weeks.next(:past)
+    assert_equal Time.local(2006, 8, 6), last_week.begin
+    assert_equal Time.local(2006, 8, 13), last_week.end
+
+    last_last_week = weeks.next(:past)
+    assert_equal Time.local(2006, 7, 30), last_last_week.begin
+    assert_equal Time.local(2006, 8, 6), last_last_week.end
+  end
+
+  def test_this_future
+    weeks = Chronic::RepeaterWeek.new(:week)
+    weeks.start = @now
+
+    this_week = weeks.this(:future)
+    assert_equal Time.local(2006, 8, 16, 15), this_week.begin
+    assert_equal Time.local(2006, 8, 20), this_week.end
+  end
+
+  def test_this_past
+    weeks = Chronic::RepeaterWeek.new(:week)
+    weeks.start = @now
+
+    this_week = weeks.this(:past)
+    assert_equal Time.local(2006, 8, 13, 0), this_week.begin
+    assert_equal Time.local(2006, 8, 16, 14), this_week.end
+  end
+
+  def test_offset
+    span = Chronic::Span.new(@now, @now + 1)
+
+    offset_span = Chronic::RepeaterWeek.new(:week).offset(span, 3, :future)
+
+    assert_equal Time.local(2006, 9, 6, 14), offset_span.begin
+    assert_equal Time.local(2006, 9, 6, 14, 0, 1), offset_span.end
+  end
+
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/test/Horde/Date/Repeater/WeekendTest.php b/framework/Date_Parser/test/Horde/Date/Repeater/WeekendTest.php
new file mode 100644 (file)
index 0000000..06f7f6e
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+class Horde_Date_Repeater_WeekendTest extends PHPUnit_Framework_TestCase
+{
+  def setup
+    # Wed Aug 16 14:00:00 2006
+    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
+  end
+
+  def test_next_future
+    weekend = Chronic::RepeaterWeekend.new(:weekend)
+    weekend.start = @now
+
+    next_weekend = weekend.next(:future)
+    assert_equal Time.local(2006, 8, 19), next_weekend.begin
+    assert_equal Time.local(2006, 8, 21), next_weekend.end
+  end
+
+  def test_next_past
+    weekend = Chronic::RepeaterWeekend.new(:weekend)
+    weekend.start = @now
+
+    next_weekend = weekend.next(:past)
+    assert_equal Time.local(2006, 8, 12), next_weekend.begin
+    assert_equal Time.local(2006, 8, 14), next_weekend.end
+  end
+
+  def test_this_future
+    weekend = Chronic::RepeaterWeekend.new(:weekend)
+    weekend.start = @now
+
+    next_weekend = weekend.this(:future)
+    assert_equal Time.local(2006, 8, 19), next_weekend.begin
+    assert_equal Time.local(2006, 8, 21), next_weekend.end
+  end
+
+  def test_this_past
+    weekend = Chronic::RepeaterWeekend.new(:weekend)
+    weekend.start = @now
+
+    next_weekend = weekend.this(:past)
+    assert_equal Time.local(2006, 8, 12), next_weekend.begin
+    assert_equal Time.local(2006, 8, 14), next_weekend.end
+  end
+
+  def test_this_none
+    weekend = Chronic::RepeaterWeekend.new(:weekend)
+    weekend.start = @now
+
+    next_weekend = weekend.this(:future)
+    assert_equal Time.local(2006, 8, 19), next_weekend.begin
+    assert_equal Time.local(2006, 8, 21), next_weekend.end
+  end
+
+  def test_offset
+    span = Chronic::Span.new(@now, @now + 1)
+
+    offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 3, :future)
+
+    assert_equal Time.local(2006, 9, 2), offset_span.begin
+    assert_equal Time.local(2006, 9, 2, 0, 0, 1), offset_span.end
+
+    offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 1, :past)
+
+    assert_equal Time.local(2006, 8, 12), offset_span.begin
+    assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
+
+    offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 0, :future)
+
+    assert_equal Time.local(2006, 8, 12), offset_span.begin
+    assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
+  end
+
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/test/Horde/Date/Repeater/YearTest.php b/framework/Date_Parser/test/Horde/Date/Repeater/YearTest.php
new file mode 100644 (file)
index 0000000..20bb861
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+
+/**
+ * @category   Horde
+ * @package    Horde_Date
+ * @subpackage UnitTests
+ */
+class Horde_Date_Repeater_YearTest extends PHPUnit_Framework_TestCase
+{
+  def setup
+    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
+  end
+
+  def test_next_future
+    years = Chronic::RepeaterYear.new(:year)
+    years.start = @now
+
+    next_year = years.next(:future)
+    assert_equal Time.local(2007, 1, 1), next_year.begin
+    assert_equal Time.local(2008, 1, 1), next_year.end
+
+    next_next_year = years.next(:future)
+    assert_equal Time.local(2008, 1, 1), next_next_year.begin
+    assert_equal Time.local(2009, 1, 1), next_next_year.end
+  end
+
+  def test_next_past
+    years = Chronic::RepeaterYear.new(:year)
+    years.start = @now
+
+    last_year = years.next(:past)
+    assert_equal Time.local(2005, 1, 1), last_year.begin
+    assert_equal Time.local(2006, 1, 1), last_year.end
+
+    last_last_year = years.next(:past)
+    assert_equal Time.local(2004, 1, 1), last_last_year.begin
+    assert_equal Time.local(2005, 1, 1), last_last_year.end
+  end
+
+  def test_this
+    years = Chronic::RepeaterYear.new(:year)
+    years.start = @now
+
+    this_year = years.this(:future)
+    assert_equal Time.local(2006, 8, 17), this_year.begin
+    assert_equal Time.local(2007, 1, 1), this_year.end
+
+    this_year = years.this(:past)
+    assert_equal Time.local(2006, 1, 1), this_year.begin
+    assert_equal Time.local(2006, 8, 16), this_year.end
+  end
+
+  def test_offset
+    span = Chronic::Span.new(@now, @now + 1)
+
+    offset_span = Chronic::RepeaterYear.new(:year).offset(span, 3, :future)
+
+    assert_equal Time.local(2009, 8, 16, 14), offset_span.begin
+    assert_equal Time.local(2009, 8, 16, 14, 0, 1), offset_span.end
+
+    offset_span = Chronic::RepeaterYear.new(:year).offset(span, 10, :past)
+
+    assert_equal Time.local(1996, 8, 16, 14), offset_span.begin
+    assert_equal Time.local(1996, 8, 16, 14, 0, 1), offset_span.end
+  end
+
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/test/TODO.txt b/framework/Date_Parser/test/TODO.txt
new file mode 100644 (file)
index 0000000..ca0c62b
--- /dev/null
@@ -0,0 +1 @@
+http://www.datejs.com/test/index.html