Merge: Misc fixes and improvements from WBTW
authorJean Privat <jean@pryen.org>
Mon, 17 Nov 2014 22:55:29 +0000 (17:55 -0500)
committerJean Privat <jean@pryen.org>
Mon, 17 Nov 2014 22:55:29 +0000 (17:55 -0500)
Pull-Request: #915
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

12 files changed:
lib/standard/collection/union_find.nit
src/markdown.nit
src/modelbuilder.nit
src/testing/testing_doc.nit
tests/base_import_standard.nit [new file with mode: 0644]
tests/base_import_standard2.nit [new file with mode: 0644]
tests/nitunit.args
tests/sav/base_import_standard.res [new file with mode: 0644]
tests/sav/base_import_standard2.res [new file with mode: 0644]
tests/sav/nitunit_args1.res
tests/sav/nitunit_args4.res [new file with mode: 0644]
tests/test_nitunit2.nit [new file with mode: 0644]

index e865703..f9ac76f 100644 (file)
@@ -37,6 +37,17 @@ class DisjointSet[E: Object]
        # The node in the hiearchical structure for each element
        private var nodes = new HashMap[E, DisjointSetNode]
 
+       # The number of subsets in the partition
+       #
+       #     var s = new DisjointSet[Int]
+       #     s.add_all([1,2,3,4,5])
+       #     assert s.number_of_subsets == 5
+       #     s.union_all([1,4,5])
+       #     assert s.number_of_subsets == 3
+       #     s.union(4,5)
+       #     assert s.number_of_subsets == 3
+       var number_of_subsets: Int = 0
+
        # Get the root node of an element
        # require: `has(e)`
        private fun find(e:E): DisjointSetNode
@@ -84,6 +95,7 @@ class DisjointSet[E: Object]
                if nodes.has_key(e) then return
                var ne = new DisjointSetNode
                nodes[e] = ne
+               number_of_subsets += 1
        end
 
        # Are two elements in the same subset?
@@ -171,6 +183,7 @@ class DisjointSet[E: Object]
                                ne.rank = er+1
                        end
                end
+               number_of_subsets -= 1
        end
 
        # Combine the subsets of all elements of `es`
index 01a054c..e254480 100644 (file)
@@ -27,6 +27,9 @@ private class Doc2Mdwn
        # The lines of the current code block, empty is no current code block
        var curblock = new Array[String]
 
+       # Count empty lines between code blocks
+       var empty_lines = 0
+
        fun work(mdoc: MDoc): HTMLTag
        do
                var root = new HTMLTag("div")
@@ -70,16 +73,18 @@ private class Doc2Mdwn
 
                        # Is codeblock? Then just collect them
                        if indent >= 3 then
+                               for i in [0..empty_lines[ do curblock.add("")
+                               empty_lines = 0
                                # to allows 4 spaces including the one that follows the #
                                curblock.add(text)
                                continue
                        end
 
-                       # Was a codblock just before the current line ?
-                       close_codeblock(n or else root)
-
                        # fence opening
                        if text.substring(0,3) == "~~~" then
+                               # Was a codblock just before the current line ?
+                               close_codeblock(n or else root)
+
                                var l = 3
                                while l < text.length and text.chars[l] == '~' do l += 1
                                in_fence = text.substring(0, l)
@@ -96,9 +101,15 @@ private class Doc2Mdwn
                        if text.is_empty or indent < lastindent then
                                n = null
                                ul = null
-                               if text.is_empty then continue
+                               if text.is_empty then
+                                       if not curblock.is_empty then empty_lines += 1
+                                       continue
+                               end
                        end
 
+                       # Was a codblock just before the current line ?
+                       close_codeblock(n or else root)
+
                        # Special first word: new paragraph
                        if text.has_prefix("TODO") or text.has_prefix("FIXME") then
                                n = new HTMLTag("p")
@@ -186,15 +197,20 @@ private class Doc2Mdwn
        do
                # Is there a codeblock to manage?
                if not curblock.is_empty then
+                       empty_lines = 0
+
                        # determine the smalest indent
                        var minindent = -1
                        for text in curblock do
                                var indent = 0
                                while indent < text.length and text.chars[indent] == ' ' do indent += 1
+                               # skip white lines
+                               if indent >= text.length then continue
                                if minindent == -1 or indent < minindent then
                                        minindent = indent
                                end
                        end
+                       if minindent < 0 then minindent = 0
 
                        # Generate the text
                        var btext = new FlatBuffer
index 83f5e0e..1ae7e45 100644 (file)
@@ -705,6 +705,13 @@ class ModelBuilder
                self.toolcontext.info("{mmodule} imports {imported_modules.join(", ")}", 3)
                mmodule.set_imported_mmodules(imported_modules)
 
+               # Force standard to be public if imported
+               for sup in mmodule.in_importation.greaters do
+                       if sup.name == "standard" then
+                               mmodule.set_visibility_for(sup, public_visibility)
+                       end
+               end
+
                # TODO: Correctly check for useless importation
                # It is even doable?
                var directs = mmodule.in_importation.direct_greaters
index f393950..7bb39ca 100644 (file)
@@ -36,6 +36,9 @@ class NitUnitExecutor
 
        redef fun process_code(n: HTMLTag, text: String)
        do
+               # Skip non-blocks
+               if n.tag != "pre" then return
+
                # Try to parse it
                var ast = toolcontext.parse_something(text)
 
@@ -98,7 +101,7 @@ class NitUnitExecutor
                toolcontext.modelbuilder.unit_entities += 1
 
                cpt += 1
-               var file = "{prefix}{cpt}.nit"
+               var file = "{prefix}-{cpt}.nit"
 
                toolcontext.info("Execute doc-unit {tc.attrs["name"]} in {file}", 1)
 
diff --git a/tests/base_import_standard.nit b/tests/base_import_standard.nit
new file mode 100644 (file)
index 0000000..2e76488
--- /dev/null
@@ -0,0 +1,17 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+private import template
+
+print 1
diff --git a/tests/base_import_standard2.nit b/tests/base_import_standard2.nit
new file mode 100644 (file)
index 0000000..da5111e
--- /dev/null
@@ -0,0 +1,17 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import base_import_standard
+
+print 2
index cc7239d..70d5027 100644 (file)
@@ -1,3 +1,4 @@
 test_nitunit.nit --no-color -o $WRITE
 test_nitunit.nit --gen-suite --only-show
 test_nitunit.nit --gen-suite --only-show --private
+test_nitunit2.nit -o $WRITE
diff --git a/tests/sav/base_import_standard.res b/tests/sav/base_import_standard.res
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
diff --git a/tests/sav/base_import_standard2.res b/tests/sav/base_import_standard2.res
new file mode 100644 (file)
index 0000000..0cfbf08
--- /dev/null
@@ -0,0 +1 @@
+2
index 3a07d20..12b7181 100644 (file)
@@ -1,6 +1,6 @@
-test_nitunit.nit:20,1--22,0: ERROR: nitunit.test_nitunit.test_nitunit::X.<class> (in .nitunit/test_nitunit2.nit): Runtime error: Assert failed (.nitunit/test_nitunit2.nit:5)
+test_nitunit.nit:20,1--22,0: ERROR: nitunit.test_nitunit.test_nitunit::X.<class> (in .nitunit/test_nitunit-2.nit): Runtime error: Assert failed (.nitunit/test_nitunit-2.nit:5)
 
-test_nitunit.nit:23,2--25,0: FAILURE: nitunit.test_nitunit.test_nitunit::X.test_nitunit::X::foo (in .nitunit/test_nitunit3.nit): .nitunit/test_nitunit3.nit:5,8--27: Error: Method or variable 'undefined_identifier' unknown in Sys.
+test_nitunit.nit:23,2--25,0: FAILURE: nitunit.test_nitunit.test_nitunit::X.test_nitunit::X::foo (in .nitunit/test_nitunit-3.nit): .nitunit/test_nitunit-3.nit:5,8--27: Error: Method or variable 'undefined_identifier' unknown in Sys.
 
 test_test_nitunit.nit:36,2--40,4: ERROR: test_foo1 (in file .nitunit/test_test_nitunit_TestX_test_foo1.nit): Runtime error: Assert failed (test_test_nitunit.nit:39)
 
@@ -11,8 +11,8 @@ TestSuites:
 Class suites: 1; Test Cases: 3; Failures: 1
 <testsuites><testsuite package="test_nitunit"><testcase classname="nitunit.test_nitunit.&lt;module&gt;" name="&lt;module&gt;"><system-err></system-err><system-out>assert true
 </system-out></testcase><testcase classname="nitunit.test_nitunit.test_nitunit::X" name="&lt;class&gt;"><system-err></system-err><system-out>assert false
-</system-out><error message="Runtime error: Assert failed (.nitunit/test_nitunit2.nit:5)
+</system-out><error message="Runtime error: Assert failed (.nitunit/test_nitunit-2.nit:5)
 "></error></testcase><testcase classname="nitunit.test_nitunit.test_nitunit::X" name="test_nitunit::X::foo"><system-err></system-err><system-out>assert undefined_identifier
-</system-out><failure message=".nitunit/test_nitunit3.nit:5,8--27: Error: Method or variable 'undefined_identifier' unknown in Sys.
+</system-out><failure message=".nitunit/test_nitunit-3.nit:5,8--27: Error: Method or variable 'undefined_identifier' unknown in Sys.
 "></failure></testcase></testsuite><testsuite package="test_test_nitunit"><testcase classname="nitunit.test_test_nitunit.test_test_nitunit::TestX" name="test_test_nitunit::TestX::test_foo"><system-err></system-err><system-out>out</system-out></testcase><testcase classname="nitunit.test_test_nitunit.test_test_nitunit::TestX" name="test_test_nitunit::TestX::test_foo1"><system-err></system-err><system-out>out</system-out><error message="Runtime error: Assert failed (test_test_nitunit.nit:39)
 "></error></testcase><testcase classname="nitunit.test_test_nitunit.test_test_nitunit::TestX" name="test_test_nitunit::TestX::test_foo2"><system-err></system-err><system-out>out</system-out></testcase></testsuite></testsuites>
\ No newline at end of file
diff --git a/tests/sav/nitunit_args4.res b/tests/sav/nitunit_args4.res
new file mode 100644 (file)
index 0000000..faaa0c9
--- /dev/null
@@ -0,0 +1,21 @@
+DocUnits:
+DocUnits Success
+Entities: 4; Documented ones: 3; With nitunits: 3; Failures: 0
+
+TestSuites:
+No test cases found
+Class suites: 0; Test Cases: 0; Failures: 0
+<testsuites><testsuite package="test_nitunit2"><testcase classname="nitunit.test_nitunit2.standard::kernel::Object" name="test_nitunit2::Object::foo1"><system-err></system-err><system-out>if true then
+
+   assert true
+
+end
+</system-out></testcase><testcase classname="nitunit.test_nitunit2.standard::kernel::Object" name="test_nitunit2::Object::bar2"><system-err></system-err><system-out>if true then
+
+    assert true
+
+end
+</system-out></testcase><testcase classname="nitunit.test_nitunit2.standard::kernel::Object" name="test_nitunit2::Object::foo3"><system-err></system-err><system-out>var a = 1
+assert a == 1
+assert a == 1
+</system-out></testcase></testsuite><testsuite></testsuite></testsuites>
\ No newline at end of file
diff --git a/tests/test_nitunit2.nit b/tests/test_nitunit2.nit
new file mode 100644 (file)
index 0000000..899ff94
--- /dev/null
@@ -0,0 +1,43 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# a fence unit
+#
+# ~~~~
+# if true then
+#
+#    assert true
+#
+# end
+# ~~~~
+fun foo1 do end
+
+# a block unit
+#
+#    if true then
+#
+#        assert true
+#
+#    end
+fun bar2 do end
+
+# a context continuation
+#
+#    var a = 1
+#    assert a == 1
+#
+# bla bla
+#
+#    assert a == 1
+fun foo3 do end