~sircmpwn/public-inbox

scdoc: Add basic working tests for line breaks parsing v1 PROPOSED

Damien Tardy-Panis: 3
 Add basic working tests for line breaks parsing
 Fix parsing of line breaks without newline
 Fix parsing of line breaks followed by underlined text

 5 files changed, 54 insertions(+), 5 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/public-inbox/patches/10698/mbox | git am -3
Learn more about email & git

[PATCH scdoc 1/3] Add basic working tests for line breaks parsing Export this patch

---
 test/line-breaks | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100755 test/line-breaks

diff --git a/test/line-breaks b/test/line-breaks
new file mode 100755
index 0000000..c6c2fc4
--- /dev/null
+++ b/test/line-breaks
@@ -0,0 +1,29 @@
#!/bin/sh
. test/lib.sh

begin "Handles line break"
scdoc <<EOF | grep '^\.br$' >/dev/null
test(8)

hello++
world
EOF
end 0

begin "Disallows empty line after line break"
scdoc <<EOF >/dev/null
test(8)

hello++

world
EOF
end 1

begin "Leave single +"
scdoc <<EOF | grep 'hello+world' >/dev/null
test(8)

hello+world
EOF
end 0
--
2.26.2

[PATCH scdoc 2/3] Fix parsing of line breaks without newline Export this patch

---
 src/main.c       | 2 +-
 test/line-breaks | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/main.c b/src/main.c
index 603c91e..08bf384 100644
--- a/src/main.c
+++ b/src/main.c
@@ -186,8 +186,8 @@ static void parse_linebreak(struct parser *p) {
	uint32_t lf = parser_getch(p);
	if (lf != '\n') {
		fprintf(p->output, "+");
		parser_pushch(p, lf);
		parser_pushch(p, plus);
		parser_pushch(p, '\n');
		return;
	}
	uint32_t ch = parser_getch(p);
diff --git a/test/line-breaks b/test/line-breaks
index c6c2fc4..e97332f 100755
--- a/test/line-breaks
+++ b/test/line-breaks
@@ -27,3 +27,11 @@ test(8)
hello+world
EOF
end 0

begin "Leave double + without newline"
scdoc <<EOF | grep 'hello++world' >/dev/null
test(8)

hello++world
EOF
end 0
-- 
2.26.2

[PATCH scdoc 3/3] Fix parsing of line breaks followed by underlined text Export this patch

---
 src/main.c       | 11 +++++++----
 test/line-breaks |  9 +++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/main.c b/src/main.c
index 08bf384..7bb6c42 100644
--- a/src/main.c
+++ b/src/main.c
@@ -176,19 +176,19 @@ static void parse_format(struct parser *p, enum formatting fmt) {
	p->flags ^= fmt;
}

static void parse_linebreak(struct parser *p) {
static bool parse_linebreak(struct parser *p) {
	uint32_t plus = parser_getch(p);
	if (plus != '+') {
		fprintf(p->output, "+");
		parser_pushch(p, plus);
		return;
		return false;
	}
	uint32_t lf = parser_getch(p);
	if (lf != '\n') {
		fprintf(p->output, "+");
		parser_pushch(p, lf);
		parser_pushch(p, plus);
		return;
		return false;
	}
	uint32_t ch = parser_getch(p);
	if (ch == '\n') {
@@ -197,6 +197,7 @@ static void parse_linebreak(struct parser *p) {
	}
	parser_pushch(p, ch);
	fprintf(p->output, "\n.br\n");
	return true;
}

static void parse_text(struct parser *p) {
@@ -230,7 +231,9 @@ static void parse_text(struct parser *p) {
			parser_pushch(p, next);
			break;
		case '+':
			parse_linebreak(p);
			if (parse_linebreak(p)) {
				last = '\n';
			}
			break;
		case '\n':
			utf8_fputch(p->output, ch);
diff --git a/test/line-breaks b/test/line-breaks
index e97332f..c119bd9 100755
--- a/test/line-breaks
+++ b/test/line-breaks
@@ -35,3 +35,12 @@ test(8)
hello++world
EOF
end 0

begin "Handles underlined text following line break"
scdoc <<EOF | grep '\\fIworld\\fR' >/dev/null
test(8)

hello++
_world_
EOF
end 0
--
2.26.2
View this thread in the archives