01: /*
02: * Copyright 2006, 2007 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.el.tree.impl.ast;
17:
18: import javax.el.ELException;
19:
20: import de.odysseus.el.TestCase;
21:
22: public class AstUnaryTest extends TestCase {
23: AstUnary parseNode(String expression) {
24: return (AstUnary) parse(expression).getRoot().getChild(0);
25: }
26:
27: public void testEval() {
28: assertEquals(true, parseNode("${!false}").eval(null, null));
29: assertEquals(false, parseNode("${!true}").eval(null, null));
30: assertEquals(false, parseNode("${empty 1}").eval(null, null));
31: assertEquals(true, parseNode("${empty null}").eval(null, null));
32: assertEquals(-1l, parseNode("${-1}").eval(null, null));
33: }
34:
35: public void testAppendStructure() {
36: StringBuilder s = new StringBuilder();
37: parseNode("${!1}").appendStructure(s, null);
38: parseNode("${empty 1}").appendStructure(s, null);
39: parseNode("${-1}").appendStructure(s, null);
40: assertEquals("! 1empty 1- 1", s.toString());
41: }
42:
43: public void testIsLiteralText() {
44: assertFalse(parseNode("${-1}").isLiteralText());
45: }
46:
47: public void testIsLeftValue() {
48: assertFalse(parseNode("${-1}").isLeftValue());
49: }
50:
51: public void testGetType() {
52: assertNull(parseNode("${-1}").getType(null, null));
53: }
54:
55: public void testIsReadOnly() {
56: assertTrue(parseNode("${-1}").isReadOnly(null, null));
57: }
58:
59: public void testSetValue() {
60: try {
61: parseNode("${-1}").setValue(null, null, null);
62: fail();
63: } catch (ELException e) {
64: }
65: }
66:
67: public void testGetValue() {
68: assertEquals(Long.valueOf(-1l), parseNode("${-1}").getValue(
69: null, null, null));
70: assertEquals("-1", parseNode("${-1}").getValue(null, null,
71: String.class));
72: }
73: }
|