/** * Formats the given ASTNode as an SBML L3 function name and appends the * result to the given StringBuffer. */ void L3FormulaFormatter_formatFunction (StringBuffer_t *sb, const ASTNode_t *node, const L3ParserSettings_t *settings) { ASTNodeType_t type = ASTNode_getType(node); switch (type) { case AST_PLUS: StringBuffer_append(sb, "plus"); break; case AST_TIMES: StringBuffer_append(sb, "times"); break; case AST_MINUS: StringBuffer_append(sb, "minus"); break; case AST_DIVIDE: StringBuffer_append(sb, "divide"); break; case AST_POWER: StringBuffer_append(sb, "pow"); break; case AST_FUNCTION_LN: StringBuffer_append(sb, "ln"); break; default: FormulaFormatter_formatFunction(sb, node); break; } }
/** * Formats the given ASTNode as an SBML L1 token and appends the result to * the given StringBuffer. */ void FormulaFormatter_format (StringBuffer_t *sb, const ASTNode_t *node) { if (sb == NULL) return; if (ASTNode_isOperator(node)) { FormulaFormatter_formatOperator(sb, node); } else if (ASTNode_isFunction(node)) { FormulaFormatter_formatFunction(sb, node); } else if (ASTNode_isInteger(node)) { StringBuffer_appendInt(sb, ASTNode_getInteger(node)); } else if (ASTNode_isRational(node)) { FormulaFormatter_formatRational(sb, node); } else if (ASTNode_isReal(node)) { FormulaFormatter_formatReal(sb, node); } else if ( !ASTNode_isUnknown(node) ) { StringBuffer_append(sb, ASTNode_getName(node)); } }
END_TEST START_TEST (test_FormulaFormatter_accessWithNULL) { // ensure we survive NULL arguments FormulaFormatter_format(NULL, NULL); FormulaFormatter_formatFunction(NULL, NULL); FormulaFormatter_formatOperator(NULL, NULL); FormulaFormatter_formatRational(NULL, NULL); FormulaFormatter_formatReal(NULL, NULL); FormulaFormatter_visit(NULL, NULL, NULL); FormulaFormatter_visitFunction(NULL, NULL, NULL); FormulaFormatter_visitLog10(NULL, NULL, NULL); FormulaFormatter_visitOther(NULL, NULL, NULL); FormulaFormatter_visitSqrt(NULL, NULL, NULL); FormulaFormatter_visitUMinus(NULL, NULL, NULL); fail_unless( FormulaFormatter_isFunction(NULL) == 0 ); fail_unless( FormulaFormatter_isGrouped(NULL, NULL) == 0 ); fail_unless( SBML_formulaToString(NULL) == NULL ); }