From d9902cdeb830bd48bf447d1b83cd3a6c73caf4ea Mon Sep 17 00:00:00 2001 From: Bastien Jansen Date: Thu, 29 Feb 2024 22:45:28 +0100 Subject: [PATCH] Don't add a second quote when typing `"` at the end of a string (fixes #176) --- .../pebble/editor/PebbleQuoteHandler.kt | 2 +- .../pebble/editor/PebbleQuoteHandlerTest.kt | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/test/kotlin/com/github/bjansen/intellij/pebble/editor/PebbleQuoteHandlerTest.kt diff --git a/src/main/kotlin/com/github/bjansen/intellij/pebble/editor/PebbleQuoteHandler.kt b/src/main/kotlin/com/github/bjansen/intellij/pebble/editor/PebbleQuoteHandler.kt index 67b1c7d..601b538 100644 --- a/src/main/kotlin/com/github/bjansen/intellij/pebble/editor/PebbleQuoteHandler.kt +++ b/src/main/kotlin/com/github/bjansen/intellij/pebble/editor/PebbleQuoteHandler.kt @@ -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]) diff --git a/src/test/kotlin/com/github/bjansen/intellij/pebble/editor/PebbleQuoteHandlerTest.kt b/src/test/kotlin/com/github/bjansen/intellij/pebble/editor/PebbleQuoteHandlerTest.kt new file mode 100644 index 0000000..59bb673 --- /dev/null +++ b/src/test/kotlin/com/github/bjansen/intellij/pebble/editor/PebbleQuoteHandlerTest.kt @@ -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, """{{ }}""") + + // When + myFixture.type("'") + + // Then + edt { + assertEquals("{{ '' }}", myFixture.editor.document.text) + } + } + + fun testOverwritingOfSingleQuote() { + // Given + myFixture.configureByText(PebbleFileType.INSTANCE, """{{ '' }}""") + + // When + myFixture.type("'") + + // Then + edt { + assertEquals("{{ '' }}", myFixture.editor.document.text) + } + } + + fun testAutoclosingOfDoubleQuote() { + // Given + myFixture.configureByText(PebbleFileType.INSTANCE, """{{ }}""") + + // When + myFixture.type("\"") + + // Then + edt { + assertEquals("{{ \"\" }}", myFixture.editor.document.text) + } + } + + fun testOverwritingOfDoubleQuote() { + // Given + myFixture.configureByText(PebbleFileType.INSTANCE, """{{ "" }}""") + + // When + myFixture.type("\"") + + // Then + edt { + assertEquals("{{ \"\" }}", myFixture.editor.document.text) + } + } + +}