Search in sources :

Example 26 with AviatorString

use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.

the class String2DateFunctionUnitTest method testCall.

@Test
public void testCall() {
    assertEquals("string_to_date", function.getName());
    String source = "2011-09-17";
    Date date = (Date) function.call(null, AviatorRuntimeJavaType.valueOf(source), new AviatorString("yyyy-MM-dd")).getValue(null);
    assertNotNull(date);
    assertEquals(111, date.getYear());
    assertEquals(8, date.getMonth());
    assertEquals(17, date.getDate());
}
Also used : AviatorString(com.googlecode.aviator.runtime.type.AviatorString) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) Date(java.util.Date) Test(org.junit.Test)

Example 27 with AviatorString

use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.

the class StringSplitJointFunctionUnitTest method testSplitJoin.

@Test
public void testSplitJoin() {
    StringSplitFunction splitFn = new StringSplitFunction();
    StringJoinFunction joinFn = new StringJoinFunction();
    assertEquals("string.split", splitFn.getName());
    assertEquals("string.join", joinFn.getName());
    String[] tmps = (String[]) splitFn.call(null, new AviatorString("a,b,c,d,e,f,g"), new AviatorString(",")).getValue(null);
    assertNotNull(tmps);
    assertEquals(7, tmps.length);
    assertArrayEquals(new String[] { "a", "b", "c", "d", "e", "f", "g" }, tmps);
    assertEquals("a b c d e f g", (String) joinFn.call(null, AviatorRuntimeJavaType.valueOf(tmps), new AviatorString(" ")).getValue(null));
    assertEquals("abcdefg", (String) joinFn.call(null, AviatorRuntimeJavaType.valueOf(tmps)).getValue(null));
}
Also used : AviatorString(com.googlecode.aviator.runtime.type.AviatorString) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) Test(org.junit.Test)

Example 28 with AviatorString

use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.

the class Date2StringFunctionUnitTest method testCall_NotDate.

@Test(expected = ClassCastException.class)
public void testCall_NotDate() {
    assertEquals("date_to_string", function.getName());
    function.call(null, AviatorRuntimeJavaType.valueOf(1), new AviatorString("yyyyMMdd"));
}
Also used : AviatorString(com.googlecode.aviator.runtime.type.AviatorString) Test(org.junit.Test)

Example 29 with AviatorString

use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.

the class Date2StringFunctionUnitTest method testCall.

@Test
public void testCall() {
    assertEquals("date_to_string", function.getName());
    Date date = new Date();
    assertEquals(DateFormatCache.getOrCreateDateFormat("yyyyMMdd").format(date), function.call(null, AviatorRuntimeJavaType.valueOf(date), new AviatorString("yyyyMMdd")).getValue(null));
    assertEquals(DateFormatCache.getOrCreateDateFormat("yyyy--MM--dd").format(date), function.call(null, AviatorRuntimeJavaType.valueOf(date), new AviatorString("yyyy--MM--dd")).getValue(null));
}
Also used : AviatorString(com.googlecode.aviator.runtime.type.AviatorString) Date(java.util.Date) Test(org.junit.Test)

Example 30 with AviatorString

use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.

the class PrintFunctionUnitTest method testCall_WithOneArgument.

@Test
public void testCall_WithOneArgument() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    System.setOut(new PrintStream(out));
    this.fun.call(null, new AviatorString("hello"));
    out.flush();
    out.close();
    byte[] data = out.toByteArray();
    assertEquals("hello", new String(data));
}
Also used : PrintStream(java.io.PrintStream) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) Test(org.junit.Test)

Aggregations

AviatorString (com.googlecode.aviator.runtime.type.AviatorString)33 Test (org.junit.Test)19 AviatorObject (com.googlecode.aviator.runtime.type.AviatorObject)14 HashMap (java.util.HashMap)11 AviatorJavaType (com.googlecode.aviator.runtime.type.AviatorJavaType)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AbstractFunction (com.googlecode.aviator.runtime.function.AbstractFunction)3 Date (java.util.Date)3 List (java.util.List)3 Map (java.util.Map)3 ExpressionRuntimeException (com.googlecode.aviator.exception.ExpressionRuntimeException)2 NumberToken (com.googlecode.aviator.lexer.token.NumberToken)2 AviatorPattern (com.googlecode.aviator.runtime.type.AviatorPattern)2 PrintStream (java.io.PrintStream)2 Collection (java.util.Collection)2 LinkedList (java.util.LinkedList)2 ID (cn.devezhao.persist4j.engine.ID)1 AviatorEvaluator (com.googlecode.aviator.AviatorEvaluator)1 AviatorNil (com.googlecode.aviator.runtime.type.AviatorNil)1 AviatorNumber (com.googlecode.aviator.runtime.type.AviatorNumber)1