From 8a92345af5981de195627d9f8c6bdb5c119a7b88 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 15 May 2018 12:51:48 -0400 Subject: [PATCH] doc/commands: test commands with filters Signed-off-by: Alexandre Terrasa --- src/doc/commands/tests/test_commands.nit | 1 + src/doc/commands/tests/test_commands_catalog.nit | 17 ++++++ src/doc/commands/tests/test_commands_model.nit | 67 +++++++++++++++++++++- 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/doc/commands/tests/test_commands.nit b/src/doc/commands/tests/test_commands.nit index d9d6564..24d1593 100644 --- a/src/doc/commands/tests/test_commands.nit +++ b/src/doc/commands/tests/test_commands.nit @@ -17,6 +17,7 @@ module test_commands import commands_base import frontend +import frontend::parse_examples # Nitunit test suite specific to commands class TestCommands diff --git a/src/doc/commands/tests/test_commands_catalog.nit b/src/doc/commands/tests/test_commands_catalog.nit index 12389f2..ecb038c 100644 --- a/src/doc/commands/tests/test_commands_catalog.nit +++ b/src/doc/commands/tests/test_commands_catalog.nit @@ -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 diff --git a/src/doc/commands/tests/test_commands_model.nit b/src/doc/commands/tests/test_commands_model.nit index d61bde0..4909823 100644 --- a/src/doc/commands/tests/test_commands_model.nit +++ b/src/doc/commands/tests/test_commands_model.nit @@ -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 -- 1.7.9.5