Skip to content

Commit

Permalink
C tests: deduplicate some test mains
Browse files Browse the repository at this point in the history
Deduplicate most more complex mains.
  • Loading branch information
TheCount committed Nov 4, 2018
1 parent 99e6bb4 commit 37d7b4a
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 756 deletions.
56 changes: 56 additions & 0 deletions test/C/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,60 @@ test_standard_read
yaep_free_grammar (g);
}

static void
test_complex_parse
(int one_parse, int ambiguous, int print_cost, int recovery_match,
int argc, char **argv)
{
struct grammar *g;
struct yaep_tree_node *root;
int ambiguous_p;

if ((g = yaep_create_grammar ()) == NULL)
{
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
yaep_set_one_parse_flag (g, one_parse);
if (print_cost)
{
yaep_set_cost_flag (g, 1);
}
if (argc > 1)
yaep_set_lookahead_level (g, atoi (argv [1]));
if (argc > 2)
yaep_set_debug_level (g, atoi (argv [2]));
else
yaep_set_debug_level (g, 3);
if (argc > 3)
yaep_set_error_recovery_flag (g, atoi (argv [3]));
if (argc > 4)
yaep_set_one_parse_flag (g, atoi (argv [4]));
if (recovery_match)
{
yaep_set_recovery_match (g, recovery_match);
}
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
exit (1);
}
if (yaep_parse (g, test_read_token, test_syntax_error, test_parse_alloc,
test_parse_free, &root, &ambiguous_p))
{
fprintf (stderr, "yaep parse: %s\n", yaep_error_message (g));
exit (1);
}
if (ambiguous != ambiguous_p)
{
fprintf (stderr, "Grammar should be %sambiguous\n", ambiguous ? "" : "un");
exit (1);
}
if (print_cost)
{
fprintf (stderr, "cost = %d\n", root->val.anode.cost);
}
yaep_free_grammar (g);
}

#endif
33 changes: 1 addition & 32 deletions test/C/test17.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include<stdio.h>
#include <stdlib.h>

#include"common.h"
#include "yaep.h"

static const char *input = "a+a";

Expand All @@ -15,35 +13,6 @@ static const char *description =

main (int argc, char **argv)
{
struct grammar *g;
struct yaep_tree_node *root;
int ambiguous_p;

if ((g = yaep_create_grammar ()) == NULL)
{
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
yaep_set_one_parse_flag (g, 0);
if (argc > 1)
yaep_set_lookahead_level (g, atoi (argv [1]));
if (argc > 2)
yaep_set_debug_level (g, atoi (argv [2]));
else
yaep_set_debug_level (g, 3);
if (argc > 3)
yaep_set_error_recovery_flag (g, atoi (argv [3]));
if (argc > 4)
yaep_set_one_parse_flag (g, atoi (argv [4]));
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
exit (1);
}
if ( yaep_parse( g, test_read_token, test_syntax_error, test_parse_alloc, test_parse_free, &root, &ambiguous_p ) ) {
fprintf (stderr, "yaep parse: %s\n", yaep_error_message (g));
exit (1);
}
yaep_free_grammar (g);
test_complex_parse (0, 0, 0, 0, argc, argv);
exit (0);
}
33 changes: 1 addition & 32 deletions test/C/test28.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include<stdio.h>
#include <stdlib.h>

#include"common.h"
#include "yaep.h"

static const char *input = "a+a*(a*+a)";

Expand All @@ -22,35 +20,6 @@ static const char *description =

main (int argc, char **argv)
{
struct grammar *g;
struct yaep_tree_node *root;
int ambiguous_p;

if ((g = yaep_create_grammar ()) == NULL)
{
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
yaep_set_one_parse_flag (g, 1);
if (argc > 1)
yaep_set_lookahead_level (g, atoi (argv [1]));
if (argc > 2)
yaep_set_debug_level (g, atoi (argv [2]));
else
yaep_set_debug_level (g, 3);
if (argc > 3)
yaep_set_error_recovery_flag (g, atoi (argv [3]));
if (argc > 4)
yaep_set_one_parse_flag (g, atoi (argv [4]));
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
exit (1);
}
if ( yaep_parse( g, test_read_token, test_syntax_error, test_parse_alloc, test_parse_free, &root, &ambiguous_p ) ) {
fprintf (stderr, "yaep parse: %s\n", yaep_error_message (g));
exit (1);
}
yaep_free_grammar (g);
test_complex_parse (1, 0, 0, 0, argc, argv);
exit (0);
}
33 changes: 1 addition & 32 deletions test/C/test29.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include<stdio.h>
#include <stdlib.h>

#include"common.h"
#include "yaep.h"

static const char *input = "a+a*(*a+a)";

Expand All @@ -22,35 +20,6 @@ static const char *description =

main (int argc, char **argv)
{
struct grammar *g;
struct yaep_tree_node *root;
int ambiguous_p;

if ((g = yaep_create_grammar ()) == NULL)
{
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
yaep_set_one_parse_flag (g, 1);
if (argc > 1)
yaep_set_lookahead_level (g, atoi (argv [1]));
if (argc > 2)
yaep_set_debug_level (g, atoi (argv [2]));
else
yaep_set_debug_level (g, 3);
if (argc > 3)
yaep_set_error_recovery_flag (g, atoi (argv [3]));
if (argc > 4)
yaep_set_one_parse_flag (g, atoi (argv [4]));
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
exit (1);
}
if ( yaep_parse( g, test_read_token, test_syntax_error, test_parse_alloc, test_parse_free, &root, &ambiguous_p ) ) {
fprintf (stderr, "yaep parse: %s\n", yaep_error_message (g));
exit (1);
}
yaep_free_grammar (g);
test_complex_parse (1, 0, 0, 0, argc, argv);
exit (0);
}
38 changes: 1 addition & 37 deletions test/C/test30.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include<stdio.h>
#include <stdlib.h>

#include"common.h"
#include "yaep.h"

static const char *input = "a+a*(a*a+a)";

Expand All @@ -17,40 +15,6 @@ static const char *description =

main (int argc, char **argv)
{
struct grammar *g;
struct yaep_tree_node *root;
int ambiguous_p;

if ((g = yaep_create_grammar ()) == NULL)
{
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
yaep_set_one_parse_flag (g, 1);
if (argc > 1)
yaep_set_lookahead_level (g, atoi (argv [1]));
if (argc > 2)
yaep_set_debug_level (g, atoi (argv [2]));
else
yaep_set_debug_level (g, 3);
if (argc > 3)
yaep_set_error_recovery_flag (g, atoi (argv [3]));
if (argc > 4)
yaep_set_one_parse_flag (g, atoi (argv [4]));
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
exit (1);
}
if ( yaep_parse( g, test_read_token, test_syntax_error, test_parse_alloc, test_parse_free, &root, &ambiguous_p ) ) {
fprintf (stderr, "yaep parse: %s\n", yaep_error_message (g));
exit (1);
}
if (!ambiguous_p)
{
fprintf (stderr, "It should be ambigous grammar\n");
exit (1);
}
yaep_free_grammar (g);
test_complex_parse (1, 1, 0, 0, argc, argv);
exit (0);
}
38 changes: 1 addition & 37 deletions test/C/test31.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include<stdio.h>
#include <stdlib.h>

#include"common.h"
#include "yaep.h"

static const char *input = "a+a*(a*a+a)";

Expand All @@ -17,40 +15,6 @@ static const char *description =

main (int argc, char **argv)
{
struct grammar *g;
struct yaep_tree_node *root;
int ambiguous_p;

if ((g = yaep_create_grammar ()) == NULL)
{
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
yaep_set_one_parse_flag (g, 0);
if (argc > 1)
yaep_set_lookahead_level (g, atoi (argv [1]));
if (argc > 2)
yaep_set_debug_level (g, atoi (argv [2]));
else
yaep_set_debug_level (g, 3);
if (argc > 3)
yaep_set_error_recovery_flag (g, atoi (argv [3]));
if (argc > 4)
yaep_set_one_parse_flag (g, atoi (argv [4]));
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
exit (1);
}
if ( yaep_parse( g, test_read_token, test_syntax_error, test_parse_alloc, test_parse_free, &root, &ambiguous_p ) ) {
fprintf (stderr, "yaep parse: %s\n", yaep_error_message (g));
exit (1);
}
if (!ambiguous_p)
{
fprintf (stderr, "It should be ambigous grammar\n");
exit (1);
}
yaep_free_grammar (g);
test_complex_parse (0, 1, 0, 0, argc, argv);
exit (0);
}
38 changes: 1 addition & 37 deletions test/C/test32.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include<stdio.h>
#include <stdlib.h>

#include"common.h"
#include "yaep.h"

static const char *input = "a+a*(*a+a)";

Expand All @@ -18,40 +16,6 @@ static const char *description =

main (int argc, char **argv)
{
struct grammar *g;
struct yaep_tree_node *root;
int ambiguous_p;

if ((g = yaep_create_grammar ()) == NULL)
{
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
yaep_set_one_parse_flag (g, 1);
if (argc > 1)
yaep_set_lookahead_level (g, atoi (argv [1]));
if (argc > 2)
yaep_set_debug_level (g, atoi (argv [2]));
else
yaep_set_debug_level (g, 3);
if (argc > 3)
yaep_set_error_recovery_flag (g, atoi (argv [3]));
if (argc > 4)
yaep_set_one_parse_flag (g, atoi (argv [4]));
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
exit (1);
}
if ( yaep_parse( g, test_read_token, test_syntax_error, test_parse_alloc, test_parse_free, &root, &ambiguous_p ) ) {
fprintf (stderr, "yaep parse: %s\n", yaep_error_message (g));
exit (1);
}
if (!ambiguous_p)
{
fprintf (stderr, "It should be ambigous grammar\n");
exit (1);
}
yaep_free_grammar (g);
test_complex_parse (1, 1, 0, 0, argc, argv);
exit (0);
}
Loading

0 comments on commit 37d7b4a

Please sign in to comment.