mirror of
https://github.com/enso-org/enso.git
synced 2024-11-27 02:55:06 +03:00
parent
c22d7422e6
commit
ef9f3cc11e
@ -1428,7 +1428,7 @@ export class MutableTextLiteral extends TextLiteral implements MutableAst {
|
|||||||
setRawTextContent(rawText: string) {
|
setRawTextContent(rawText: string) {
|
||||||
let boundary = this.boundaryTokenCode()
|
let boundary = this.boundaryTokenCode()
|
||||||
const isInterpolated = this.isInterpolated()
|
const isInterpolated = this.isInterpolated()
|
||||||
const mustBecomeInterpolated = !isInterpolated && (!boundary || rawText.includes(boundary))
|
const mustBecomeInterpolated = !isInterpolated && (!boundary || rawText.match(/["\n\r]/))
|
||||||
if (mustBecomeInterpolated) {
|
if (mustBecomeInterpolated) {
|
||||||
boundary = "'"
|
boundary = "'"
|
||||||
this.setBoundaries(boundary)
|
this.setBoundaries(boundary)
|
||||||
|
@ -900,9 +900,23 @@ test.prop({
|
|||||||
literal.setBoundaries(boundary)
|
literal.setBoundaries(boundary)
|
||||||
literal.setRawTextContent(rawText)
|
literal.setRawTextContent(rawText)
|
||||||
expect(literal.rawTextContent).toBe(rawText)
|
expect(literal.rawTextContent).toBe(rawText)
|
||||||
const expectInterpolated = rawText.includes('"') || boundary === "'"
|
const codeAsInterpolated = `'${escapeTextLiteral(rawText)}'`
|
||||||
const expectedCode = expectInterpolated ? `'${escapeTextLiteral(rawText)}'` : `"${rawText}"`
|
if (boundary === "'") {
|
||||||
expect(literal.code()).toBe(expectedCode)
|
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 = [
|
const docEditCases = [
|
||||||
|
Loading…
Reference in New Issue
Block a user