Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include new lines for single quote style #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ private[yaml] class Scanner(str: String) extends Tokenizer {
Scalar(choompedScalar, ScalarStyle.Folded, pos)

private def parseSingleQuoteValue(): Token = {
val sb = new StringBuilder
val singleQuoteIndent = indent
val sb = new StringBuilder

@tailrec
def readScalar(): String =
in.peek() match
Expand All @@ -217,15 +217,16 @@ private[yaml] class Scanner(str: String) extends Tokenizer {
sb.append('\'')
readScalar()
case Some('\n') =>
in.skipCharacter()
skipUntilNextIndent(singleQuoteIndent)
sb.append(' ')
skipUntilNextChar()
readScalar()
case Some('\'') | None =>
case Some('\'') =>
in.skipCharacter()
sb.result()
case Some(char) =>
sb.append(in.read())
readScalar()
case None => sb.result()

val pos = in.pos()
in.skipCharacter() // skip single quote
Expand Down Expand Up @@ -293,5 +294,8 @@ private[yaml] class Scanner(str: String) extends Tokenizer {
indent += 1
in.skipCharacter()

def skipUntilNextChar() =
while (in.isWhitespace) do in.skipCharacter()

private def skipComment(): Unit = while !in.isNewline do in.skipCharacter()
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ class ScalarSpec extends BaseParseSuite:
assertEventsEquals(events, expectedEvents)
}

test("should parse single quote scalar value with multiline") {
val yaml =
s"""description: 'multiline
| plain
| scalar'
|type: string
|""".stripMargin

val reader = Scanner(yaml)
val events = ParserImpl.getEvents(reader)

val expectedEvents = List(
StreamStart,
DocumentStart(),
MappingStart(),
Scalar("description", ScalarStyle.Plain),
Scalar("multiline plain scalar", ScalarStyle.SingleQuoted),
Scalar("type", ScalarStyle.Plain),
Scalar("string", ScalarStyle.Plain),
MappingEnd(),
DocumentEnd(),
StreamEnd
)

assertEventsEquals(events, expectedEvents)
}

test("should parse value with double quote") {
val yaml =
s"""| "/mnt/ iscsipd"
Expand Down Expand Up @@ -102,7 +129,7 @@ class ScalarSpec extends BaseParseSuite:

test("should parse single quote with multiline") {
val yaml =
s"""|description: 'Quote
s"""|description: 'Quote
| multiline.'
|""".stripMargin

Expand Down