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());
}
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));
}
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"));
}
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));
}
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));
}
Aggregations