Пример #1
0
  /** Tests the stripchars expression. */
  public void testStripchars() {

    assertEquals(
        "test",
        zx.getExpressionHandler().eval("stripchars('t1e2s3t4', '[1234]')").getStringValue());
    // Same as stripnonxchars('t-e!s.t@', '[a-zA-Z0-9]')
    assertEquals(
        "test",
        zx.getExpressionHandler().eval("stripchars('t-e!s.t@', '[^a-zA-Z0-9]')").getStringValue());
  }
Пример #2
0
  /** Tests expressions with no arguments. */
  public void testNoArgs() {

    assertEquals("", zx.getExpressionHandler().eval("null()").getStringValue());
    assertEquals(true, zx.getExpressionHandler().eval("null()").isNull);

    assertEquals("\r", zx.getExpressionHandler().eval("cr()").getStringValue());

    // assertEquals(new Date().toString(),
    // ((Property)zx.getExpressionHandler().eval("now()")).dateValue().toString());

    zx.trace.addError("test");
    assertEquals("test", zx.getExpressionHandler().eval("systemmsg()").getStringValue());
  }
Пример #3
0
  /** Test expressions with variable arguements */
  public void testVarArgs() {

    // choose(3, 'a', 'b', 'c', 'd') - > c
    assertEquals(
        "c", zx.getExpressionHandler().eval("choose(3, 'a', 'b', 'c', 'd')").getStringValue());

    // translate(1, 0, 'a', 1, 'b', 2, 'c', 3, 'd') - > b
    assertEquals(
        "b",
        zx.getExpressionHandler()
            .eval("translate(1, 0, 'a', 1, 'b', 2, 'c', 3, 'd')")
            .getStringValue());
    assertEquals(
        "charlie",
        zx.getExpressionHandler()
            .eval("translate('c', 'a', 'alpha', 'b', 'bravo', 'c', 'charlie', 'd', 'delta')")
            .getStringValue());

    assertEquals(
        "abcd", zx.getExpressionHandler().eval("concat('a','b','c','d')").getStringValue());
    assertEquals(
        "12)4", zx.getExpressionHandler().eval("concat('1', '2', ')', '4')").getStringValue());
  }
Пример #4
0
  /** Test expressions with a single argument. */
  public void testOneArgs() {
    // char(3) - > 3
    assertEquals("3", zx.getExpressionHandler().eval("chr(3)").getStringValue());

    assertEquals(true, zx.getExpressionHandler().eval("setqs('test','hello')").booleanValue());
    assertEquals("hello", zx.getExpressionHandler().eval("qs('test')").getStringValue());
    assertEquals(true, zx.getExpressionHandler().eval("setqs('test','')").booleanValue());
    assertEquals(true, zx.getExpressionHandler().eval("qs('test')").isNull);

    assertEquals(10, zx.getExpressionHandler().eval("add(5,5)").longValue());
    assertEquals(5.5, zx.getExpressionHandler().eval("add(5,0.5)").doubleValue(), 0.0);

    assertEquals(25, zx.getExpressionHandler().eval("mul(5,5)").longValue());
    assertEquals(2.5, zx.getExpressionHandler().eval("mul(5,0.5)").doubleValue(), 0.0);

    assertEquals(0, zx.getExpressionHandler().eval("sub(5,5)").longValue());
    assertEquals(4.5, zx.getExpressionHandler().eval("sub(5,0.5)").doubleValue(), 0.0);

    assertEquals(1, zx.getExpressionHandler().eval("div(5,5)").longValue());
    assertEquals(10, zx.getExpressionHandler().eval("div(5,0.5)").doubleValue(), 0.0);

    assertEquals("Hello", zx.getExpressionHandler().eval("getline('Hello',0)").getStringValue());
    assertEquals("Hello", zx.getExpressionHandler().eval("getline('Hello',1)").getStringValue());

    assertEquals("Hello", zx.getExpressionHandler().eval("getline('Hello','-1')").getStringValue());
    assertEquals("Hello", zx.getExpressionHandler().eval("getline('Hello',-1)").getStringValue());
    assertEquals(
        "World", zx.getExpressionHandler().eval("getline('Hello\nWorld','-1')").getStringValue());

    // getword
    assertEquals("", zx.getExpressionHandler().eval("getword('', 0, ' ')").getStringValue());
    assertEquals("", zx.getExpressionHandler().eval("getword('', 2, ' ')").getStringValue());
    assertEquals("", zx.getExpressionHandler().eval("getword('', -1)").getStringValue());
    assertEquals("t", zx.getExpressionHandler().eval("getword('t', -1, ' ')").getStringValue());
    assertEquals("t", zx.getExpressionHandler().eval("getword('t', 1)").getStringValue());
    assertEquals("", zx.getExpressionHandler().eval("getword('testing', 2, ' ')").getStringValue());
    assertEquals(
        "", zx.getExpressionHandler().eval("getword('testing', -2, ' ')").getStringValue());
    assertEquals(
        "testing", zx.getExpressionHandler().eval("getword('testing', 1, ' ')").getStringValue());
    assertEquals(
        "yes", zx.getExpressionHandler().eval("getword('yes test', 1, ' ')").getStringValue());
    assertEquals(
        "test", zx.getExpressionHandler().eval("getword('yes test', 2, ' ')").getStringValue());
    assertEquals(
        "four",
        zx.getExpressionHandler()
            .eval("getword('yes test one four you', 4, ' ')")
            .getStringValue());
  }