001package csheets.core.formula.lang;
002
003import static org.junit.Assert.*;
004
005import org.junit.*;
006
007import csheets.core.*;
008
009/**
010 * Class that will test the eval function
011 * 
012 * @author Andre
013 * 
014 */
015public class EvalTest {
016
017        private static Workbook workbook;
018        private static Spreadsheet sheetApp;
019
020        /**
021         * Create a new workbook for the program
022         * 
023         * @throws Exception
024         *             any Exception can occur
025         */
026        @BeforeClass
027        public static void setUpBeforeClass() throws Exception {
028                /** create a new instance of workbook */
029                workbook = new Workbook(3);
030
031                /** Change to the first spreadsheet */
032                sheetApp = workbook.getSpreadsheet(0);
033        }
034
035        /**
036         * Test the get identifier
037         */
038        @Test
039        public void testGetIdentifier() {
040                Eval ev = new Eval();
041                assertEquals("EVAL", ev.getIdentifier());
042        }
043
044        /**
045         * Test the apply to
046         */
047        @Test
048        public void testApplyTo() {
049                try {
050                        Cell cellOri = sheetApp.getCell(new Address(0, 0));
051                        Cell cellFim = sheetApp.getCell(new Address(0, 1));
052                        cellFim.setContent("");
053                        cellOri.setContent("#eval(\"#a2:=2\")");
054                        Value resulted = cellOri.getValue();
055                        assertEquals("#a2:=2", resulted.toString());
056
057                } catch (Exception e) {
058                        e.printStackTrace();
059                        fail("Exception error!");
060                }
061
062        }
063
064        /**
065         * Test if is Variable arguments
066         */
067        @Test
068        public void testIsVarArg() {
069                Eval ev = new Eval();
070                assertTrue(ev.isVarArg());
071        }
072
073}