From 12a690b4b555086a7a1e0a5429a22dadf6961767 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 14 Nov 2023 00:49:58 +0100 Subject: [PATCH] Tests for empty line comment, and fix in Rust --- implementations/python/tests/samples.pr | 6 ++++++ .../racket/preserves/preserves/tests/samples.pr | 6 ++++++ implementations/rust/preserves/src/value/text/reader.rs | 9 +++++++++ tests/samples.pr | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/implementations/python/tests/samples.pr b/implementations/python/tests/samples.pr index bd6b456..c55e2aa 100644 --- a/implementations/python/tests/samples.pr +++ b/implementations/python/tests/samples.pr @@ -56,6 +56,12 @@ annotation8a: @"Commas forbidden between @ and annotation in a collection" annotation9: @"Commas forbidden between annotation and underlying" annotation9a: @"Commas forbidden between annotation and underlying in a collection" + annotation10: @"Line comment that's just hash-newline" + annotation11: @"Line comments: one hash-newline, one normal" + bytes2: bytes2a: bytes2b: @"Commas forbidden in internal whitespace" diff --git a/implementations/racket/preserves/preserves/tests/samples.pr b/implementations/racket/preserves/preserves/tests/samples.pr index bd6b456..c55e2aa 100644 --- a/implementations/racket/preserves/preserves/tests/samples.pr +++ b/implementations/racket/preserves/preserves/tests/samples.pr @@ -56,6 +56,12 @@ annotation8a: @"Commas forbidden between @ and annotation in a collection" annotation9: @"Commas forbidden between annotation and underlying" annotation9a: @"Commas forbidden between annotation and underlying in a collection" + annotation10: @"Line comment that's just hash-newline" + annotation11: @"Line comments: one hash-newline, one normal" + bytes2: bytes2a: bytes2b: @"Commas forbidden in internal whitespace" diff --git a/implementations/rust/preserves/src/value/text/reader.rs b/implementations/rust/preserves/src/value/text/reader.rs index 5f02453..a25ac75 100644 --- a/implementations/rust/preserves/src/value/text/reader.rs +++ b/implementations/rust/preserves/src/value/text/reader.rs @@ -520,6 +520,15 @@ impl<'de, 'src, N: NestedValue, Dec: DomainParse, S: BinarySource<' continue 'restart; } } + b'\n' | b'\r' => { + if read_annotations { + let mut annotations = vec![N::new("")]; + self.gather_annotations(&mut annotations)?; + self.prepend_annotations_to_next(annotations)? + } else { + continue 'restart; + } + } b'f' => { self.require_delimiter("Delimiter must follow #f")?; N::new(false) } b't' => { self.require_delimiter("Delimiter must follow #t")?; N::new(true) } b'{' => self.read_set(read_annotations)?, diff --git a/tests/samples.pr b/tests/samples.pr index bd6b456..c55e2aa 100644 --- a/tests/samples.pr +++ b/tests/samples.pr @@ -56,6 +56,12 @@ annotation8a: @"Commas forbidden between @ and annotation in a collection" annotation9: @"Commas forbidden between annotation and underlying" annotation9a: @"Commas forbidden between annotation and underlying in a collection" + annotation10: @"Line comment that's just hash-newline" + annotation11: @"Line comments: one hash-newline, one normal" + bytes2: bytes2a: bytes2b: @"Commas forbidden in internal whitespace"