private void CheckRead(String str, Boolean success, Int32 expected, String message) { Int32 actual = ConstantTest.CheckRead(HexaDecimalConstant.Read, str, success, message); if (success) { Assert.AreEqual(expected, actual, message); } }
private void CheckRead(String str, Boolean success, String expected, String message) { String actual = ConstantTest.CheckRead(StringConstant.Read, str, success, message); if (success) { Assert.AreEqual(expected, actual, message); } }
private void CheckParse(String str, Boolean success, Constant expected, String message) { Literal literal = OperandTest.CheckParse(Literal.Parse, str, success, message); if (success) { Constant actual = literal.Constant; ConstantTest.Check(expected, actual, message); } }
public void Parse() { CheckParse( "12345", ConstantTest.MakeArray(new DecimalConstant(12345)), TokenType.EndOfToken, "10 進定数"); CheckParse( "#ABCD", ConstantTest.MakeArray(new HexaDecimalConstant(0xABCD)), TokenType.EndOfToken, "16 進定数"); CheckParse( "'abc'", ConstantTest.MakeArray(new StringConstant("abc")), TokenType.EndOfToken, "文字定数"); CheckParse( "L001", ConstantTest.MakeArray(new AddressConstant("L001")), TokenType.EndOfToken, "アドレス定数"); CheckParse( "12345,#ABCD,'StrConst',L001", ConstantTest.MakeArray( new DecimalConstant(12345), new HexaDecimalConstant(0xABCD), new StringConstant("StrConst"), new AddressConstant("L001")), TokenType.EndOfToken, "定数の並び"); CheckParse( String.Empty, null, DontCare, "空文字列でオペランドなし => エラー, 1 つ以上の定数が必要"); CheckParse( "123,", null, DontCare, "コンマに続く定数なし => エラー, コンマがあれば続いて定数が必要"); CheckParse( "'abc'123", ConstantTest.MakeArray(new StringConstant("abc")), TokenType.DecimalConstant, "区切りのコンマがない => コンマがなければ、解釈はそこまで"); }
public void ReadOperand() { const Constant[] DontCare = null; CheckReadOperand( "'StrConst',12345,L001,#ABCD", true, ConstantTest.MakeArray( new StringConstant("StrConst"), new DecimalConstant(12345), new AddressConstant("L001"), new HexaDecimalConstant(0xABCD)), "定数の並び"); CheckReadOperand( String.Empty, false, DontCare, "空文字列でオペランドなし => エラー, 1 つ以上の定数が必要"); CheckReadOperand( "; コメント", false, DontCare, "コメントでオペランドなし => エラー, 1 つ以上の定数が必要"); CheckReadOperand( "'abc'123", false, DontCare, "区切りのコンマではなく別の字句要素がある => エラー"); }
internal static void Check(Literal expected, Literal actual, String message) { ConstantTest.Check(expected.Constant, actual.Constant, message); }