Changeset 2247


Ignore:
Timestamp:
Jan 12, 2007, 10:58:24 PM (14 years ago)
Author:
roman
Message:
 
Location:
devel-tools/trunk/eclipse/org.refal.plus.comp.test/src/org/refal/plus/comp/test
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • devel-tools/trunk/eclipse/org.refal.plus.comp.test/src/org/refal/plus/comp/test/FenceAndCutCheckerTest.java

    r2245 r2247  
    11package org.refal.plus.comp.test;
    22
     3import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    35
    46import org.junit.After;
    57import org.junit.Before;
    68import org.junit.Test;
     9import org.refal.plus.comp.FenceAndCutChecker;
     10import org.refal.plus.comp.MsgCode;
     11import org.refal.plus.comp.ast.AstFuncDef;
    712
    813public class FenceAndCutCheckerTest {
     14
     15        private static void checkCutWithoutFence(String input) {
     16                expectMessage(input, MsgCode.CutWithoutAMatchingFence);
     17        }
     18
     19        private static void expectMessage(String input, MsgCode msgCode) {
     20                MsgAccumulator msgAcc = parseAndReturnMessages(input);
     21                assertTrue(msgAcc.messages.size() > 0);
     22                assertEquals(msgCode, msgAcc.messages.get(0).msgCode);
     23        }
     24
     25        private static void expectOK(String input) {
     26                MsgAccumulator msgAcc = parseAndReturnMessages(input);
     27                assertTrue(msgAcc.messages.size() == 0);
     28        }
     29
     30        private static MsgAccumulator parseAndReturnMessages(String input) {
     31                MsgAccumulator msgAcc = new MsgAccumulator();
     32                AstFuncDef astFuncDef = Util.parseAndGetFuncDef(input, msgAcc);
     33                FenceAndCutChecker fcc = new FenceAndCutChecker(msgAcc);
     34                fcc.visit(astFuncDef.body, 0);
     35                return msgAcc;
     36        }
    937
    1038        @Before
     
    1846        @Test
    1947        public void check() {
     48                checkCutWithoutFence("F = \\! ;");
     49                expectOK("F = {\\? \\!;}, \\? \\!;");
     50                expectOK("F = \\? A :: A, \\! X;");
     51                expectOK("F = \\? A :: A, \\! X;");
     52                expectOK("F = A $iter B :: C, D;");
     53                expectOK("F = A : B , C;");
     54                expectOK("F = A, B;");
     55                expectOK("F = #A, B;");
     56                expectOK("F = \\? \\? #A, \\! \\! B;");
     57                expectOK("F = $fail;");
     58                checkCutWithoutFence("F = \\? = \\!;");
     59                checkCutWithoutFence("F $error \\!;");
     60                checkCutWithoutFence("F $trap \\! $with { A , B;};");
     61                expectOK("F = \\? \\{\\!;};");
     62                expectOK("F = A : {B,C;};");
    2063        }
    2164}
  • devel-tools/trunk/eclipse/org.refal.plus.comp.test/src/org/refal/plus/comp/test/ParserTest.java

    r2245 r2247  
    11package org.refal.plus.comp.test;
    22
    3 import org.junit.After;
    4 import org.junit.AfterClass;
    5 import org.junit.Before;
    6 import org.junit.BeforeClass;
    7 import org.junit.Test;
    83import static org.junit.Assert.assertEquals;
    94
     5import org.junit.After;
     6import org.junit.Before;
     7import org.junit.Test;
    108import org.refal.plus.comp.ast.AstImplem;
    119import org.refal.plus.comp.ast.AstInterf;
  • devel-tools/trunk/eclipse/org.refal.plus.comp.test/src/org/refal/plus/comp/test/TestSuite.java

    r2245 r2247  
    1111                ParserTest.class, //
    1212                LexicalEnvironmentTest.class, //
    13                 VariableScopeCheckerTest.class //
     13                VariableScopeCheckerTest.class, //
     14                FenceAndCutCheckerTest.class //
    1415})
    1516public class TestSuite {
  • devel-tools/trunk/eclipse/org.refal.plus.comp.test/src/org/refal/plus/comp/test/Util.java

    r2245 r2247  
    33import static org.junit.Assert.assertEquals;
    44import static org.junit.Assert.assertTrue;
    5 import static org.refal.plus.comp.test.Util.parseAndReturnMessages;
    65
    7 import org.refal.plus.comp.LexicalEnvironment;
    86import org.refal.plus.comp.MsgCode;
    9 import org.refal.plus.comp.VariableScopeChecker;
    10 import org.refal.plus.comp.TkAttributes.VarType;
    117import org.refal.plus.comp.ast.AstFuncDef;
    128import org.refal.plus.comp.ast.AstImplem;
     
    1511
    1612public class Util {
    17 
    18         static MsgAccumulator parseAndReturnMessages(String input) {
    19                 MsgAccumulator msgAcc = new MsgAccumulator();
    20                 AstFuncDef astFuncDef = Util.parseAndGetFuncDef(input, msgAcc);
    21                 VariableScopeChecker vsc = new VariableScopeChecker(msgAcc);
    22                 vsc.visit(astFuncDef.body, new LexicalEnvironment<VarType>(null));
    23                 return msgAcc;
    24         }
    2513
    2614        static AstFuncDef parseAndGetFuncDef(String input,
     
    3422        }
    3523
    36         static void expectMessage(String input, MsgCode msgCode,
    37                         String expectedArg) {
    38                 MsgAccumulator msgAcc = parseAndReturnMessages(input);
     24        static void checkMsg(MsgAccumulator msgAcc, MsgCode msgCode, String expectedArg) {
    3925                assertTrue(msgAcc.messages.size() > 0);
    4026                Message msg = msgAcc.messages.get(0);
     
    4430        }
    4531
    46         static void expectOK(String input) {
    47                 MsgAccumulator msgAcc = parseAndReturnMessages(input);
    48                 assertTrue(msgAcc.messages.size() == 0);
    49         }
    50 
    5132}
  • devel-tools/trunk/eclipse/org.refal.plus.comp.test/src/org/refal/plus/comp/test/VariableScopeCheckerTest.java

    r2245 r2247  
    1010import org.junit.Before;
    1111import org.junit.Test;
     12import org.refal.plus.comp.LexicalEnvironment;
    1213import org.refal.plus.comp.MsgCode;
    1314import org.refal.plus.comp.VariableCollector;
     15import org.refal.plus.comp.VariableScopeChecker;
    1416import org.refal.plus.comp.TkAttributes.VarType;
    1517import org.refal.plus.comp.ast.AstCall;
    1618import org.refal.plus.comp.ast.AstCharSymbol;
    1719import org.refal.plus.comp.ast.AstExp;
     20import org.refal.plus.comp.ast.AstFuncDef;
    1821import org.refal.plus.comp.ast.AstName;
    1922import org.refal.plus.comp.ast.AstNumberSymbol;
     
    2326import org.refal.plus.comp.ast.AstVar;
    2427import org.refal.plus.comp.ast.AstWordSymbol;
    25 
    26 import static org.refal.plus.comp.test.Util.*;
    2728
    2829public class VariableScopeCheckerTest {
     
    3536                expectMessage(input, MsgCode.TwoOccurrencesOfTheVariable_X_HaveDifferentTypes,
    3637                                expectedIndex);
     38        }
     39
     40        private static MsgAccumulator parseAndReturnMessages(String input) {
     41                MsgAccumulator msgAcc = new MsgAccumulator();
     42                AstFuncDef astFuncDef = Util.parseAndGetFuncDef(input, msgAcc);
     43                VariableScopeChecker vsc = new VariableScopeChecker(msgAcc);
     44                vsc.visit(astFuncDef.body, new LexicalEnvironment<VarType>(null));
     45                return msgAcc;
     46        }
     47
     48        private static void expectMessage(String input, MsgCode msgCode,
     49                        String expectedArg) {
     50                MsgAccumulator msgAcc = parseAndReturnMessages(input);
     51                Util.checkMsg(msgAcc, msgCode, expectedArg);
     52        }
     53
     54        private static void expectOK(String input) {
     55                MsgAccumulator msgAcc = parseAndReturnMessages(input);
     56                assertTrue(msgAcc.messages.size() == 0);
    3757        }
    3858
Note: See TracChangeset for help on using the changeset viewer.