Debian Codegraph @

src/test/java/org/apache/felix/gogo/runtime/TestParser3.java

raw
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.felix.gogo.runtime;
20
21 import junit.framework.TestCase;
22
23 import java.io.EOFException;
24
25 /*
26 * Test features of the new parser/tokenizer, many of which are not supported
27 * by the original parser.
28 */
29 public class TestParser3 extends TestCase
30 {
31 public void testArithmetic() throws Exception
32 {
33 Context c = new Context();
34 c.addCommand("echo", this);
35
36 assertEquals("10d", c.execute("echo %(2*(3+2))d"));
37 assertEquals(3l, c.execute("%(1+2)"));
38
39 c.set("a", 2l);
40 assertEquals(3l, c.execute("%(a+=1)"));
41 assertEquals(3l, c.get("a"));
42 }
43
44 public CharSequence echo(Object args[])
45 {
46 if (args == null)
47 {
48 return "null args!";
49 }
50
51 StringBuilder sb = new StringBuilder();
52 for (Object arg : args)
53 {
54 if (sb.length() > 0)
55 sb.append(' ');
56 sb.append(String.valueOf(arg));
57 }
58 return sb.toString();
59 }
60
61 }