doc/commands: test commands with filters
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 15 May 2018 16:51:48 +0000 (12:51 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 21 Jun 2018 00:45:30 +0000 (20:45 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/commands/tests/test_commands.nit
src/doc/commands/tests/test_commands_catalog.nit
src/doc/commands/tests/test_commands_model.nit

index d9d6564..24d1593 100644 (file)
@@ -17,6 +17,7 @@ module test_commands
 
 import commands_base
 import frontend
+import frontend::parse_examples
 
 # Nitunit test suite specific to commands
 class TestCommands
index 12389f2..ecb038c 100644 (file)
@@ -64,6 +64,23 @@ class TestCommandsCatalog
                assert cmd.results.as(not null).first isa MPackage
        end
 
+       fun test_cmd_catalog_search_without_filter is test do
+               var cmd = new CmdCatalogSearch(test_model, test_catalog, query = "MyGame")
+               var res = cmd.init_command
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).first.full_name == "test_prog::MyGame"
+               assert cmd.results.as(not null).first isa MClass
+       end
+
+       fun test_cmd_catalog_search_with_filter is test do
+               var filter = new ModelFilter(accept_example = false)
+               var cmd = new CmdCatalogSearch(test_model, test_catalog, filter, query = "MyGame")
+               var res = cmd.init_command
+               assert res isa CmdSuccess
+               assert cmd.results.as(not null).first.full_name == "test_prog::Game" # not MyGame
+               assert cmd.results.as(not null).first isa MClass
+       end
+
        fun test_cmd_catalog_stats is test do
                var cmd = new CmdCatalogStats(test_model, test_catalog)
                var res = cmd.init_command
index d61bde0..4909823 100644 (file)
@@ -130,6 +130,29 @@ class TestCommandsModel
                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_model, test_main, mentity_name = "test_prog::Career", children = false)
                var res = cmd.init_command
@@ -161,6 +184,39 @@ class TestCommandsModel
                assert cmd.results.as(not null).length == 10
        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 == 7
+       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 == 4
+       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 == 3
+       end
+
        fun test_cmd_features_no_features is test do
                var cmd = new CmdFeatures(test_model, mentity_name = "test_prog$Career$strength_bonus")
                var res = cmd.init_command
@@ -203,7 +259,16 @@ class TestCommandsModel
                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