doc/commands: render `commands_main` as JSON
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 2 May 2018 23:20:39 +0000 (19:20 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 10 May 2018 20:35:10 +0000 (16:35 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/commands/commands_json.nit
src/doc/commands/tests/test_commands_json.nit
src/doc/commands/tests/test_commands_json.sav/test_cmd_main_compile.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_json.sav/test_cmd_mains.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_json.sav/test_cmd_man_options.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_json.sav/test_cmd_man_synopsis.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_json.sav/test_cmd_testing.res [new file with mode: 0644]

index 82571cc..b109c87 100644 (file)
@@ -20,6 +20,7 @@ import commands::commands_graph
 import commands::commands_usage
 import commands::commands_catalog
 import commands::commands_ini
+import commands::commands_main
 
 import templates::templates_json
 import catalog::catalog_json
@@ -252,3 +253,45 @@ redef class CmdContribFileContent
                return obj
        end
 end
+
+# CmdMain
+
+redef class CmdMains
+       redef fun to_json do
+               var obj = new JsonObject
+               obj["results"] = results
+               return obj
+       end
+end
+
+redef class CmdMainCompile
+       redef fun to_json do
+               var obj = new JsonObject
+               obj["command"] = command
+               return obj
+       end
+end
+
+redef class CmdTesting
+       redef fun to_json do
+               var obj = new JsonObject
+               obj["command"] = command
+               return obj
+       end
+end
+
+redef class CmdManSynopsis
+       redef fun to_json do
+               var obj = new JsonObject
+               obj["synopsis"] = synopsis
+               return obj
+       end
+end
+
+redef class CmdManOptions
+       redef fun to_json do
+               var obj = new JsonObject
+               obj["options"] = options
+               return obj
+       end
+end
index c5bdd10..2d55a3d 100644 (file)
@@ -15,6 +15,7 @@
 module test_commands_json is test
 
 import test_commands
+intrude import doc::commands::commands_main
 import doc::commands::commands_json
 
 class TestCommandsJson
@@ -201,6 +202,38 @@ class TestCommandsJson
                cmd.file = cmd.file.as(not null).basename # for testing path
                print_json cmd.to_json
        end
+
+       # CmdMain
+
+       fun test_cmd_mains is test do
+               var cmd = new CmdMains(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_json cmd.to_json
+       end
+
+       fun test_cmd_main_compile is test do
+               var cmd = new CmdMainCompile(test_view, mentity_name = "test_prog::test_prog")
+               cmd.init_command
+               print_json cmd.to_json
+       end
+
+       fun test_cmd_testing is test do
+               var cmd = new CmdTesting(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_json cmd.to_json
+       end
+
+       fun test_cmd_man_synopsis is test do
+               var cmd = new CmdManSynopsis(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_json cmd.to_json
+       end
+
+       fun test_cmd_man_options is test do
+               var cmd = new CmdManOptions(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_json cmd.to_json
+       end
 end
 
 redef class nitc::Location
@@ -218,3 +251,20 @@ redef class nitc::Location
                end
        end
 end
+
+# Avoid path diff
+redef class CmdMainCompile
+       redef fun test_path(file) do
+               if file == null then return null
+               return file.filename.basename
+       end
+end
+
+# Avoid path diff
+redef class CmdTesting
+       redef fun test_path(mentity) do
+               var file = mentity.location.file
+               if file == null then return null
+               return file.filename.basename
+       end
+end
diff --git a/src/doc/commands/tests/test_commands_json.sav/test_cmd_main_compile.res b/src/doc/commands/tests/test_commands_json.sav/test_cmd_main_compile.res
new file mode 100644 (file)
index 0000000..2c5663c
--- /dev/null
@@ -0,0 +1,3 @@
+{
+       "command": "nitc test_prog.nit"
+}
diff --git a/src/doc/commands/tests/test_commands_json.sav/test_cmd_mains.res b/src/doc/commands/tests/test_commands_json.sav/test_cmd_mains.res
new file mode 100644 (file)
index 0000000..529d91b
--- /dev/null
@@ -0,0 +1,18 @@
+{
+       "results": [{
+               "name": "test_prog",
+               "synopsis": "A test program with a fake model to check model tools.",
+               "namespace": [{
+                       "name": "test_prog",
+                       "synopsis": "Test program for model tools."
+               }, "::", {
+                       "name": "test_prog",
+                       "synopsis": "A test program with a fake model to check model tools."
+               }],
+               "class_name": "MModule",
+               "full_name": "test_prog::test_prog",
+               "visibility": "public",
+               "html_synopsis": "<span class=\"synopsys nitdoc\">A test program with a fake model to check model tools.</span>",
+               "modifiers": ["module"]
+       }]
+}
diff --git a/src/doc/commands/tests/test_commands_json.sav/test_cmd_man_options.res b/src/doc/commands/tests/test_commands_json.sav/test_cmd_man_options.res
new file mode 100644 (file)
index 0000000..3253e3a
--- /dev/null
@@ -0,0 +1,6 @@
+{
+       "options": {
+               "--opt1": "Option 1.",
+               "--opt2": "Option 2."
+       }
+}
diff --git a/src/doc/commands/tests/test_commands_json.sav/test_cmd_man_synopsis.res b/src/doc/commands/tests/test_commands_json.sav/test_cmd_man_synopsis.res
new file mode 100644 (file)
index 0000000..c7ff136
--- /dev/null
@@ -0,0 +1,3 @@
+{
+       "synopsis": "test_prog [*options*] ARGS..."
+}
diff --git a/src/doc/commands/tests/test_commands_json.sav/test_cmd_testing.res b/src/doc/commands/tests/test_commands_json.sav/test_cmd_testing.res
new file mode 100644 (file)
index 0000000..b46dce7
--- /dev/null
@@ -0,0 +1,3 @@
+{
+       "command": "nitunit tests"
+}