From 1c7210da0d3db8a384e4be19f2db1f1047b531c2 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 23 Apr 2014 23:36:41 -0400 Subject: [PATCH] nitunit: allows multiple independant block in a single comment A new block is started by non-trivial modules Signed-off-by: Jean Privat --- src/nitunit.nit | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/nitunit.nit b/src/nitunit.nit index c9029a9..688f8cf 100644 --- a/src/nitunit.nit +++ b/src/nitunit.nit @@ -42,7 +42,7 @@ class NitUnitExecutor end # All blocks of code from a same `ADoc` - var block = new Array[String] + var blocks = new Array[Array[String]] redef fun process_code(n: HTMLTag, text: String) do @@ -57,8 +57,14 @@ class NitUnitExecutor v.enter_visit(ast) if not v.foundit then return + # Create a first block + # Or create a new block for modules that are more than a main part + if blocks.is_empty or ast isa AModule then + blocks.add(new Array[String]) + end + # Add it to the file - block.add(text) + blocks.last.add(text) end # used to generate distinct names @@ -68,12 +74,18 @@ class NitUnitExecutor # Fill the prepated `tc` (testcase) XTM node fun extract(ndoc: ADoc, tc: HTMLTag) do - block.clear + blocks.clear work(ndoc.to_mdoc) - if block.is_empty then return + if blocks.is_empty then return + for block in blocks do test_block(ndoc, tc, block) + end + + # Execute a block + fun test_block(ndoc: ADoc, tc: HTMLTag, block: Array[String]) + do toolcontext.modelbuilder.unit_entities += 1 cpt += 1 -- 1.7.9.5