Skip to content

Commit

Permalink
fix not covering happy path that has no escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
cottand committed Jul 6, 2024
1 parent 9bc2749 commit 82d8b4c
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/main/java/org/nixos/idea/psi/NixStringLiteralEscaper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,28 @@ class NixStringLiteralEscaper(host: AbstractNixString) : LiteralTextEscaper<PsiL
}
// $ can be escaped by prefixing it with '' (that is, two single quotes), i.e., ''$.
'$' -> outChars.append(c)
// Linefeed, carriage-return and tab characters can
// be written as ''\n, ''\r, ''\t, and ''\ escapes any other character.
'a' -> outChars.append(0x07.toChar())
'b' -> outChars.append('\b')
'f' -> outChars.append(0x0c.toChar())
'n' -> outChars.append('\n')
't' -> outChars.append('\t')
'r' -> outChars.append('\r')
'v' -> outChars.append(0x0b.toChar())
'\\' -> {
if (index == chars.length) return false
c = chars[index++]
when(c) {
// Linefeed, carriage-return and tab characters can
// be written as ''\n, ''\r, ''\t, and ''\ escapes any other character.
'a' -> outChars.append(0x07.toChar())
'b' -> outChars.append('\b')
'f' -> outChars.append(0x0c.toChar())
'n' -> outChars.append('\n')
't' -> outChars.append('\t')
'r' -> outChars.append('\r')
'v' -> outChars.append(0x0b.toChar())
else -> return false
}
}
else -> return false
}
if (sourceOffsets != null) {
sourceOffsets[outChars.length - outOffset] = index
}
continue
}

// // $ removes any special meaning from the following $.
Expand All @@ -122,10 +133,7 @@ class NixStringLiteralEscaper(host: AbstractNixString) : LiteralTextEscaper<PsiL
// // what here??
// }


if (sourceOffsets != null) {
sourceOffsets[outChars.length - outOffset] = index
}
outChars.append(c)
}
return true
}
Expand Down

0 comments on commit 82d8b4c

Please sign in to comment.