mirror of
https://github.com/enso-org/enso.git
synced 2024-11-27 03:43:20 +03:00
parent
c22d7422e6
commit
ef9f3cc11e
@ -1428,7 +1428,7 @@ export class MutableTextLiteral extends TextLiteral implements MutableAst {
|
||||
setRawTextContent(rawText: string) {
|
||||
let boundary = this.boundaryTokenCode()
|
||||
const isInterpolated = this.isInterpolated()
|
||||
const mustBecomeInterpolated = !isInterpolated && (!boundary || rawText.includes(boundary))
|
||||
const mustBecomeInterpolated = !isInterpolated && (!boundary || rawText.match(/["\n\r]/))
|
||||
if (mustBecomeInterpolated) {
|
||||
boundary = "'"
|
||||
this.setBoundaries(boundary)
|
||||
|
@ -900,9 +900,23 @@ test.prop({
|
||||
literal.setBoundaries(boundary)
|
||||
literal.setRawTextContent(rawText)
|
||||
expect(literal.rawTextContent).toBe(rawText)
|
||||
const expectInterpolated = rawText.includes('"') || boundary === "'"
|
||||
const expectedCode = expectInterpolated ? `'${escapeTextLiteral(rawText)}'` : `"${rawText}"`
|
||||
expect(literal.code()).toBe(expectedCode)
|
||||
const codeAsInterpolated = `'${escapeTextLiteral(rawText)}'`
|
||||
if (boundary === "'") {
|
||||
expect(literal.code()).toBe(codeAsInterpolated)
|
||||
} else {
|
||||
const codeAsRaw = `"${rawText}"`
|
||||
// Uninterpolated text will be promoted to interpolated if necessary to escape a special character.
|
||||
expect([codeAsInterpolated, codeAsRaw]).toContainEqual(literal.code())
|
||||
}
|
||||
})
|
||||
|
||||
test('setRawTextContent promotes single-line uninterpolated text to interpolated if a newline is added', () => {
|
||||
const literal = TextLiteral.new('')
|
||||
literal.setBoundaries('"')
|
||||
const rawText = '\n'
|
||||
literal.setRawTextContent(rawText)
|
||||
expect(literal.rawTextContent).toBe(rawText)
|
||||
expect(literal.code()).toBe(`'${escapeTextLiteral(rawText)}'`)
|
||||
})
|
||||
|
||||
const docEditCases = [
|
||||
|
Loading…
Reference in New Issue
Block a user