benry-cmdapp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/func_test.rb ADDED
@@ -0,0 +1,137 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'oktest'
4
+
5
+ require 'benry/cmdapp'
6
+ require_relative './shared'
7
+
8
+
9
+ Oktest.scope do
10
+
11
+
12
+ topic Benry::CmdApp do
13
+
14
+
15
+ topic '.delete_action()' do
16
+
17
+ spec "[!era7d] deletes action." do
18
+ class DeleteAction2Test < Benry::CmdApp::ActionScope
19
+ @action.("test")
20
+ def delaction2(); end
21
+ end
22
+ #
23
+ pr = proc {
24
+ class DeleteAction2Test
25
+ @action.("test")
26
+ def delaction2(); end
27
+ end
28
+ }
29
+ ok {pr}.raise?(Benry::CmdApp::ActionDefError,
30
+ "def delaction2(): Action 'delaction2' already exist.")
31
+ #
32
+ Benry::CmdApp.delete_action("delaction2")
33
+ ok {pr}.NOT.raise?(Exception)
34
+ end
35
+
36
+ spec "[!ifaj1] raises error if action not exist." do
37
+ pr = proc { Benry::CmdApp.delete_action("delaction91") }
38
+ ok {pr}.raise?(Benry::CmdApp::ActionNotFoundError,
39
+ "delete_action(\"delaction91\"): Action not found.")
40
+ end
41
+
42
+ end
43
+
44
+
45
+ topic '.delete_alias()' do
46
+
47
+ spec "[!9g0x9] deletes alias." do
48
+ class DeleteAlias2Test < Benry::CmdApp::ActionScope
49
+ @action.("test")
50
+ def delalias2(); end
51
+ end
52
+ Benry::CmdApp.action_alias("delali2", "delalias2")
53
+ #
54
+ pr = proc {
55
+ Benry::CmdApp.action_alias("delali2", "delalias2")
56
+ }
57
+ ok {pr}.raise?(Benry::CmdApp::AliasDefError,
58
+ "action_alias(\"delali2\", \"delalias2\"): Alias name duplicated.")
59
+ #
60
+ Benry::CmdApp.delete_alias("delali2")
61
+ ok {pr}.NOT.raise?(Exception)
62
+ end
63
+
64
+ spec "[!r49vi] raises error if alias not exist." do
65
+ pr = proc { Benry::CmdApp.delete_alias("delalias91") }
66
+ ok {pr}.raise?(Benry::CmdApp::ActionNotFoundError,
67
+ "delete_alias(\"delalias91\"): Alias not found.")
68
+ end
69
+
70
+ end
71
+
72
+
73
+ topic '.action_alias()' do
74
+
75
+ class Alias1Test < Benry::CmdApp::ActionScope
76
+ prefix "alias1"
77
+ @action.("alias test")
78
+ def a1(); end
79
+ @action.("alias test")
80
+ def a2(); end
81
+ end
82
+
83
+ spec "[!vzlrb] registers alias name with action name." do
84
+ Benry::CmdApp.action_alias("a4", "alias1:a1")
85
+ ok {Benry::CmdApp::INDEX.alias_exist?("a4")} == true
86
+ ok {Benry::CmdApp::INDEX.get_alias("a4").alias_name} == "a4"
87
+ ok {Benry::CmdApp::INDEX.get_alias("a4").action_name} == "alias1:a1"
88
+ end
89
+
90
+ spec "[!0cq6o] supports args." do
91
+ Benry::CmdApp.action_alias("a8", "alias1:a1", "Alice", "-l", "it")
92
+ ok {Benry::CmdApp::INDEX.alias_exist?("a8")} == true
93
+ ok {Benry::CmdApp::INDEX.get_alias("a8").alias_name} == "a8"
94
+ ok {Benry::CmdApp::INDEX.get_alias("a8").action_name} == "alias1:a1"
95
+ ok {Benry::CmdApp::INDEX.get_alias("a8").args} == ["Alice", "-l", "it"]
96
+ end
97
+
98
+ spec "[!4wtxj] supports 'tag:' keyword arg." do
99
+ Benry::CmdApp.action_alias("a7", "alias1:a1", tag: :important)
100
+ ok {Benry::CmdApp::INDEX.alias_exist?("a7")} == true
101
+ ok {Benry::CmdApp::INDEX.get_alias("a7").action_name} == "alias1:a1"
102
+ ok {Benry::CmdApp::INDEX.get_alias("a7").tag} == :important
103
+ end
104
+
105
+ spec "[!5immb] convers both alias name and action name into string." do
106
+ Benry::CmdApp.action_alias(:a5, :'alias1:a2')
107
+ ok {Benry::CmdApp::INDEX.alias_exist?("a5")} == true
108
+ ok {Benry::CmdApp::INDEX.get_alias("a5").alias_name} == "a5"
109
+ ok {Benry::CmdApp::INDEX.get_alias("a5").action_name} == "alias1:a2"
110
+ end
111
+
112
+ spec "[!nrz3d] error if action not found." do
113
+ pr = proc { Benry::CmdApp.action_alias(:a5, :'alias1:a5') }
114
+ ok {pr}.raise?(Benry::CmdApp::AliasDefError,
115
+ "action_alias(:a5, :\"alias1:a5\"): Action not found.")
116
+ end
117
+
118
+ spec "[!vvmwd] error when action with same name as alias exists." do
119
+ pr = proc { Benry::CmdApp.action_alias(:'alias1:a2', :'alias1:a1') }
120
+ ok {pr}.raise?(Benry::CmdApp::AliasDefError,
121
+ "action_alias(:\"alias1:a2\", :\"alias1:a1\"): Not allowed to define same name alias as existing action.")
122
+ end
123
+
124
+ spec "[!i9726] error if alias already defined." do
125
+ pr1 = proc { Benry::CmdApp.action_alias(:'a6', :'alias1:a1') }
126
+ pr2 = proc { Benry::CmdApp.action_alias(:'a6', :'alias1:a2') }
127
+ ok {pr1}.NOT.raise?(Exception)
128
+ ok {pr2}.raise?(Benry::CmdApp::AliasDefError,
129
+ "action_alias(:a6, :\"alias1:a2\"): Alias name duplicated.")
130
+ end
131
+
132
+ end
133
+
134
+ end
135
+
136
+
137
+ end