Exemplo n.º 1
0
/* Given                            should become
 *            OperatorToken *                 OperatorToken *
 *            --------------                  --------------
 * type:      TOKEN_OPERATOR_TYPE             TOKEN_OPERATOR_TYPE
 * symbol:       '/='                          '/='
 * arity:         0                           INFIX
 * assoc:         0                           RIGHT_TO_LEFT
 * precedence:    0                           1
 *
 */
void test_extendDoubleCharacterOperator_given_divideEqual_should_give_correct_attributes(void)
{
  OperatorToken *op = (OperatorToken*)createOperatorToken("/=");
  Attributes *attr = &operatorAttributesTable[(int)*(op->symbol)];
  op =(OperatorToken *)attr->extend((Token *)op, attr);

  TEST_ASSERT_EQUAL_ATTRIBUTE_OPERATOR(INFIX, RIGHT_TO_LEFT, 1, "/=", op);
}
Exemplo n.º 2
0
/* Given                            should become
 *            OperatorToken *                 OperatorToken *
 *            --------------                  --------------
 * type:      TOKEN_OPERATOR_TYPE             TOKEN_OPERATOR_TYPE
 * symbol:       '('                          '('
 * arity:         0                           PREFIX
 * assoc:         0                           LEFT_TO_RIGHT
 * precedence:    0                           13
 *
 */
void test_extendSingleCharacterOperator_given_openBracket_should_give_correct_attributes(void)
{
  OperatorToken *op = (OperatorToken*)createOperatorToken("(");
  Attributes *attr = &operatorAttributesTable[(int)*(op->symbol)];
  op =(OperatorToken *)attr->extend((Token *)op, attr);

  TEST_ASSERT_EQUAL_ATTRIBUTE_OPERATOR(PREFIX, LEFT_TO_RIGHT, 13, "(", op);
}
Exemplo n.º 3
0
/* Given                            should become
 *            OperatorToken *                 OperatorToken *
 *            --------------                  --------------
 * type:      TOKEN_OPERATOR_TYPE             TOKEN_OPERATOR_TYPE
 * symbol:       '<'                          '<'
 * arity:         0                           INFIX
 * assoc:         0                           LEFT_TO_RIGHT
 * precedence:    0                           8
 *
 */
void test_extendQuadrupleCharacterOperator_given_lessThan_should_give_correct_attributes(void)
{
  OperatorToken *op = (OperatorToken*)createOperatorToken("<");
  Attributes *attr = &operatorAttributesTable[(int)*(op->symbol)];
  op =(OperatorToken *)attr->extend((Token *)op, attr);

  TEST_ASSERT_EQUAL_ATTRIBUTE_OPERATOR(INFIX, LEFT_TO_RIGHT, 8, "<", op);
}
Exemplo n.º 4
0
/* Given                            should become
 *            OperatorToken *                 OperatorToken *
 *            --------------                  --------------
 * type:      TOKEN_OPERATOR_TYPE             TOKEN_OPERATOR_TYPE
 * symbol:       '!'                          '!'
 * arity:         0                           PREFIX
 * assoc:         0                           RIGHT_TO_LEFT
 * precedence:    0                           12
 *
 */
void test__getToken_given_logicalNegation_then_called_table_should_give_correct_attributes(void)
{
  OperatorToken *opPlus = (OperatorToken*)createOperatorToken("!");
  getToken_ExpectAndReturn((Token *)opPlus);

  opPlus = (OperatorToken *)_getToken();

  TEST_ASSERT_EQUAL_ATTRIBUTE_OPERATOR(PREFIX, RIGHT_TO_LEFT, 12, "!", opPlus);
}
Exemplo n.º 5
0
/* Given                            should become
 *            OperatorToken *                 OperatorToken *
 *            --------------                  --------------
 * type:      TOKEN_OPERATOR_TYPE             TOKEN_OPERATOR_TYPE
 * symbol:       '^'                          '^'
 * arity:         0                           INFIX
 * assoc:         0                           LEFT_TO_RIGHT
 * precedence:    0                           5
 *
 */
void test__getToken_given_bitwiseXor_then_called_table_should_give_correct_attributes(void)
{
  OperatorToken *opPlus = (OperatorToken*)createOperatorToken("^");
  getToken_ExpectAndReturn((Token *)opPlus);

  opPlus = (OperatorToken *)_getToken();

  TEST_ASSERT_EQUAL_ATTRIBUTE_OPERATOR(INFIX, LEFT_TO_RIGHT, 5, "^", opPlus);
}
Exemplo n.º 6
0
/* Given                            should become
 *            OperatorToken *                 OperatorToken *
 *            --------------                  --------------
 * type:      TOKEN_OPERATOR_TYPE             TOKEN_OPERATOR_TYPE
 * symbol:       '('                          '('
 * arity:         0                           PREFIX
 * assoc:         0                           LEFT_TO_RIGHT
 * precedence:    0                           13
 *
 */
void test_tryConvertToPrefix_given_openBracket_should_convert_to_prefix_successfully(void)
{
  OperatorToken *op = (OperatorToken*)createOperatorToken("(");

  OperatorToken **opP = malloc(sizeof(OperatorToken));
  opP = &op;
  tryConvertToPrefix((Token ***)&opP);

  TEST_ASSERT_EQUAL_ATTRIBUTE_OPERATOR(PREFIX, LEFT_TO_RIGHT, 13, "(", op);
}
Exemplo n.º 7
0
/* Given                            should become
 *            OperatorToken *                 OperatorToken *
 *            --------------                  --------------
 * type:      TOKEN_OPERATOR_TYPE             TOKEN_OPERATOR_TYPE
 * symbol:       '!'                          '!'
 * arity:         0                           PREFIX
 * assoc:         0                           RIGHT_TO_LEFT
 * precedence:    0                           12
 *
 */
void test_tryConvertToPrefix_given_logicalNOT_should_convert_to_prefix_successfully(void)
{
  OperatorToken *op = (OperatorToken*)createOperatorToken("!");

  OperatorToken **opP = malloc(sizeof(OperatorToken));
  opP = &op;
  tryConvertToPrefix((Token ***)&opP);

  TEST_ASSERT_EQUAL_ATTRIBUTE_OPERATOR(PREFIX, RIGHT_TO_LEFT, 12, "!", op);
}
Exemplo n.º 8
0
LogicToken*	LogicTokenFactory::createToken(const char *token, bool isUnary) {
	LogicToken *tokenobj = isUnary ? createUnaryOperatorToken(token) : createOperatorToken(token) ;

	if ( *token == '(' )
		tokenobj = new LogicTokenParenthesisOpen();
	
	if ( *token == ')' )
		tokenobj = new LogicTokenParenthesisClose();
	
	if ( !tokenobj ) {
		tokenobj = createVariableToken( token );
	}
	
	return tokenobj;
}
Exemplo n.º 9
0
/* Given                            should catch the error.
 *            OperatorToken *
 *            --------------
 * type:      TOKEN_OPERATOR_TYPE
 * symbol:       "~="
 * arity:         0
 * assoc:         0
 * precedence:    0
 *
 */
void test_extendSingleCharacterOperator_given_illegal_symbol_should_catch_the_error(void)
{
  OperatorToken *op = (OperatorToken*)createOperatorToken("~=");
  Attributes *attr = &operatorAttributesTable[(int)*(op->symbol)];

  ErrorObject *err;
  Try
  {
    op = (OperatorToken *)attr->extend((Token *)op, attr);
    TEST_FAIL_MESSAGE("Expected to catch Error here, but didn't.\n");
  }
  Catch(err)
  {
    TEST_ASSERT_EQUAL_STRING(("%s is an undefined operator.", ((OperatorToken *)op)->symbol), \
                               err->errorMsg);
    TEST_ASSERT_EQUAL(UNDEFINED_OPERATOR, err->errorCode);
    freeError(err);
  }
}
Exemplo n.º 10
0
/* Given                            should catch the error.
 *            OperatorToken *
 *            --------------
 * type:      TOKEN_OPERATOR_TYPE
 * symbol:       '+++'
 * arity:         0
 * assoc:         0
 * precedence:    0
 *
 */
void test_tryConvertToPrefix_given_plus_plus_plus_should_fail_to_convert_to_prefix(void)
{
  OperatorToken *op = (OperatorToken*)createOperatorToken("+++");
  Attributes *attr = &operatorAttributesTable[(int)*(op->symbol)];
  OperatorToken **opP = malloc(sizeof(OperatorToken));
  opP = &op;
  ErrorObject *err;
  Try
  {
    tryConvertToPrefix((Token ***)&opP);
    TEST_FAIL_MESSAGE("Expected to catch Error here, but didn't.\n");
  }
  Catch(err)
  {
    TEST_ASSERT_EQUAL_STRING("Hey! This symbol is not belong to prefix type.", \
                               err->errorMsg);
    TEST_ASSERT_EQUAL(FAIL_TO_CONVERT_TO_PREFIX, err->errorCode);

    freeError(err);
  }
}