Search in sources :

Example 6 with Field

use of com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field in project intellij-community by JetBrains.

the class PyStringFormatParserTest method testNewStyleAutoPosition.

public void testNewStyleAutoPosition() {
    final ParseResult result = PyNewStyleStringFormatParser.parse("'{foo} {} {bar} {0} {}'");
    final List<Field> topLevelFields = result.getFields();
    assertSize(5, topLevelFields);
    assertEquals("foo", topLevelFields.get(0).getMappingKey());
    assertNull(topLevelFields.get(0).getPosition());
    assertNull(topLevelFields.get(0).getAutoPosition());
    assertNull(topLevelFields.get(1).getMappingKey());
    assertNull(topLevelFields.get(1).getPosition());
    assertEquals(0, (int) topLevelFields.get(1).getAutoPosition());
    assertEquals("bar", topLevelFields.get(2).getMappingKey());
    assertNull(topLevelFields.get(2).getPosition());
    assertNull(topLevelFields.get(2).getAutoPosition());
    assertNull(topLevelFields.get(3).getMappingKey());
    assertEquals(0, (int) topLevelFields.get(3).getPosition());
    assertNull(topLevelFields.get(3).getAutoPosition());
    assertNull(topLevelFields.get(4).getMappingKey());
    assertNull(topLevelFields.get(4).getPosition());
    assertEquals(1, (int) topLevelFields.get(4).getAutoPosition());
}
Also used : Field(com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field) ParseResult(com.jetbrains.python.inspections.PyNewStyleStringFormatParser.ParseResult)

Example 7 with Field

use of com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field in project intellij-community by JetBrains.

the class PyStringFormatParserTest method testNewStyleNamedUnicodeEscapeInLookup.

public void testNewStyleNamedUnicodeEscapeInLookup() {
    final Field field = doParseAndGetFirstField("'{foo[\\N{ESCAPE WITH ]}]}'");
    assertOrderedEquals(field.getAttributesAndLookups(), "[\\N{ESCAPE WITH ]}]");
}
Also used : Field(com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field)

Example 8 with Field

use of com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field in project intellij-community by JetBrains.

the class PyStringFormatParserTest method testNewStyleNamedUnicodeEscapeInAttribute.

public void testNewStyleNamedUnicodeEscapeInAttribute() {
    final Field field = doParseAndGetFirstField("'{foo.b\\N{ESCAPE WITH [}.b\\N{ESCAPE WITH .}}'");
    assertOrderedEquals(field.getAttributesAndLookups(), ".b\\N{ESCAPE WITH [}", ".b\\N{ESCAPE WITH .}");
}
Also used : Field(com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field)

Example 9 with Field

use of com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field in project intellij-community by JetBrains.

the class PyStringFormatParserTest method testNewStyleTooNestedFields.

public void testNewStyleTooNestedFields() {
    final ParseResult result = PyNewStyleStringFormatParser.parse("'{:{:{:{}}}} {}'");
    final List<Field> topLevelFields = result.getFields();
    assertSize(2, topLevelFields);
    assertSize(5, result.getAllFields());
    assertOrderedEquals(result.getAllFields().stream().map(Field::getDepth).toArray(), 1, 2, 3, 4, 1);
    assertOrderedEquals(result.getAllFields().stream().map(SubstitutionChunk::getAutoPosition).toArray(), 0, 1, 2, 3, 4);
}
Also used : Field(com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field) ParseResult(com.jetbrains.python.inspections.PyNewStyleStringFormatParser.ParseResult)

Example 10 with Field

use of com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field in project intellij-community by JetBrains.

the class PyStringFormatParserTest method doParseAndGetFirstField.

@NotNull
private static Field doParseAndGetFirstField(@NotNull String nodeText) {
    final ParseResult result = PyNewStyleStringFormatParser.parse(nodeText);
    final List<Field> topLevelFields = result.getFields();
    assertSize(1, topLevelFields);
    return topLevelFields.get(0);
}
Also used : Field(com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field) ParseResult(com.jetbrains.python.inspections.PyNewStyleStringFormatParser.ParseResult) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Field (com.jetbrains.python.inspections.PyNewStyleStringFormatParser.Field)10 ParseResult (com.jetbrains.python.inspections.PyNewStyleStringFormatParser.ParseResult)3 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 PySubstitutionChunkReference (com.jetbrains.python.codeInsight.PySubstitutionChunkReference)1 NotNull (org.jetbrains.annotations.NotNull)1