loader: set correct location for README files
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 4 Jun 2015 15:32:08 +0000 (11:32 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 24 Jun 2015 20:29:59 +0000 (16:29 -0400)
Also correct comment for line_starts

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/loader.nit
src/location.nit
tests/sav/nitunit_args6.res
tests/sav/nitunit_args7.res

index d78ac71..5d20c9c 100644 (file)
@@ -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
 
index 1a27697..108cf28 100644 (file)
@@ -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
 
index ac5aebd..8971f9e 100644 (file)
@@ -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.<group> (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.<group> (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
-<testsuites><testsuite package="test_nitunit3"><testcase classname="nitunit.test_nitunit3" name="&lt;group&gt;"><failure message="test_nitunit3&#47;README.md: Invalid block of code. At 1,2--4: Syntax Error: unexpected malformed character &#39;\].."></failure><system-err></system-err><system-out>assert false
+<testsuites><testsuite package="test_nitunit3"><testcase classname="nitunit.test_nitunit3" name="&lt;group&gt;"><failure message="test_nitunit3&#47;README.md:1,0--13,0: Invalid block of code. At 1,2--4: Syntax Error: unexpected malformed character &#39;\].."></failure><system-err></system-err><system-out>assert false
 assert true
 </system-out><error message="Runtime error: Assert failed (.nitunit&#47;test_nitunit3-0.nit:7)
 "></error></testcase></testsuite><testsuite package="test_nitunit3"><testcase classname="nitunit.test_nitunit3.&lt;module&gt;" name="&lt;module&gt;"><system-err></system-err><system-out>assert true
index ea6bab2..fc20a76 100644 (file)
@@ -1,4 +1,4 @@
-test_nitunit_md.md: ERROR: nitunit.<file>.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.<file>.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
-<testsuites><testsuite package="test_nitunit_md.md"><testcase classname="nitunit.&lt;file&gt;" name="test_nitunit_md.md"><system-err></system-err><system-out>var a = 1
+<testsuites><testsuite package="test_nitunit_md.md:1,0--15,0"><testcase classname="nitunit.&lt;file&gt;" name="test_nitunit_md.md:1,0--15,0"><system-err></system-err><system-out>var a = 1
 assert 1 == 1
 assert false
 </system-out><error message="Runtime error: Assert failed (.nitunit&#47;file-0.nit:8)