tests: Fix tests
[nit.git] / src / doc / commands / tests / test_commands_model.nit
index 901dd3e..0ee6952 100644 (file)
@@ -24,28 +24,28 @@ class TestCommandsModel
        # CmdEntity
 
        fun test_cmd_entity is test do
-               var cmd = new CmdEntity(test_view, mentity_name = "test_prog::Character")
+               var cmd = new CmdEntity(test_model, mentity_name = "test_prog::Character")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.mentity.as(not null).full_name == "test_prog::Character"
        end
 
        fun test_cmd_entity_not_found is test do
-               var cmd = new CmdEntity(test_view, mentity_name = "test_prog::Characterzz")
+               var cmd = new CmdEntity(test_model, mentity_name = "test_prog::Characterz")
                var res = cmd.init_command
                assert res isa ErrorMEntityNotFound
                assert res.suggestions.first.full_name == "test_prog::Character"
        end
 
        fun test_cmd_entity_conflict is test do
-               var cmd = new CmdEntity(test_view, mentity_name = "+")
+               var cmd = new CmdEntity(test_model, mentity_name = "+")
                var res = cmd.init_command
                assert res isa ErrorMEntityConflict
                assert res.conflicts.length == 2
        end
 
        fun test_cmd_entity_no_name is test do
-               var cmd = new CmdEntity(test_view)
+               var cmd = new CmdEntity(test_model)
                var res = cmd.init_command
                assert res isa ErrorMEntityNoName
        end
@@ -53,14 +53,14 @@ class TestCommandsModel
        # CmdComment
 
        fun test_cmd_comment is test do
-               var cmd = new CmdComment(test_view, mentity_name = "test_prog::Character")
+               var cmd = new CmdComment(test_model, mentity_name = "test_prog::Character")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.mdoc != null
        end
 
        fun test_cmd_comment_no_mdoc is test do
-               var cmd = new CmdComment(test_view, mentity_name = "test_prog::Character", fallback = false)
+               var cmd = new CmdComment(test_model, mentity_name = "test_prog::Character", fallback = false)
                var res = cmd.init_command
                assert res isa WarningNoMDoc
        end
@@ -68,7 +68,7 @@ class TestCommandsModel
        # CmdLink
 
        fun test_cmd_link is test do
-               var cmd = new CmdEntityLink(test_view, mentity_name = "test_prog::Character")
+               var cmd = new CmdEntityLink(test_model, mentity_name = "test_prog::Character")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.text == "Character"
@@ -76,7 +76,7 @@ class TestCommandsModel
        end
 
        fun test_cmd_link_with_text is test do
-               var cmd = new CmdEntityLink(test_view, mentity_name = "test_prog::Character", text = "foo")
+               var cmd = new CmdEntityLink(test_model, mentity_name = "test_prog::Character", text = "foo")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.text == "foo"
@@ -84,7 +84,7 @@ class TestCommandsModel
        end
 
        fun test_cmd_link_with_title is test do
-               var cmd = new CmdEntityLink(test_view, mentity_name = "test_prog::Character", title = "bar")
+               var cmd = new CmdEntityLink(test_model, mentity_name = "test_prog::Character", title = "bar")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.text == "Character"
@@ -92,7 +92,7 @@ class TestCommandsModel
        end
 
        fun test_cmd_link_with_text_and_title is test do
-               var cmd = new CmdEntityLink(test_view, mentity_name = "test_prog::Character",
+               var cmd = new CmdEntityLink(test_model, mentity_name = "test_prog::Character",
                        text = "foo", title = "bar")
                var res = cmd.init_command
                assert res isa CmdSuccess
@@ -103,35 +103,58 @@ class TestCommandsModel
        # CmdInheritance
 
        fun test_cmd_parents is test do
-               var cmd = new CmdParents(test_view, mentity_name = "test_prog::Warrior")
+               var cmd = new CmdParents(test_model, test_main, mentity_name = "test_prog::Warrior")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 1
        end
 
        fun test_cmd_ancestors is test do
-               var cmd = new CmdAncestors(test_view, mentity_name = "test_prog::Warrior")
+               var cmd = new CmdAncestors(test_model, test_main, mentity_name = "test_prog::Warrior")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 2
        end
 
-       fun test_cmd_ancestorsi_without_parents is test do
-               var cmd = new CmdAncestors(test_view, mentity_name = "test_prog::Warrior", parents = false)
+       fun test_cmd_ancestors_without_parents is test do
+               var cmd = new CmdAncestors(test_model, test_main, mentity_name = "test_prog::Warrior", parents = false)
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 1
        end
 
        fun test_cmd_children is test do
-               var cmd = new CmdChildren(test_view, mentity_name = "test_prog::Career")
+               var cmd = new CmdChildren(test_model, test_main, mentity_name = "test_prog::Career")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 3
        end
 
+       fun test_cmd_children_without_filter is test do
+               var cmd = new CmdDescendants(test_model, test_main, mentity_name = "test_prog::Game")
+               var res = cmd.init_command
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).length == 2
+       end
+
+       fun test_cmd_children_with_filter_example is test do
+               var filter = new ModelFilter(accept_example = false)
+               var cmd = new CmdDescendants(test_model, test_main, filter, mentity_name = "test_prog::Game")
+               var res = cmd.init_command
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).length == 1
+       end
+
+       fun test_cmd_children_with_filter_match is test do
+               var filter = new ModelFilter(accept_full_name = "MyGame")
+               var cmd = new CmdDescendants(test_model, test_main, filter, mentity_name = "test_prog::Game")
+               var res = cmd.init_command
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).length == 1
+       end
+
        fun test_cmd_descendants is test do
-               var cmd = new CmdDescendants(test_view, mentity_name = "test_prog::Career", children = false)
+               var cmd = new CmdDescendants(test_model, test_main, mentity_name = "test_prog::Career", children = false)
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 0
@@ -140,14 +163,14 @@ class TestCommandsModel
        # CmdSearch
 
        fun test_cmd_search is test do
-               var cmd = new CmdSearch(test_view, query = "Carer")
+               var cmd = new CmdSearch(test_model, query = "Carer")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.results.as(not null).first.full_name == "test_prog::Career"
        end
 
        fun test_cmd_search_no_query is test do
-               var cmd = new CmdSearch(test_view)
+               var cmd = new CmdSearch(test_model)
                var res = cmd.init_command
                assert res isa ErrorNoQuery
        end
@@ -155,14 +178,47 @@ class TestCommandsModel
        # CmdFeatures
 
        fun test_cmd_features is test do
-               var cmd = new CmdFeatures(test_view, mentity_name = "test_prog::Career")
+               var cmd = new CmdFeatures(test_model, mentity_name = "test_prog::Career")
+               var res = cmd.init_command
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).length == 11
+       end
+
+       fun test_cmd_features_with_filter_attribute is test do
+               var filter = new ModelFilter(accept_attribute = false)
+               var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::Career")
                var res = cmd.init_command
                assert res isa CmdSuccess
-               assert cmd.results.as(not null).length == 10
+               assert cmd.results.as(not null).length == 8
+       end
+
+       fun test_cmd_features_with_filter_public is test do
+               var filter = new ModelFilter(min_visibility = public_visibility)
+               var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::Career")
+               var res = cmd.init_command
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).length == 5
+       end
+
+       fun test_cmd_features_with_filter_match is test do
+               var filter = new ModelFilter(accept_full_name = "endurance")
+               var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::Career")
+               var res = cmd.init_command
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).length == 3
+       end
+
+       fun test_cmd_features_with_filter_inh is test do
+               var context = test_model.mentity_by_full_name("test_prog::TestGame").as(not null)
+               var filter = new ModelFilter(accept_inherited = context)
+               var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::TestGame")
+               var res = cmd.init_command
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).length == 4
        end
 
        fun test_cmd_features_no_features is test do
-               var cmd = new CmdFeatures(test_view, mentity_name = "test_prog$Career$strength_bonus")
+               var cmd = new CmdFeatures(test_model, mentity_name = "test_prog$Career$strength_bonus")
                var res = cmd.init_command
                assert res isa WarningNoFeatures
        end
@@ -170,15 +226,14 @@ class TestCommandsModel
        # CmdLinearization
 
        fun test_cmd_lin is test do
-               var cmd = new CmdLinearization(test_view, mentity_name = "init")
+               var cmd = new CmdLinearization(test_model, test_main, mentity_name = "init")
                var res = cmd.init_command
                assert res isa CmdSuccess
-               print cmd.results.as(not null)
-               assert cmd.results.as(not null).length == 10
+               assert cmd.results.as(not null).length == 9
        end
 
        fun test_cmd_lin_no_lin is test do
-               var cmd = new CmdLinearization(test_view, mentity_name = "test_prog")
+               var cmd = new CmdLinearization(test_model, test_main, mentity_name = "test_prog")
                var res = cmd.init_command
                assert res isa WarningNoLinearization
        end
@@ -186,14 +241,14 @@ class TestCommandsModel
        # CmdCode
 
        fun test_cmd_code is test do
-               var cmd = new CmdEntityCode(test_view, test_builder, mentity_name = "test_prog::Career")
+               var cmd = new CmdEntityCode(test_model, test_builder, mentity_name = "test_prog::Career")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.node isa AStdClassdef
        end
 
        fun test_cmd_code_no_code is test do
-               var cmd = new CmdEntityCode(test_view, test_builder, mentity_name = "test_prog")
+               var cmd = new CmdEntityCode(test_model, test_builder, mentity_name = "test_prog")
                var res = cmd.init_command
                assert res isa WarningNoCode
        end
@@ -201,14 +256,23 @@ class TestCommandsModel
        # CmdModel
 
        fun test_cmd_results is test do
-               var cmd = new CmdModelEntities(test_view, kind = "modules")
+               var cmd = new CmdModelEntities(test_model, kind = "modules")
                var res = cmd.init_command
                assert res isa CmdSuccess
-               assert cmd.results.as(not null).length == 10
+               assert cmd.results.as(not null).length == 11
+       end
+
+       fun test_cmd_results_with_filter is test do
+               var filter = new ModelFilter(accept_test = false, accept_example = false)
+               var cmd = new CmdModelEntities(test_model, filter, kind = "modules")
+               var res = cmd.init_command
+               assert res isa CmdSuccess
+               print cmd.results.as(not null)
+               assert cmd.results.as(not null).length == 9
        end
 
        fun test_cmd_results_random is test do
-               var cmd = new CmdRandomEntities(test_view, kind = "packages")
+               var cmd = new CmdRandomEntities(test_model, kind = "packages")
                var res = cmd.init_command
                assert res isa CmdSuccess
                assert cmd.results.as(not null).length == 2