ion-java icon indicating copy to clipboard operation
ion-java copied to clipboard

Incorrect line numbers on values inside list or struct

Open toddjonker opened this issue 5 years ago • 0 comments

(Isolating a defect identified amidst #226)

The reader is computing incorrect line numbers inside multi-line structs and lists (but not sexps). The following test case illustrates:

import static com.amazon.ion.util.Spans.currentSpan;
import static org.junit.Assert.assertEquals;
import com.amazon.ion.IonReader;
import com.amazon.ion.TextSpan;
import com.amazon.ion.system.IonReaderBuilder;
import org.junit.Test;

public class LineNumberTest
{
    private void assertNextLine(IonReader r, int expectedLine)
    {
        r.next();
        TextSpan textSpan = currentSpan(TextSpan.class, r);
        assertEquals(expectedLine, textSpan.getStartLine());
    }

    @Test
    public void testStructLineNumbers()
    {
        String text =
              "{ line: 1, \n"
            + "  line: 2, \n"
            + "  line: 3, \n"
            + "}";

        IonReader r = IonReaderBuilder.standard().build(text);
        assertNextLine(r, 1);
        r.stepIn();
        {
            assertNextLine(r, 1);
            assertNextLine(r, 2);           // FAILURE
            assertNextLine(r, 3);
        }
    }

    @Test
    public void testListLineNumbers()
    {
        String text =
              "[ 'line 1', \n"
            + "  'line 2', \n"
            + "  'line 3', \n"
            + "]";

        IonReader r = IonReaderBuilder.standard().build(text);
        assertNextLine(r, 1);
        r.stepIn();
        {
            assertNextLine(r, 1);
            assertNextLine(r, 2);           // FAILURE
            assertNextLine(r, 3);
        }
    }

    @Test
    public void testSexpLineNumbers()
    {
        String text =
              "( 'line 1' \n"
            + "  'line 2' \n"
            + "  'line 3' \n"
            + ")";

        IonReader r = IonReaderBuilder.standard().build(text);
        assertNextLine(r, 1);
        r.stepIn();
        {
            assertNextLine(r, 1);
            assertNextLine(r, 2);
            assertNextLine(r, 3);
        }
    }
}

toddjonker avatar Apr 19 '19 19:04 toddjonker