indent: fix off-by-one error in comment wrapping

The manual page says that the default maximum length of a comment line
is 78.  The test 'comments.0' wrongly assumed that this 78 would refer
to the maximum _column_ allowed, which is off by one.

Fix the wording in the test 'comments.0' and remove the (now satisfied)
expectation comments in the test 'token-comment.0'.

Several other tests just happened to hit that limit, fix these as well.
This commit is contained in:
rillig 2021-03-14 01:34:13 +00:00
parent 80a063b8f7
commit 1e4c413bac
7 changed files with 28 additions and 27 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: comments.0,v 1.1 2019/04/04 15:27:35 kamil Exp $ */
/* $NetBSD: comments.0,v 1.2 2021/03/14 01:34:13 rillig Exp $ */
/* $FreeBSD: head/usr.bin/indent/tests/comments.0 321383 2017-07-23 15:07:52Z pstef $ */
typedef enum x {
aaaaaaaaaaaaaaaaaaaaaa = 1 << 0, /* test a */
@ -16,8 +16,9 @@ void t(void) {
*/
/*
* Old indent did not wrap to column 78
*
* The default maximum line length for comments is 78, and the 'kk' at
* the end makes the line exactly 78 bytes long.
*
* aaaaaa bbbbbb cccccc dddddd eeeeee ffffff ggggg hhhhh iiiii jjjj kk
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: comments.0.stdout,v 1.1 2019/04/04 15:27:35 kamil Exp $ */
/* $NetBSD: comments.0.stdout,v 1.2 2021/03/14 01:34:13 rillig Exp $ */
/* $FreeBSD: head/usr.bin/indent/tests/comments.0.stdout 334563 2018-06-03 15:28:55Z pstef $ */
typedef enum x {
aaaaaaaaaaaaaaaaaaaaaa = 1 << 0, /* test a */
@ -18,10 +18,10 @@ t(void)
*/
/*
* Old indent did not wrap to column 78
* The default maximum line length for comments is 78, and the 'kk' at
* the end makes the line exactly 78 bytes long.
*
* aaaaaa bbbbbb cccccc dddddd eeeeee ffffff ggggg hhhhh iiiii jjjj
* kk
* aaaaaa bbbbbb cccccc dddddd eeeeee ffffff ggggg hhhhh iiiii jjjj kk
*/
/*

View File

@ -1,8 +1,7 @@
/* $NetBSD: opt-P.0.stdout,v 1.2 2021/03/07 10:12:18 rillig Exp $ */
/* $NetBSD: opt-P.0.stdout,v 1.3 2021/03/14 01:34:13 rillig Exp $ */
/* $FreeBSD$ */
/*
* Mentioning another profile via -P has no effect since only a single
* profile can be specified on the command line, and there is no 'include'
* option.
* Mentioning another profile via -P has no effect since only a single profile
* can be specified on the command line, and there is no 'include' option.
*/

View File

@ -1,10 +1,10 @@
/* $NetBSD: opt-bap+sob.0.stdout,v 1.1 2021/03/08 22:13:05 rillig Exp $ */
/* $NetBSD: opt-bap+sob.0.stdout,v 1.2 2021/03/14 01:34:13 rillig Exp $ */
/* $FreeBSD$ */
/*
* As of 2021-03-08, the combination of -bap and -sob, which occurs in the
* example indent.pro from NetBSD, removes the empty line above the
* separator. Seen in games/cgram/cgram.c.
* example indent.pro from NetBSD, removes the empty line above the separator.
* Seen in games/cgram/cgram.c.
*/
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: token-comment.0.stdout,v 1.2 2021/03/14 00:50:39 rillig Exp $ */
/* $NetBSD: token-comment.0.stdout,v 1.3 2021/03/14 01:34:13 rillig Exp $ */
/* $FreeBSD$ */
/*
@ -12,12 +12,8 @@
/* 456789 123456789 123456789 123456789 123456789 123456789 123456789 12345 */
/* 456789 123456789 123456789 123456789 123456789 123456789 123456789 123456 */
/* 456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 */
/* $ XXX: The '12345678' should be kept on the main line since it adds up */
/* $ XXX: to a line length of exactly 78, which according to the manual */
/* $ XXX: page should be ok. */
/*
* 456789 123456789 123456789 123456789 123456789 123456789 123456789
* 12345678
* 456789 123456789 123456789 123456789 123456789 123456789 123456789 12345678
*/
/*
* 456789 123456789 123456789 123456789 123456789 123456789 123456789

View File

@ -1,10 +1,10 @@
/* $NetBSD: token-keyword_do_else.0.stdout,v 1.1 2021/03/12 00:13:06 rillig Exp $ */
/* $NetBSD: token-keyword_do_else.0.stdout,v 1.2 2021/03/14 01:34:13 rillig Exp $ */
/* $FreeBSD$ */
/*
* Tests for the keyword 'do' or 'else'. These two keywords are followed by
* a space. In contrast to 'for', 'if' and 'while', the space is not
* followed by a parenthesized expression.
* Tests for the keyword 'do' or 'else'. These two keywords are followed by a
* space. In contrast to 'for', 'if' and 'while', the space is not followed
* by a parenthesized expression.
*/
/* TODO: Add some code to be formatted. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: pr_comment.c,v 1.31 2021/03/14 00:22:16 rillig Exp $ */
/* $NetBSD: pr_comment.c,v 1.32 2021/03/14 01:34:13 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93";
#include <sys/cdefs.h>
#ifndef lint
#if defined(__NetBSD__)
__RCSID("$NetBSD: pr_comment.c,v 1.31 2021/03/14 00:22:16 rillig Exp $");
__RCSID("$NetBSD: pr_comment.c,v 1.32 2021/03/14 01:34:13 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@ -200,6 +200,11 @@ process_comment(void)
if (t_ptr >= buf_end)
fill_buffer();
if (t_ptr[0] == '*' && t_ptr[1] == '/') {
/*
* XXX: This computation ignores the leading " * ", as well
* as the trailing ' ' '*' '/'. In simple cases, these cancel
* out since they are equally long.
*/
int right_margin = indentation_after_range(ps.com_col - 1,
buf_ptr, t_ptr + 2);
if (right_margin < adj_max_line_length)
@ -341,7 +346,7 @@ process_comment(void)
(now_len < adj_max_line_length || !last_bl));
ps.last_nl = false;
/* XXX: signed character comparison '>' does not work for UTF-8 */
if (now_len >= adj_max_line_length &&
if (now_len > adj_max_line_length &&
!ps.box_com && e_com[-1] > ' ') {
/*
* the comment is too long, it must be broken up