From d4003a5e3bdfe138e5c3e0babaf8a6d086ab382e Mon Sep 17 00:00:00 2001 From: kstich Date: Fri, 21 Feb 2020 14:03:23 -0800 Subject: [PATCH] Fix dropping one character text block lines --- .../amazon/smithy/model/loader/SmithyModelLexer.java | 2 +- .../amazon/smithy/model/loader/SmithyModelLexerTest.java | 5 +++++ .../software/amazon/smithy/model/loader/valid/traits.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/SmithyModelLexer.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/SmithyModelLexer.java index 46944c7e678..22a1f0aa092 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/SmithyModelLexer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/SmithyModelLexer.java @@ -623,6 +623,6 @@ private static String createTextBlockLine(String line, int longestPadding) { endPosition--; } - return endPosition > startPosition ? line.substring(startPosition, endPosition + 1) : null; + return endPosition >= startPosition ? line.substring(startPosition, endPosition + 1) : null; } } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/SmithyModelLexerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/SmithyModelLexerTest.java index f666be20847..1ccf97c6365 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/SmithyModelLexerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/SmithyModelLexerTest.java @@ -65,8 +65,13 @@ private static Stream validTextProvider() { Arguments.of("\"\\ud83d\\ude00\"", "\uD83D\uDE00"), // Text blocks + Arguments.of("\"\"\"\nf\"\"\"", "f"), Arguments.of("\"\"\"\nfoo\"\"\"", "foo"), Arguments.of("\"\"\"\nfoo\\\"\"\"\"", "foo\""), + Arguments.of("\"\"\"\nf\n foo\n\"\"\"", "f\n foo\n"), + Arguments.of("\"\"\"\n f\n foo\n\"\"\"", "f\n foo\n"), + Arguments.of("\"\"\"\n foo\nf\n\"\"\"", " foo\nf\n"), + Arguments.of("\"\"\"\n foo\n f\n\"\"\"", " foo\nf\n"), Arguments.of("\"\"\"\n foo\n baz\"\"\"", "foo\nbaz"), Arguments.of("\"\"\"\n\n\n\"\"\"", "\n\n"), Arguments.of("\"\"\"\n foo\n baz\n \"\"\"", "foo\nbaz\n"), diff --git a/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/traits.json b/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/traits.json index 325a5c144fe..05a2774dd1e 100644 --- a/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/traits.json +++ b/smithy-model/src/test/resources/software/amazon/smithy/model/loader/valid/traits.json @@ -162,7 +162,7 @@ "com.example#U": { "type": "string", "traits": { - "smithy.api#documentation": "This is a\nstring defined on multiple lines.\nIt can span\n\ngreat\nmany\nlines." + "smithy.api#documentation": "This is a\nstring defined on multiple lines.\nIt can span\na\ngreat\nmany\nlines." } }, "com.example#numeric": {