public void TestCaseOperatorRegistration() { var tokenizer = new Tokenizer("irrelevant"); var lexer = new Lexer(tokenizer, ExpressionFlowSymbols.Default, StringComparer.OrdinalIgnoreCase); var neutral = new ArithmeticNeutralOperator(TypeConverter); var sum = new ArithmeticSumOperator(TypeConverter); ExpectArgumentNullException("operator", () => lexer.RegisterOperator(null)); Assert.AreEqual(lexer, lexer.RegisterOperator(neutral)); Assert.AreEqual(lexer, lexer.RegisterOperator(sum)); ExpectOperatorAlreadyRegisteredException(neutral.ToString(), () => lexer.RegisterOperator(neutral)); ExpectOperatorAlreadyRegisteredException(sum.ToString(), () => lexer.RegisterOperator(sum)); /* Clashing with specials */ lexer.RegisterSpecial("FALSE", false); var clashingOp1 = new ArithmeticNeutralOperator("FALSE", TypeConverter); var clashingOp2 = new ArithmeticSumOperator("FALSE", TypeConverter); ExpectOperatorAlreadyRegisteredException(clashingOp1.ToString(), () => lexer.RegisterOperator(clashingOp1)); ExpectOperatorAlreadyRegisteredException(clashingOp2.ToString(), () => lexer.RegisterOperator(clashingOp2)); /* Flow */ ExpectOperatorAlreadyRegisteredException("(", () => lexer.RegisterOperator(new ArithmeticNeutralOperator("(", TypeConverter))); lexer.RegisterOperator(new ArithmeticNeutralOperator(")", TypeConverter)); lexer.RegisterOperator(new ArithmeticNeutralOperator(".", TypeConverter)); lexer.RegisterOperator(new ArithmeticNeutralOperator(",", TypeConverter)); lexer.RegisterOperator(new ArithmeticSumOperator("(", TypeConverter)); ExpectOperatorAlreadyRegisteredException(")", () => lexer.RegisterOperator(new ArithmeticSumOperator(")", TypeConverter))); ExpectOperatorAlreadyRegisteredException(".", () => lexer.RegisterOperator(new ArithmeticSumOperator(".", TypeConverter))); ExpectOperatorAlreadyRegisteredException(",", () => lexer.RegisterOperator(new ArithmeticSumOperator(",", TypeConverter))); }
public void TestCaseOperatorRegistration1() { var expression = new Expression(); var unaryOpPlus = new ArithmeticNeutralOperator("+", TypeConverter); var binaryOpPlus = new ArithmeticSumOperator("+", TypeConverter); expression.RegisterOperator(unaryOpPlus); ExpectOperatorAlreadyRegisteredException(unaryOpPlus.ToString(), () => expression.RegisterOperator(unaryOpPlus)); expression.RegisterOperator(binaryOpPlus); ExpectOperatorAlreadyRegisteredException(binaryOpPlus.ToString(), () => expression.RegisterOperator(binaryOpPlus)); }
public void TestCaseOperatorRegistration2() { var expression = new Expression(); var unary1 = new ArithmeticNeutralOperator("(", TypeConverter); var unary2 = new ArithmeticNeutralOperator(")", TypeConverter); var unary3 = new ArithmeticNeutralOperator(".", TypeConverter); var unary4 = new ArithmeticNeutralOperator(",", TypeConverter); var binary1 = new ArithmeticSumOperator("(", TypeConverter); var binary2 = new ArithmeticSumOperator(")", TypeConverter); var binary3 = new ArithmeticSumOperator(".", TypeConverter); var binary4 = new ArithmeticSumOperator(",", TypeConverter); ExpectOperatorAlreadyRegisteredException(unary1.ToString(), () => expression.RegisterOperator(unary1)); ExpectOperatorAlreadyRegisteredException(unary2.ToString(), () => expression.RegisterOperator(unary2)); ExpectOperatorAlreadyRegisteredException(unary3.ToString(), () => expression.RegisterOperator(unary3)); ExpectOperatorAlreadyRegisteredException(unary4.ToString(), () => expression.RegisterOperator(unary4)); ExpectOperatorAlreadyRegisteredException(binary1.ToString(), () => expression.RegisterOperator(binary1)); ExpectOperatorAlreadyRegisteredException(binary2.ToString(), () => expression.RegisterOperator(binary2)); ExpectOperatorAlreadyRegisteredException(binary3.ToString(), () => expression.RegisterOperator(binary3)); ExpectOperatorAlreadyRegisteredException(binary4.ToString(), () => expression.RegisterOperator(binary4)); }