Example #1
0
  // NOTE: BuiltinFunTable already implements Left; todo: use this
  public void testLeft() {
    assertEquals("abc", Vba.left("abcxyz", 3));
    // length=0 is OK
    assertEquals("", Vba.left("abcxyz", 0));
    // Spec says: "If greater than or equal to the number of characters in
    // string, the entire string is returned."
    assertEquals("abcxyz", Vba.left("abcxyz", 8));
    assertEquals("", Vba.left("", 3));

    // Length<0 is illegal.
    // Note: SSAS 2005 allows length<0, giving the same result as length=0.
    // We favor the VBA spec over SSAS 2005.
    if (Bug.Ssas2005Compatible) {
      assertEquals("", Vba.left("xyz", -2));
    } else {
      try {
        String s = Vba.left("xyz", -2);
        fail("expected error, got " + s);
      } catch (RuntimeException e) {
        assertMessage(e, "StringIndexOutOfBoundsException");
      }
    }

    assertEquals("Hello", Vba.left("Hello World!", 5));
  }