Skip to content

Commit

Permalink
C tests: deduplicate some test mains
Browse files Browse the repository at this point in the history
Deduplicate standard yaep_read_grammar() type tests.
  • Loading branch information
TheCount committed Nov 3, 2018
1 parent a649673 commit 99e6bb4
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 147 deletions.
29 changes: 29 additions & 0 deletions test/C/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,33 @@ test_standard_parse (void)
yaep_free_grammar (g);
}

static void
test_standard_read
(const char *(*read_terminal) (int *),
const char *(*read_rule) (const char ***, const char **, int *, int **))
{
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);
}
if (yaep_read_grammar (g, 1, read_terminal, read_rule) != 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);
}

#endif
22 changes: 1 addition & 21 deletions test/C/test21.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"

/* The following variable is the current number of next input grammar
terminal. */
Expand Down Expand Up @@ -69,24 +67,6 @@ static const char *input = "a+a*(a*a+a)";

main ()
{
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);
}
if (yaep_read_grammar (g, 1, read_terminal, read_rule) != 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_standard_read (read_terminal, read_rule);
exit (0);
}
22 changes: 1 addition & 21 deletions test/C/test22.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"

/* The following variable is the current number of next input grammar
terminal. */
Expand Down Expand Up @@ -68,24 +66,6 @@ static const char *input = "a+a*(a*a+a)";

main ()
{
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);
}
if (yaep_read_grammar (g, 1, read_terminal, read_rule) != 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_standard_read (read_terminal, read_rule);
exit (0);
}
22 changes: 1 addition & 21 deletions test/C/test23.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"

/* The following variable is the current number of next input grammar
terminal. */
Expand Down Expand Up @@ -69,24 +67,6 @@ static const char *input = "a+a*(a*a+a)";

main ()
{
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);
}
if (yaep_read_grammar (g, 1, read_terminal, read_rule) != 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_standard_read (read_terminal, read_rule);
exit (0);
}
22 changes: 1 addition & 21 deletions test/C/test24.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"

/* The following variable is the current number of next input grammar
terminal. */
Expand Down Expand Up @@ -69,24 +67,6 @@ static const char *input = "a+a*(a*a+a)";

main ()
{
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);
}
if (yaep_read_grammar (g, 1, read_terminal, read_rule) != 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_standard_read (read_terminal, read_rule);
exit (0);
}
22 changes: 1 addition & 21 deletions test/C/test25.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"

/* The following variable is the current number of next input grammar
terminal. */
Expand Down Expand Up @@ -68,24 +66,6 @@ static const char *input = "a+a*(a*a+a)";

main ()
{
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);
}
if (yaep_read_grammar (g, 1, read_terminal, read_rule) != 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_standard_read (read_terminal, read_rule);
exit (0);
}
22 changes: 1 addition & 21 deletions test/C/test26.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"

/* The following variable is the current number of next input grammar
terminal. */
Expand Down Expand Up @@ -68,24 +66,6 @@ static const char *input = "a+a*(a*a+a)";

main ()
{
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);
}
if (yaep_read_grammar (g, 1, read_terminal, read_rule) != 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_standard_read (read_terminal, read_rule);
exit (0);
}
22 changes: 1 addition & 21 deletions test/C/test44.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"

/* The following variable is the current number of next input grammar
terminal. */
Expand Down Expand Up @@ -68,24 +66,6 @@ static const char *input = "a+a*(a*a+a)";

main ()
{
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);
}
if (yaep_read_grammar (g, 1, read_terminal, read_rule) != 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_standard_read (read_terminal, read_rule);
exit (0);
}

0 comments on commit 99e6bb4

Please sign in to comment.