public void ToStringTest()
        {
            R1R2Operand target = R1R2Operand.MakeForUnitTest(RegisterOperandTest.GR2, RegisterOperandTest.GR7);
            String      actual = target.ToString();

            Assert.AreEqual("GR2,GR7", actual, "GR2,GR7 => 'GR2,GR7'");
        }
        public void Parse()
        {
            const MachineInstructionOperand DontCare = null;

            CheckParse(
                "GR0,#ABCD,GR1", true,
                RAdrXOperand.MakeForUnitTest(
                    RAdrXOpcode,
                    RegisterOperandTest.GR0,
                    AdrXOperand.MakeForUnitTest(new HexaDecimalConstant(0xABCD), RegisterOperandTest.GR1)),
                "r,adr,x の場合");
            CheckParse(
                "GR0,GR1", true,
                R1R2Operand.MakeForUnitTest(
                    R1R2Opcode, RegisterOperandTest.GR0, RegisterOperandTest.GR1),
                "r1,r2 の場合");

            CheckParse(
                "NoSuchRegister,GR0", false, DontCare,
                "最初のオペランドがレジスタでない場合 => 例外");
            CheckParse(
                "GR0#GR1", false, DontCare,
                "区切りが ',' でない場合 => 例外、'GR#GR1' は項目の区切りまでラベルとして読み込まれる");
            CheckParse(
                "GR1,#CDEF,GR0", false, DontCare,
                "x に GR0 は使えない => 例外");
            CheckParse(
                "GR0,'abc'", false, DontCare,
                "2 つめのオペランドがレジスタでもアドレスでもない場合 => 例外");
        }
        private void CheckParse(String str, Boolean success, R1R2Operand expected, String message)
        {
            R1R2Operand actual = OperandTest.CheckParse(
                (lexer) => R1R2Operand.Parse(lexer, Opcode), str, success, message);

            if (success)
            {
                MachineInstructionOperandTest.Check(expected, actual, Check, message);
            }
        }
Beispiel #4
0
 public void TestInitialize()
 {
     m_GR1_GR2      = R1R2Operand.MakeForUnitTest(RegisterOperandTest.GR1, RegisterOperandTest.GR2);
     m_GR3_1111_GR4 = RAdrXOperand.MakeForUnitTest(
         RegisterOperandTest.GR3,
         AdrXOperand.MakeForUnitTest(new DecimalConstant(1111), RegisterOperandTest.GR4));
     m_GR3_Eq1234_GR4 = RAdrXOperand.MakeForUnitTest(
         RegisterOperandTest.GR3,
         AdrXOperand.MakeForUnitTest(
             Literal.MakeForUnitTest(new DecimalConstant(1234)), RegisterOperandTest.GR4));
     m_GR5_2222 = RAdrXOperand.MakeForUnitTest(
         RegisterOperandTest.GR5,
         AdrXOperand.MakeForUnitTest(new DecimalConstant(2222), null));
     m_3333_GR6  = AdrXOperand.MakeForUnitTest(new DecimalConstant(3333), RegisterOperandTest.GR6);
     m_EqSTR_GR6 = AdrXOperand.MakeForUnitTest(
         Literal.MakeForUnitTest(new StringConstant("STR")), RegisterOperandTest.GR6);
     m_4444      = AdrXOperand.MakeForUnitTest(new DecimalConstant(4444), null);
     m_GR7       = RegisterOperandTest.GR7;
     m_NoOperand = NoOperand.MakeForUnitTest();
 }
        public void Parse()
        {
            const R1R2Operand DontCare = null;

            CheckParse(
                "GR3,GR5", true,
                R1R2Operand.MakeForUnitTest(Opcode, RegisterOperandTest.GR3, RegisterOperandTest.GR5),
                "r1,r2 => OK");

            CheckParse(
                "GRZ,GR1", false,
                DontCare,
                "最初がレジスタ名でない => 例外");
            CheckParse(
                "GR3@GR1", false,
                DontCare,
                "レジスタ名の後が ',' でない => 例外");
            CheckParse(
                "GR3,1111", false,
                DontCare,
                "レジスタ名と ',' の後がレジスタ名でない => 例外");
        }
 internal static void Check(R1R2Operand expected, R1R2Operand actual, String message)
 {
     RegisterOperandTest.Check(expected.R1, actual.R1, "R1: " + message);
     RegisterOperandTest.Check(expected.R2, actual.R2, "R2: " + message);
 }