use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoStringLiteralEscaperTest method testDecodeHexCharString.
public void testDecodeHexCharString() {
GoStringLiteral expr = createStringFromText("\\x41");
assertNotNull(expr);
String a = decodeRange(expr, TextRange.create(1, 5));
assertEquals("A", a);
}
use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoConvertStringToByteQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement element = descriptor.getPsiElement();
if (!(element instanceof GoConditionalExpr) || !element.isValid()) {
return;
}
GoConditionalExpr expr = (GoConditionalExpr) element;
GoStringLiteral literal = ContainerUtil.findInstance(Arrays.asList(expr.getLeft(), expr.getRight()), GoStringLiteral.class);
if (literal == null || !isSingleCharLiteral(literal)) {
return;
}
literal.replace(createExpression(project, extractSingleCharFromText(literal)));
}
use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoStringLiteralEscaperTest method testDecodeShortUnicodeCharString.
public void testDecodeShortUnicodeCharString() {
GoStringLiteral expr = createStringFromText("\\u8a9e");
assertNotNull(expr);
String a = decodeRange(expr, TextRange.create(1, 7));
assertEquals("語", a);
}
use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoStringLiteralEscaperTest method testDecodeEscapedString.
// region decode tests
public void testDecodeEscapedString() {
GoStringLiteral expr = createStringFromText("\\t\\n\\b");
assertNotNull(expr);
String a = decodeRange(expr, TextRange.create(1, 7));
assertEquals("\t\n\b", a);
}
use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoStringLiteralEscaperTest method testEscaperOffsetInStringHostSubString.
public void testEscaperOffsetInStringHostSubString() {
GoStringLiteral expr = createStringFromText("\\nfoo");
assertNotNull(expr);
LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
TextRange fooOnly = TextRange.create(3, 6);
escaper.decode(fooOnly, new StringBuilder());
assertEquals(3, escaper.getOffsetInHost(0, fooOnly));
assertEquals(4, escaper.getOffsetInHost(1, fooOnly));
assertEquals(5, escaper.getOffsetInHost(2, fooOnly));
assertEquals(6, escaper.getOffsetInHost(3, fooOnly));
assertEquals(-1, escaper.getOffsetInHost(4, fooOnly));
}
Aggregations