use of com.jetbrains.python.psi.PyStringLiteralExpression in project intellij-community by JetBrains.
the class PyBlockEvaluatorTest method testDictNoEvaluate.
public void testDictNoEvaluate() {
PyBlockEvaluator eval = doEvaluate("a={'b': 'c'}", true);
Map map = (Map) eval.getValue("a");
assertEquals(1, map.size());
assertTrue(map.get("b") instanceof PyStringLiteralExpression);
}
use of com.jetbrains.python.psi.PyStringLiteralExpression in project intellij-community by JetBrains.
the class PySectionBasedDocStringTest method findFirstDocString.
@Nullable
private String findFirstDocString() {
final PsiElementProcessor.FindElement<PsiElement> processor = new PsiElementProcessor.FindElement<PsiElement>() {
@Override
public boolean execute(@NotNull PsiElement element) {
if (element instanceof PyStringLiteralExpression && element.getFirstChild().getNode().getElementType() == PyTokenTypes.DOCSTRING) {
return setFound(element);
}
return true;
}
};
PsiTreeUtil.processElements(myFixture.getFile(), processor);
if (!processor.isFound()) {
return null;
}
final PsiElement foundElement = processor.getFoundElement();
assertNotNull(foundElement);
return ((PyStringLiteralExpression) foundElement).getStringValue();
}
use of com.jetbrains.python.psi.PyStringLiteralExpression in project intellij-community by JetBrains.
the class PyStringLiteralTest method getCharacterRanges.
private List<String> getCharacterRanges(String text) {
final PyStringLiteralExpression expr = createLiteralFromText(text);
assertNotNull(expr);
final List<String> characters = new ArrayList<>();
for (Pair<TextRange, String> fragment : expr.getDecodedFragments()) {
characters.add(fragment.getSecond());
}
return characters;
}
use of com.jetbrains.python.psi.PyStringLiteralExpression in project intellij-community by JetBrains.
the class PyStringLiteralTest method testEscaperOffsetInHost.
public void testEscaperOffsetInHost() {
final PyStringLiteralExpression expr = createLiteralFromText("'\\nfoo'");
assertNotNull(expr);
final LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
final TextRange newLineFoo = TextRange.create(1, 6);
assertEquals(1, escaper.getOffsetInHost(0, newLineFoo));
assertEquals(3, escaper.getOffsetInHost(1, newLineFoo));
assertEquals(4, escaper.getOffsetInHost(2, newLineFoo));
assertEquals(5, escaper.getOffsetInHost(3, newLineFoo));
assertEquals(6, escaper.getOffsetInHost(4, newLineFoo));
assertEquals(-1, escaper.getOffsetInHost(5, newLineFoo));
}
use of com.jetbrains.python.psi.PyStringLiteralExpression in project intellij-community by JetBrains.
the class PyStringLiteralTest method testEscaperOffsetInSingleCharString.
public void testEscaperOffsetInSingleCharString() {
final PyStringLiteralExpression expr = createLiteralFromText("'c'");
assertNotNull(expr);
final LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
final TextRange range = TextRange.create(1, 2);
assertEquals(1, escaper.getOffsetInHost(0, range));
assertEquals(2, escaper.getOffsetInHost(1, range));
assertEquals(-1, escaper.getOffsetInHost(2, range));
}
Aggregations