lib/markdown: factorize clones `code_from_block` into `BlockCode::raw_content`
[nit.git] / src / testing / testing_doc.nit
index 0f29d40..b5b0f5d 100644 (file)
@@ -68,7 +68,6 @@ class NitUnitExecutor
 
                # Populate `blocks` from the markdown decorator
                mdproc.process(mdoc.content.join("\n"))
-               if blocks.is_empty then return
 
                toolcontext.check_errors
 
@@ -77,11 +76,13 @@ class NitUnitExecutor
                                var ne = new HTMLTag("failure")
                                ne.attr("message", msg)
                                tc.add ne
+                               toolcontext.modelbuilder.unit_entities += 1
                                toolcontext.modelbuilder.failed_entities += 1
                        end
                        if blocks.is_empty then testsuite.add(tc)
                end
 
+               if blocks.is_empty then return
                for block in blocks do
                        docunits.add new DocUnit(mdoc, tc, block.write_to_string)
                end
@@ -289,7 +290,7 @@ private class NitunitDecorator
        var executor: NitUnitExecutor
 
        redef fun add_code(v, block) do
-               var code = code_from_block(block)
+               var code = block.raw_content
                var meta = "nit"
                if block isa BlockFence and block.meta != null then
                        meta = block.meta.to_s
@@ -320,26 +321,6 @@ private class NitunitDecorator
                # Add it to the file
                executor.blocks.last.append code
        end
-
-       # Extracts code as String from a `BlockCode`.
-       fun code_from_block(block: BlockCode): String do
-               var infence = block isa BlockFence
-               var text = new FlatBuffer
-               var line = block.block.first_line
-               while line != null do
-                       if not line.is_empty then
-                               var str = line.value
-                               if not infence and str.has_prefix("    ") then
-                                       text.append str.substring(4, str.length - line.trailing)
-                               else
-                                       text.append str
-                               end
-                       end
-                       text.append "\n"
-                       line = line.next
-               end
-               return text.write_to_string
-       end
 end
 
 # A unit-test to run
@@ -380,9 +361,9 @@ redef class ModelBuilder
                # usualy, only the original module must be imported in the unit test.
                var o = mmodule
                var g = o.mgroup
-               if g != null and g.mproject.name == "standard" then
-                       # except for a unit test in a module of standard
-                       # in this case, the whole standard must be imported
+               if g != null and g.mproject.name == "core" then
+                       # except for a unit test in a module of `core`
+                       # in this case, the whole `core` must be imported
                        o = get_mmodule_by_name(nmodule, g, g.mproject.name).as(not null)
                end