Example #1
0
  public void testCDate() throws ParseException {
    Date date = new Date();
    assertEquals(date, Vba.cDate(date));
    assertNull(Vba.cDate(null));
    // CInt rounds to the nearest even number
    try {
      assertEquals(DateFormat.getDateInstance().parse("Jan 12, 1952"), Vba.cDate("Jan 12, 1952"));
      assertEquals(
          DateFormat.getDateInstance().parse("October 19, 1962"), Vba.cDate("October 19, 1962"));
      assertEquals(DateFormat.getTimeInstance().parse("4:35:47 PM"), Vba.cDate("4:35:47 PM"));
      assertEquals(
          DateFormat.getDateTimeInstance().parse("October 19, 1962 4:35:47 PM"),
          Vba.cDate("October 19, 1962 4:35:47 PM"));
    } catch (ParseException e) {
      e.printStackTrace();
      fail();
    }

    try {
      Vba.cDate("Jan, 1952");
      fail();
    } catch (InvalidArgumentException e) {
      assertTrue(e.getMessage().indexOf("Jan, 1952") >= 0);
    }
  }
Example #2
0
 public void testInStrRev() {
   assertEquals(32, Vba.inStrRev("the quick brown fox jumps over the lazy dog", "the"));
   assertEquals(1, Vba.inStrRev("the quick brown fox jumps over the lazy dog", "the", 16));
   try {
     Vba.inStrRev("the quick brown fox jumps over the lazy dog", "the", 0);
     fail();
   } catch (InvalidArgumentException e) {
     assertTrue(e.getMessage().indexOf("-1 or a location") >= 0);
   }
 }
Example #3
0
 public void testInStr() {
   assertEquals(1, Vba.inStr("the quick brown fox jumps over the lazy dog", "the"));
   assertEquals(32, Vba.inStr(16, "the quick brown fox jumps over the lazy dog", "the"));
   assertEquals(0, Vba.inStr(16, "the quick brown fox jumps over the lazy dog", "cat"));
   assertEquals(0, Vba.inStr(1, "the quick brown fox jumps over the lazy dog", "cat"));
   assertEquals(0, Vba.inStr(1, "", "cat"));
   assertEquals(0, Vba.inStr(100, "short string", "str"));
   try {
     Vba.inStr(0, "the quick brown fox jumps over the lazy dog", "the");
     fail();
   } catch (InvalidArgumentException e) {
     assertTrue(e.getMessage().indexOf("-1 or a location") >= 0);
   }
 }