Search in sources :

Example 1 with GoStringLiteral

use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStringLiteralEscaperTest method testEscaperOffsetInStringHost.

public void testEscaperOffsetInStringHost() {
    GoStringLiteral expr = createStringFromText("\\nfoo");
    assertNotNull(expr);
    LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
    TextRange newLineFoo = TextRange.create(1, 6);
    escaper.decode(newLineFoo, new StringBuilder());
    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));
}
Also used : GoStringLiteral(com.goide.psi.GoStringLiteral) TextRange(com.intellij.openapi.util.TextRange)

Example 2 with GoStringLiteral

use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStringLiteralEscaperTest method testEscaperOffsetInRawStringHost.

public void testEscaperOffsetInRawStringHost() {
    GoStringLiteral expr = createRawStringFromText("\nfoo");
    assertNotNull(expr);
    LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
    TextRange newLineFoo = TextRange.create(1, 5);
    escaper.decode(newLineFoo, new StringBuilder());
    assertEquals(1, escaper.getOffsetInHost(0, newLineFoo));
    assertEquals(2, escaper.getOffsetInHost(1, newLineFoo));
    assertEquals(3, escaper.getOffsetInHost(2, newLineFoo));
    assertEquals(4, escaper.getOffsetInHost(3, newLineFoo));
    assertEquals(5, escaper.getOffsetInHost(4, newLineFoo));
    assertEquals(-1, escaper.getOffsetInHost(5, newLineFoo));
}
Also used : GoStringLiteral(com.goide.psi.GoStringLiteral) TextRange(com.intellij.openapi.util.TextRange)

Example 3 with GoStringLiteral

use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStringLiteralEscaperTest method testDecodeEscapedBellString.

public void testDecodeEscapedBellString() {
    GoStringLiteral expr = createStringFromText("\\a");
    assertNotNull(expr);
    String a = decodeRange(expr, TextRange.create(1, 3));
    assertEquals("\007", a);
}
Also used : GoStringLiteral(com.goide.psi.GoStringLiteral)

Example 4 with GoStringLiteral

use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStringLiteralEscaperTest method testEscaperOffsetInRawStringHostSubString.

public void testEscaperOffsetInRawStringHostSubString() {
    GoStringLiteral expr = createRawStringFromText("\nfoo");
    assertNotNull(expr);
    LiteralTextEscaper<? extends PsiLanguageInjectionHost> escaper = expr.createLiteralTextEscaper();
    TextRange fooOnly = TextRange.create(2, 5);
    escaper.decode(fooOnly, new StringBuilder());
    assertEquals(2, escaper.getOffsetInHost(0, fooOnly));
    assertEquals(3, escaper.getOffsetInHost(1, fooOnly));
    assertEquals(4, escaper.getOffsetInHost(2, fooOnly));
    assertEquals(5, escaper.getOffsetInHost(3, fooOnly));
    assertEquals(-1, escaper.getOffsetInHost(4, fooOnly));
}
Also used : GoStringLiteral(com.goide.psi.GoStringLiteral) TextRange(com.intellij.openapi.util.TextRange)

Example 5 with GoStringLiteral

use of com.goide.psi.GoStringLiteral in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStringLiteralEscaperTest method testQuote.

public void testQuote() {
    PlatformTestUtil.withEncoding(CharsetToolkit.UTF8, () -> {
        GoStringLiteral expr = createStringFromText("import \\\"fmt\\\"");
        assertNotNull(expr);
        assertEquals("\"fmt\"", decodeRange(expr, TextRange.create(8, 15)));
    });
}
Also used : GoStringLiteral(com.goide.psi.GoStringLiteral)

Aggregations

GoStringLiteral (com.goide.psi.GoStringLiteral)16 TextRange (com.intellij.openapi.util.TextRange)5 GoConditionalExpr (com.goide.psi.GoConditionalExpr)1 PsiElement (com.intellij.psi.PsiElement)1