tests/indent: add 11 test cases, demonstrate 8 bugs

This commit is contained in:
rillig 2021-03-06 19:30:44 +00:00
parent adaf54dac0
commit f4551e581c
21 changed files with 352 additions and 42 deletions

View File

@ -1,4 +1,6 @@
/* $NetBSD: opt--version.0,v 1.1 2021/03/06 17:56:33 rillig Exp $ */
/* $NetBSD: opt--version.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
When the option '--version' is given, any other options are ignored.
Therefore the source file, if given, can contain arbitrary text that
even might generate syntax errors when given to a C compiler.

View File

@ -1,4 +1,19 @@
/* $NetBSD: opt-bacc.0,v 1.1 2021/03/06 17:56:33 rillig Exp $ */
/* $NetBSD: opt-bacc.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
int a;
#if 0 /* FIXME: need blank line above */
int b;
#endif /* FIXME: need blank line below */
int c;
int space_a;
#if 0 /* FIXME: need blank line above */
int space_b; /* FIXME: need no blank line above */
#endif
int space_c;

View File

@ -1,4 +1,17 @@
/* $NetBSD: opt-bacc.0.stdout,v 1.1 2021/03/06 17:56:33 rillig Exp $ */
/* $NetBSD: opt-bacc.0.stdout,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
int a;
#if 0 /* FIXME: need blank line above */
int b;
#endif /* FIXME: need blank line below */
int c;
int space_a;
#if 0 /* FIXME: need blank line above */
int space_b; /* FIXME: need no blank line above */
#endif
int space_c;

View File

@ -1,4 +1,18 @@
/* $NetBSD: opt-bad.0,v 1.1 2021/03/06 17:56:33 rillig Exp $ */
/* $NetBSD: opt-bad.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
/*
* The option -bad only affects declarations of local variables. It does not
* affect file-scoped declarations or definitions.
*/
int global_variable;
void function_declaration(void);
#if 0
#endif
void function_definition(void) {
int local_variable;
function_call();
int local_variable_after_statement;
function_call();
}

View File

@ -1,4 +1,22 @@
/* $NetBSD: opt-bad.0.stdout,v 1.1 2021/03/06 17:56:33 rillig Exp $ */
/* $NetBSD: opt-bad.0.stdout,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
/*
* The option -bad only affects declarations of local variables. It does not
* affect file-scoped declarations or definitions.
*/
int global_variable;
void function_declaration(void);
#if 0
#endif
void
function_definition(void)
{
int local_variable;
function_call();
int local_variable_after_statement;
function_call();
}

View File

@ -1,4 +1,33 @@
/* $NetBSD: opt-badp.0,v 1.1 2021/03/06 17:56:33 rillig Exp $ */
/* $NetBSD: opt-badp.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
static void
no_declarations(void)
{
action();
}
static void
declarations_without_blank_line(void)
{
int local_variable;
action(); /* FIXME: need empty line above */
}
static void
declaration_with_blank_line(void)
{
int local_variable;
action();
}
static void
declaration_with_several_blank_lines(void)
{
int local_variable;
action();
}

View File

@ -1,4 +1,34 @@
/* $NetBSD: opt-badp.0.stdout,v 1.1 2021/03/06 17:56:33 rillig Exp $ */
/* $NetBSD: opt-badp.0.stdout,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
static void
no_declarations(void)
{
action();
}
static void
declarations_without_blank_line(void)
{
int local_variable;
action(); /* FIXME: need empty line above */
}
static void
declaration_with_blank_line(void)
{
int local_variable;
action();
}
static void
declaration_with_several_blank_lines(void)
{
int local_variable;
action();
}

View File

@ -1,4 +1,22 @@
/* $NetBSD: opt-bap.0,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-bap.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
static void one_liner(void) { /* FIXME: needs empty line below */ }
static void several_lines(void) {
action();
/* FIXME: needs empty line below */
}
int main(void){/* FIXME: needs empty line below */}
int global_variable;
void already_has_blank_line_below(void)
{
}
void has_several_blank_lines_below(void)
{
}
int the_end;

View File

@ -1,4 +1,32 @@
/* $NetBSD: opt-bap.0.stdout,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-bap.0.stdout,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
static void
one_liner(void)
{ /* FIXME: needs empty line below */
}
static void
several_lines(void)
{
action();
/* FIXME: needs empty line below */
}
int
main(void)
{ /* FIXME: needs empty line below */
}
int global_variable;
void
already_has_blank_line_below(void)
{
}
void
has_several_blank_lines_below(void)
{
}
int the_end;

View File

@ -1,4 +1,26 @@
/* $NetBSD: opt-bbb.0,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-bbb.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
/*
* This is a block comment.
*/
/* This is not a block comment since it is single-line. */
/*
* This is a second block comment.
*/
/* This is not a block comment. */
/*
* Documentation of global_variable.
*/
int global_variable;
/*
* Documentation of function_declaration.
*/
void function_declaration(void);
/*
* Documentation of function_definition.
*/
void
function_definition(void)
{
}

View File

@ -1,4 +1,30 @@
/* $NetBSD: opt-bbb.0.stdout,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-bbb.0.stdout,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
/*
* This is a block comment.
*/
/* This is not a block comment since it is single-line. */
/*
* This is a second block comment.
*/
/* This is not a block comment. */
/*
* Documentation of global_variable.
*/
int global_variable;
/*
* Documentation of function_declaration.
*/
void function_declaration(void);
/*
* Documentation of function_definition.
*/
void
function_definition(void)
{
}

View File

@ -1,4 +1,5 @@
/* $NetBSD: opt-bc.0,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-bc.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
int a,b,c;
void function_declaration(int a,int b,int c);

View File

@ -1,4 +1,7 @@
/* $NetBSD: opt-bc.0.stdout,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-bc.0.stdout,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
int a,
b,
c;
void function_declaration(int a, int b, int c);

View File

@ -1,4 +1,15 @@
/* $NetBSD: opt-bl.0,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-bl.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
void
example(int n)
{
/*
* XXX: The '} else' looks strange in this style since the 'else' is
* not at the left margin of the code.
*/
if (n > 99) { print("large"); }
else if (n > 9) { print("double-digit"); }
else if (n > 0) print("positive");
else { print("negative"); }
}

View File

@ -1,4 +1,23 @@
/* $NetBSD: opt-bl.0.stdout,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-bl.0.stdout,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
void
example(int n)
{
/*
* XXX: The '} else' looks strange in this style since the 'else' is
* not at the left margin of the code.
*/
if (n > 99)
{
print("large");
} else if (n > 9)
{
print("double-digit");
} else if (n > 0)
print("positive");
else
{
print("negative");
}
}

View File

@ -1,4 +1,11 @@
/* $NetBSD: opt-br.0,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-br.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
void
example(int n)
{
if (n > 99) { print("large"); }
else if (n > 9) { print("double-digit"); }
else if (n > 0) print("positive");
else { print("negative"); }
}

View File

@ -1,4 +1,16 @@
/* $NetBSD: opt-br.0.stdout,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-br.0.stdout,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
void
example(int n)
{
if (n > 99) {
print("large");
} else if (n > 9) {
print("double-digit");
} else if (n > 0)
print("positive");
else {
print("negative");
}
}

View File

@ -1,4 +1,17 @@
/* $NetBSD: opt-bs.0,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-bs.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
void
example(int i)
{
print(sizeof(i));
print(sizeof(int));
print(sizeof i);
print(sizeof (i));
print(sizeof (int));
print(sizeof i);
print(sizeof (i));
print(sizeof (int));
}

View File

@ -1,4 +1,17 @@
/* $NetBSD: opt-bs.0.stdout,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-bs.0.stdout,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
void
example(int i)
{
print(sizeof (i));
print(sizeof (int));
print(sizeof i);
print(sizeof (i));
print(sizeof (int));
print(sizeof i);
print(sizeof (i));
print(sizeof (int));
}

View File

@ -1,4 +1,12 @@
/* $NetBSD: opt-c.0,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-c.0,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
bool
is_prime(int n)
{
if (n <= 3)
return n >= 2; /* special case */
if (n % 2 == 0)
return false; /* even numbers */
return true;
}

View File

@ -1,4 +1,12 @@
/* $NetBSD: opt-c.0.stdout,v 1.1 2021/03/06 17:56:34 rillig Exp $ */
/* $NetBSD: opt-c.0.stdout,v 1.2 2021/03/06 19:30:44 rillig Exp $ */
/* $FreeBSD$ */
/* TODO: implement the test */
bool
is_prime(int n)
{
if (n <= 3)
return n >= 2; /* special case */
if (n % 2 == 0)
return false; /* even numbers */
return true;
}