1 ////////////////////////////////////////////////////////////////////////////////
2 // MillScript: an Open Spice interpreter and batch website creation tool
3 // Copyright (C) 2005 Kevin Rogers
4 //
5 // This file is part of MillScript.
6 //
7 // MillScript is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 2 of the License, or (at your option)
10 // any later version.
11 //
12 // MillScript is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 // more details.
16 //
17 // You should have received a copy of the GNU General Public License along with
18 // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19 // Place, Suite 330, Boston, MA 02111-1307 USA
20 ////////////////////////////////////////////////////////////////////////////////
21 package org.millscript.millscript.syntax;
22
23 import org.millscript.millscript.expr.ConstantExpr;
24 import org.millscript.millscript.expr.Expr;
25
26 /**
27 * @
28 */
29 public class ArithSyntaxTest extends AbstractSyntaxTestCase {
30
31 /**
32 * Constructor for ArithSyntaxTest.
33 * @param arg0
34 */
35 public ArithSyntaxTest(String arg0) {
36 super(arg0);
37 }
38
39 /**
40 * Simple addition tests
41 */
42 public void testAdd() {
43 final Parser p = getStringParser( "2 + 5" );
44 final Expr e = p.readExpr();
45 // Both number are constants so we should get a compile time constant
46 // value back
47 assertTrue( e instanceof ConstantExpr );
48 assertEquals( new Integer( 7 ), ((ConstantExpr) e).getValue() );
49 }
50
51 /**
52 * Simple subtraction tests
53 */
54 public void testSub() {
55 final Parser p = getStringParser( "7 - 6" );
56 final Expr e = p.readExpr();
57 // Both number are constants so we should get a compile time constant
58 // value back
59 assertTrue( e instanceof ConstantExpr );
60 assertEquals( new Integer( 1 ), ((ConstantExpr) e).getValue() );
61 }
62
63 /**
64 * Simple multiplication tests
65 */
66 public void testMultiplication() {
67 final Parser p = getStringParser( "4 * 6" );
68 final Expr e = p.readExpr();
69 // Both number are constants so we should get a compile time constant
70 // value back
71 assertTrue( e instanceof ConstantExpr );
72 assertEquals( new Integer( 24 ), ((ConstantExpr) e).getValue() );
73 }
74
75 /**
76 * Simple div tests
77 */
78 public void testDiv() {
79 final Parser p = getStringParser( "9 div 2" );
80 final Expr e = p.readExpr();
81 // Both number are constants so we should get a compile time constant
82 // value back
83 assertTrue( e instanceof ConstantExpr );
84 assertEquals( new Integer( 4 ), ((ConstantExpr) e).getValue() );
85 }
86
87 /**
88 * Simple mod tests
89 */
90 public void testMod() {
91 final Parser p = getStringParser( "9 mod 2" );
92 final Expr e = p.readExpr();
93 // Both number are constants so we should get a compile time constant
94 // value back
95 assertTrue( e instanceof ConstantExpr );
96 assertEquals( new Integer( 1 ), ((ConstantExpr) e).getValue() );
97 }
98
99 }