@Override public String toString() { return "'" + getLiteralValue().getValue() + "'"; }
@Test(expected = SpelEvaluationException.class) public void test_unaryPlusWithStringLiteral() { ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext()); StringLiteral str = new StringLiteral("word", -1, -1, "word"); OpPlus o = new OpPlus(-1, -1, str); o.getValueInternal(expressionState); }
@Test public void test_binaryPlusWithTime_ToString() { ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext()); Time time = new Time(new Date().getTime()); VariableReference var = new VariableReference("timeVar", -1, -1); var.setValue(expressionState, time); StringLiteral n2 = new StringLiteral("\" is now\"", -1, -1, "\" is now\""); OpPlus o = new OpPlus(-1, -1, var, n2); TypedValue value = o.getValueInternal(expressionState); assertEquals(String.class, value.getTypeDescriptor().getObjectType()); assertEquals(String.class, value.getTypeDescriptor().getType()); assertEquals(time + " is now", value.getValue()); }
@Test public void test_binaryPlusWithTimeConverted() { SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH); GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(Time.class, String.class, format::format); StandardEvaluationContext evaluationContextConverter = new StandardEvaluationContext(); evaluationContextConverter.setTypeConverter(new StandardTypeConverter(conversionService)); ExpressionState expressionState = new ExpressionState(evaluationContextConverter); Time time = new Time(new Date().getTime()); VariableReference var = new VariableReference("timeVar", -1, -1); var.setValue(expressionState, time); StringLiteral n2 = new StringLiteral("\" is now\"", -1, -1, "\" is now\""); OpPlus o = new OpPlus(-1, -1, var, n2); TypedValue value = o.getValueInternal(expressionState); assertEquals(String.class, value.getTypeDescriptor().getObjectType()); assertEquals(String.class, value.getTypeDescriptor().getType()); assertEquals(format.format(time) + " is now", value.getValue()); }
@Override public String toString() { return "'" + getLiteralValue().getValue() + "'"; }
@Test public void test_binaryPlusWithStringOperands() { ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext()); StringLiteral n1 = new StringLiteral("\"foo\"", -1, -1, "\"foo\""); StringLiteral n2 = new StringLiteral("\"bar\"", -1, -1, "\"bar\""); OpPlus o = new OpPlus(-1, -1, n1, n2); TypedValue value = o.getValueInternal(expressionState); assertEquals(String.class, value.getTypeDescriptor().getObjectType()); assertEquals(String.class, value.getTypeDescriptor().getType()); assertEquals("foobar", value.getValue()); }
@Override public String toString() { return "'" + getLiteralValue().getValue() + "'"; }
@Test public void test_binaryPlusWithLeftStringOperand() { ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext()); StringLiteral n1 = new StringLiteral("\"number is \"", -1, -1, "\"number is \""); LongLiteral n2 = new LongLiteral("123", -1, -1, 123); OpPlus o = new OpPlus(-1, -1, n1, n2); TypedValue value = o.getValueInternal(expressionState); assertEquals(String.class, value.getTypeDescriptor().getObjectType()); assertEquals(String.class, value.getTypeDescriptor().getType()); assertEquals("number is 123", value.getValue()); }
@Test public void test_binaryPlusWithRightStringOperand() { ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext()); LongLiteral n1 = new LongLiteral("123", -1, -1, 123); StringLiteral n2 = new StringLiteral("\" is a number\"", -1, -1, "\" is a number\""); OpPlus o = new OpPlus(-1, -1, n1, n2); TypedValue value = o.getValueInternal(expressionState); assertEquals(String.class, value.getTypeDescriptor().getObjectType()); assertEquals(String.class, value.getTypeDescriptor().getType()); assertEquals("123 is a number", value.getValue()); }
push(new StringLiteral(t.stringValue(), t.startPos, t.endPos, t.stringValue()));
push(new StringLiteral(t.stringValue(), toPos(t), t.stringValue()));
push(new StringLiteral(t.stringValue(), toPos(t), t.stringValue()));