Skip to content

Commit

Permalink
Don't add a second quote when typing " at the end of a string (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bjansen committed Feb 29, 2024
1 parent 4d648d3 commit d9902cd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import com.github.bjansen.pebble.parser.PebbleLexer
import com.intellij.codeInsight.editorActions.SimpleTokenSetQuoteHandler

class PebbleQuoteHandler
: SimpleTokenSetQuoteHandler(tokens[PebbleLexer.STRING_START], tokens[PebbleLexer.SINGLE_QUOTED_STRING])
: SimpleTokenSetQuoteHandler(tokens[PebbleLexer.STRING_START], tokens[PebbleLexer.DOUBLE_QUOTED_PLAIN_STRING], tokens[PebbleLexer.SINGLE_QUOTED_STRING])

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.github.bjansen.intellij.pebble.editor

import com.github.bjansen.intellij.pebble.lang.PebbleFileType
import com.intellij.testFramework.fixtures.BasePlatformTestCase

class PebbleQuoteHandlerTest : BasePlatformTestCase() {
override fun getTestDataPath() = "src/test/resources/editor"

fun testAutoclosingOfSingleQuote() {
// Given
myFixture.configureByText(PebbleFileType.INSTANCE, """{{ <caret> }}""")

// When
myFixture.type("'")

// Then
edt<Throwable> {
assertEquals("{{ '' }}", myFixture.editor.document.text)
}
}

fun testOverwritingOfSingleQuote() {
// Given
myFixture.configureByText(PebbleFileType.INSTANCE, """{{ '<caret>' }}""")

// When
myFixture.type("'")

// Then
edt<Throwable> {
assertEquals("{{ '' }}", myFixture.editor.document.text)
}
}

fun testAutoclosingOfDoubleQuote() {
// Given
myFixture.configureByText(PebbleFileType.INSTANCE, """{{ <caret> }}""")

// When
myFixture.type("\"")

// Then
edt<Throwable> {
assertEquals("{{ \"\" }}", myFixture.editor.document.text)
}
}

fun testOverwritingOfDoubleQuote() {
// Given
myFixture.configureByText(PebbleFileType.INSTANCE, """{{ "<caret>" }}""")

// When
myFixture.type("\"")

// Then
edt<Throwable> {
assertEquals("{{ \"\" }}", myFixture.editor.document.text)
}
}

}

0 comments on commit d9902cd

Please sign in to comment.