From 58101d3ef0e5c520cd0ab4c734438b0c690622b6 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Thu, 4 Jun 2015 11:32:08 -0400 Subject: [PATCH] loader: set correct location for README files Also correct comment for line_starts Signed-off-by: Alexandre Terrasa --- src/loader.nit | 16 +++++++++++++--- src/location.nit | 4 +++- tests/sav/nitunit_args6.res | 6 +++--- tests/sav/nitunit_args7.res | 4 ++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/loader.nit b/src/loader.nit index d78ac71..5d20c9c 100644 --- a/src/loader.nit +++ b/src/loader.nit @@ -479,11 +479,21 @@ redef class ModelBuilder # Load a markdown file as a documentation object fun load_markdown(filepath: String): MDoc do - var mdoc = new MDoc(new Location(new SourceFile.from_string(filepath, ""),0,0,0,0)) var s = new FileReader.open(filepath) + var lines = new Array[String] + var line_starts = new Array[Int] + var len = 1 while not s.eof do - mdoc.content.add(s.read_line) - end + var line = s.read_line + lines.add(line) + line_starts.add(len) + len += line.length + 1 + end + s.close + var source = new SourceFile.from_string(filepath, lines.join("\n")) + source.line_starts.add_all line_starts + var mdoc = new MDoc(new Location(source, 1, lines.length, 0, 0)) + mdoc.content.add_all(lines) return mdoc end diff --git a/src/location.nit b/src/location.nit index 1a27697..108cf28 100644 --- a/src/location.nit +++ b/src/location.nit @@ -42,7 +42,9 @@ class SourceFile line_starts[0] = 0 end - # Position of each line start + # Offset of each line start in the content `string`. + # + # Used for fast access to each line when rendering parts of the `string`. var line_starts = new Array[Int] end diff --git a/tests/sav/nitunit_args6.res b/tests/sav/nitunit_args6.res index ac5aebd..8971f9e 100644 --- a/tests/sav/nitunit_args6.res +++ b/tests/sav/nitunit_args6.res @@ -1,5 +1,5 @@ -test_nitunit3/README.md: Error: there is a block of invalid Nit code, thus not considered a nitunit. To suppress this warning, enclose the block with a fence tagged `nitish` or `raw` (see `man nitdoc`). At 1,2--4: Syntax Error: unexpected malformed character '\].. -test_nitunit3/README.md: ERROR: nitunit.test_nitunit3. (in .nitunit/test_nitunit3-0.nit): Runtime error: Assert failed (.nitunit/test_nitunit3-0.nit:7) +test_nitunit3/README.md:1,0--13,0: Error: there is a block of invalid Nit code, thus not considered a nitunit. To suppress this warning, enclose the block with a fence tagged `nitish` or `raw` (see `man nitdoc`). At 1,2--4: Syntax Error: unexpected malformed character '\].. +test_nitunit3/README.md:1,0--13,0: ERROR: nitunit.test_nitunit3. (in .nitunit/test_nitunit3-0.nit): Runtime error: Assert failed (.nitunit/test_nitunit3-0.nit:7) DocUnits: Entities: 2; Documented ones: 2; With nitunits: 3; Failures: 2 @@ -7,7 +7,7 @@ Entities: 2; Documented ones: 2; With nitunits: 3; Failures: 2 TestSuites: No test cases found Class suites: 0; Test Cases: 0; Failures: 0 -assert false +assert false assert true assert true diff --git a/tests/sav/nitunit_args7.res b/tests/sav/nitunit_args7.res index ea6bab2..fc20a76 100644 --- a/tests/sav/nitunit_args7.res +++ b/tests/sav/nitunit_args7.res @@ -1,4 +1,4 @@ -test_nitunit_md.md: ERROR: nitunit..test_nitunit_md.md (in .nitunit/file-0.nit): Runtime error: Assert failed (.nitunit/file-0.nit:8) +test_nitunit_md.md:1,0--15,0: ERROR: nitunit..test_nitunit_md.md:1,0--15,0 (in .nitunit/file-0.nit): Runtime error: Assert failed (.nitunit/file-0.nit:8) DocUnits: Entities: 1; Documented ones: 1; With nitunits: 1; Failures: 1 @@ -6,7 +6,7 @@ Entities: 1; Documented ones: 1; With nitunits: 1; Failures: 1 TestSuites: No test cases found Class suites: 0; Test Cases: 0; Failures: 0 -var a = 1 +var a = 1 assert 1 == 1 assert false