Skip to content

Commit

Permalink
C tests: deduplicate test_read_token()
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCount committed Nov 2, 2018
1 parent b931e20 commit 8e37c71
Show file tree
Hide file tree
Showing 45 changed files with 70 additions and 776 deletions.
19 changes: 19 additions & 0 deletions test/C/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,23 @@ test_syntax_error (int err_tok_num, void *err_tok_attr,
start_ignored_tok_num);
}

static const char *input;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
static int ntok = 0;

*attr = NULL;
if (input [ntok])
{
return input [ntok++];
}
else
{
return -1;
}
}

#endif
19 changes: 1 addition & 18 deletions test/C/test06.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description =
"\n"
Expand All @@ -47,7 +31,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
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);
Expand Down
19 changes: 1 addition & 18 deletions test/C/test07.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description =
"\n"
Expand All @@ -47,7 +31,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
if (yaep_parse_grammar (g, 0, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
Expand Down
19 changes: 1 addition & 18 deletions test/C/test08.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description =
"\n"
Expand All @@ -47,7 +31,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
Expand Down
19 changes: 1 addition & 18 deletions test/C/test09.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description =
"\n"
Expand All @@ -47,7 +31,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
Expand Down
19 changes: 1 addition & 18 deletions test/C/test10.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description =
"\n"
Expand All @@ -47,7 +31,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
Expand Down
19 changes: 1 addition & 18 deletions test/C/test11.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description =
"\n"
Expand All @@ -47,7 +31,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
Expand Down
19 changes: 1 addition & 18 deletions test/C/test12.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description = "TERM;\n";

Expand All @@ -35,7 +19,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
Expand Down
19 changes: 1 addition & 18 deletions test/C/test13.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description = "TERM ident; ident : ;\n";

Expand All @@ -35,7 +19,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
Expand Down
19 changes: 1 addition & 18 deletions test/C/test14.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description =
"\n"
Expand All @@ -47,7 +31,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
Expand Down
19 changes: 1 addition & 18 deletions test/C/test15.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description =
"\n"
Expand All @@ -47,7 +31,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
Expand Down
19 changes: 1 addition & 18 deletions test/C/test16.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
#include"common.h"
#include "yaep.h"

/* The following variable is the current number of next input
token. */
static int ntok;

/* The following function imported by YAEP (see comments in the interface file). */
static int
test_read_token (void **attr)
{
const char input [] ="a+a*(a*a+a)";

ntok++;
*attr = NULL;
if (ntok < sizeof (input))
return input [ntok - 1];
else
return -1;
}
static const char *input = "a+a*(a*a+a)";

static const char *description =
"\n"
Expand All @@ -46,7 +30,6 @@ main ()
fprintf (stderr, "yaep_create_grammar: No memory\n");
exit (1);
}
ntok = 0;
if (yaep_parse_grammar (g, 1, description) != 0)
{
fprintf (stderr, "%s\n", yaep_error_message (g));
Expand Down
Loading

0 comments on commit 8e37c71

Please sign in to comment.