From: Jean Privat Date: Mon, 17 Nov 2014 22:55:29 +0000 (-0500) Subject: Merge: Misc fixes and improvements from WBTW X-Git-Tag: v0.6.11~30 X-Git-Url: http://nitlanguage.org?hp=8cf51fcd69ffcdfe7e81db79c7dc8fe7742b0996 Merge: Misc fixes and improvements from WBTW Pull-Request: #915 Reviewed-by: Jean Privat Reviewed-by: Lucas Bajolet --- diff --git a/lib/standard/collection/union_find.nit b/lib/standard/collection/union_find.nit index e865703..f9ac76f 100644 --- a/lib/standard/collection/union_find.nit +++ b/lib/standard/collection/union_find.nit @@ -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` diff --git a/src/markdown.nit b/src/markdown.nit index 01a054c..e254480 100644 --- a/src/markdown.nit +++ b/src/markdown.nit @@ -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 diff --git a/src/modelbuilder.nit b/src/modelbuilder.nit index 83f5e0e..1ae7e45 100644 --- a/src/modelbuilder.nit +++ b/src/modelbuilder.nit @@ -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 diff --git a/src/testing/testing_doc.nit b/src/testing/testing_doc.nit index f393950..7bb39ca 100644 --- a/src/testing/testing_doc.nit +++ b/src/testing/testing_doc.nit @@ -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 index 0000000..2e76488 --- /dev/null +++ b/tests/base_import_standard.nit @@ -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 index 0000000..da5111e --- /dev/null +++ b/tests/base_import_standard2.nit @@ -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 diff --git a/tests/nitunit.args b/tests/nitunit.args index cc7239d..70d5027 100644 --- a/tests/nitunit.args +++ b/tests/nitunit.args @@ -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 index 0000000..d00491f --- /dev/null +++ b/tests/sav/base_import_standard.res @@ -0,0 +1 @@ +1 diff --git a/tests/sav/base_import_standard2.res b/tests/sav/base_import_standard2.res new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/tests/sav/base_import_standard2.res @@ -0,0 +1 @@ +2 diff --git a/tests/sav/nitunit_args1.res b/tests/sav/nitunit_args1.res index 3a07d20..12b7181 100644 --- a/tests/sav/nitunit_args1.res +++ b/tests/sav/nitunit_args1.res @@ -1,6 +1,6 @@ -test_nitunit.nit:20,1--22,0: ERROR: nitunit.test_nitunit.test_nitunit::X. (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. (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 assert true assert false -assert undefined_identifier -outoutout \ No newline at end of file diff --git a/tests/sav/nitunit_args4.res b/tests/sav/nitunit_args4.res new file mode 100644 index 0000000..faaa0c9 --- /dev/null +++ b/tests/sav/nitunit_args4.res @@ -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 +if true then + + assert true + +end +if true then + + assert true + +end +var a = 1 +assert a == 1 +assert a == 1 + \ No newline at end of file diff --git a/tests/test_nitunit2.nit b/tests/test_nitunit2.nit new file mode 100644 index 0000000..899ff94 --- /dev/null +++ b/tests/test_nitunit2.nit @@ -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