-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: retrieve value from quoted/single quoted/unquoted psi element (#…
…128) Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/com/redhat/devtools/intellij/common/utils/StringHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.redhat.devtools.intellij.common.utils; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.redhat.devtools.intellij.common.FixtureBaseTest; | ||
import org.jetbrains.yaml.YAMLFileType; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class StringHelperTest extends FixtureBaseTest { | ||
|
||
@Test | ||
public void GetUnquotedValueFromPsi_DoubleQuotedValue_ValueWithoutQuotes() throws IOException { | ||
String content = "\"foo\""; | ||
PsiFile psiFile = myFixture.configureByText(YAMLFileType.YML, content); | ||
ApplicationManager.getApplication().runReadAction(() -> { | ||
PsiElement result = psiFile.getFirstChild().getLastChild(); | ||
assertEquals("foo", StringHelper.getUnquotedValueFromPsi(result)); | ||
}); | ||
} | ||
|
||
@Test | ||
public void GetUnquotedValueFromPsi_SingleQuotedValue_ValueWithoutQuotes() throws IOException { | ||
String content = "'foo'"; | ||
PsiFile psiFile = myFixture.configureByText(YAMLFileType.YML, content); | ||
ApplicationManager.getApplication().runReadAction(() -> { | ||
PsiElement result = psiFile.getFirstChild().getLastChild(); | ||
assertEquals("foo", StringHelper.getUnquotedValueFromPsi(result)); | ||
}); | ||
} | ||
|
||
@Test | ||
public void GetUnquotedValueFromPsi_UnquotedValue_ValueAsIs() throws IOException { | ||
String content = "foo"; | ||
PsiFile psiFile = myFixture.configureByText(YAMLFileType.YML, content); | ||
ApplicationManager.getApplication().runReadAction(() -> { | ||
PsiElement result = psiFile.getFirstChild().getLastChild(); | ||
assertEquals("foo", StringHelper.getUnquotedValueFromPsi(result)); | ||
}); | ||
} | ||
} |