mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Tighten the grammar around quoted strings. Test-case fixes.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13717 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
f39f66e858
commit
3233622edc
@ -13,6 +13,10 @@
|
||||
|
||||
2006-03-30 Joshua Sled <jsled@asynchronous.org>
|
||||
|
||||
* src/calculation/expression_parser.c (primary_exp):
|
||||
* src/app-utils/test/test-exp-parser.c (test_parser): Tighten the
|
||||
grammar around quoted strings. Test-case fixes.
|
||||
|
||||
* src/calculation/expression_parser.c (primary_exp):
|
||||
* src/app-utils/test/test-exp-parser.c (test_parser): Add basic
|
||||
validation and test-cases for invalid expressions. Bugs#308554,
|
||||
|
@ -39,6 +39,7 @@ _add_pass_test (const char *test_name, const char *exp, gnc_numeric result, char
|
||||
tests = g_list_append (tests, node);
|
||||
}
|
||||
|
||||
|
||||
#define add_fail_test(n,e,o) _add_fail_test((n), (e), (o), __FILE__, __LINE__)
|
||||
|
||||
static void
|
||||
@ -134,6 +135,7 @@ test_parser (void)
|
||||
add_fail_test ("bad expression", "ç 1", 0);
|
||||
add_fail_test ("bad expression", "1 asdf", 6);
|
||||
add_fail_test ("bad expression", "asdf 1", 6);
|
||||
add_fail_test ("bad expression", "asdf jkl", 8);
|
||||
add_fail_test ("bad expression", " (5 + 23)/ ", 14);
|
||||
add_fail_test ("bad expression", " ((((5 + 23)/ ", 17);
|
||||
add_fail_test ("divide by zero", " 4 / (1 - 1)", -1);
|
||||
@ -160,7 +162,7 @@ test_parser (void)
|
||||
"- 42.72 + 13.32 + 15.48 + 23.4 + 115.4",
|
||||
gnc_numeric_create(35897, 100) );
|
||||
|
||||
// This must be defined for the function-parsing to work.
|
||||
/* This must be defined for the function-parsing to work. */
|
||||
scm_c_eval_string("(define (gnc:error->string tag args) (define (write-error port) (if (and (list? args) (not (null? args))) (let ((func (car args))) (if func (begin (display \"Function: \" port) (display func port) (display \", \" port) (display tag port) (display \"\n\n\" port))))) (false-if-exception (apply display-error (fluid-ref the-last-stack) port args)) (display-backtrace (fluid-ref the-last-stack) port) (force-output port)) (false-if-exception (call-with-output-string write-error)))");
|
||||
|
||||
scm_c_eval_string( "(define (gnc:plus a b) (+ a b))" );
|
||||
@ -193,8 +195,7 @@ test_parser (void)
|
||||
add_pass_test( "test_str( \"two\" : 2 )", NULL, gnc_numeric_create( 4, 1 ) );
|
||||
add_fail_test( "test_str( 3 : \"three\" )", NULL, 23 );
|
||||
add_pass_test( "test_str( \"asdf\" : 1 )", NULL, gnc_numeric_create( 1, 1 ) );
|
||||
// This used to work before the 334811, 308554 fixes... :/
|
||||
//add_fail_test( "\"asdf\" + 0", NULL, 0 );
|
||||
add_fail_test("\"asdf\" + 0", NULL, 8);
|
||||
|
||||
scm_c_eval_string( "(define (gnc:blindreturn val) val)" );
|
||||
add_pass_test( "blindreturn( 123.1 )", NULL, gnc_numeric_create( 1231, 10 ) );
|
||||
|
@ -262,7 +262,7 @@
|
||||
* After parsing the above expressions the variables nni, jk, tyh and
|
||||
* tgh would all be defined.
|
||||
*
|
||||
* Functiosn are invoked with expressions of the format
|
||||
* Functions are invoked with expressions of the format
|
||||
*
|
||||
* [_a-zA-Z]( <argument_0> : <argument_1> : ... : <argument_n> )
|
||||
*
|
||||
@ -1226,9 +1226,13 @@ primary_exp (parser_env_ptr pe)
|
||||
rslt = get_named_var (pe);
|
||||
break;
|
||||
case STR_TOKEN:
|
||||
|
||||
if (check_expression_grammar_error(pe))
|
||||
if (!(pe->Token == ')'
|
||||
|| pe->Token == ARG_TOKEN))
|
||||
{
|
||||
add_token(pe, EOS);
|
||||
pe->error_code = EXPRESSION_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
rslt = get_unnamed_var( pe );
|
||||
rslt->type = VST_STRING;
|
||||
|
Loading…
Reference in New Issue
Block a user