lizarb 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.tool-versions +1 -0
  4. data/Gemfile +1 -0
  5. data/Gemfile.lock +7 -4
  6. data/README.md +23 -64
  7. data/README_SYSTEMS.md +80 -0
  8. data/Rakefile +3 -1
  9. data/app/dev/benches/loops_bench.rb +35 -0
  10. data/app/dev/commands/calculator_command.rb +69 -0
  11. data/app/dev/commands/calculator_command_test.rb +58 -0
  12. data/app/dev/commands/circle_command.rb +70 -0
  13. data/app/dev/commands/circle_command_test.rb +76 -0
  14. data/app/dev/commands/narrative_method_command.rb +60 -0
  15. data/app/dev/commands/narrative_method_command_test.rb +36 -0
  16. data/app/dev/commands/quadratic_command.rb +66 -0
  17. data/app/dev/commands/quadratic_command_test.rb +47 -0
  18. data/app/dev/generators/bench_generator/bench.rb.erb +24 -0
  19. data/app/dev/generators/bench_generator/bench_test.rb.erb +12 -0
  20. data/app/dev/generators/bench_generator.rb +2 -51
  21. data/app/dev/generators/command_generator/command.rb.erb +26 -0
  22. data/app/dev/generators/command_generator/command_test.rb.erb +12 -0
  23. data/app/dev/generators/command_generator.rb +2 -35
  24. data/app/dev/generators/record_generator.rb +46 -0
  25. data/app/dev/generators/{model_generator_test.rb → record_generator_test.rb} +2 -2
  26. data/app/dev_box.rb +24 -4
  27. data/app/happy_box.rb +1 -1
  28. data/app/net/databases/sqlite_db_test.rb +5 -5
  29. data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
  30. data/app/net/records/app_record_test.rb +8 -0
  31. data/app/net/records/post_record.rb +4 -0
  32. data/app/net/records/post_record_test.rb +8 -0
  33. data/app/net/records/user_record.rb +4 -0
  34. data/app/net/records/user_record_test.rb +8 -0
  35. data/app/net_box.rb +7 -7
  36. data/app/web/requests/api_request.rb +8 -7
  37. data/app/web/requests/assets_request.rb +12 -13
  38. data/app/web/requests/root_request.rb +6 -7
  39. data/app/web/requests/root_request_test.rb +1 -1
  40. data/app/web_box.rb +9 -1
  41. data/exe/lrb +3 -0
  42. data/lib/app.rb +19 -15
  43. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +27 -0
  44. data/lib/dev_system/dev/controllers/{command/dev_command_test.rb → bench/not_found_bench_test.rb} +3 -5
  45. data/lib/dev_system/dev/controllers/bench.rb +5 -7
  46. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +37 -39
  47. data/lib/dev_system/dev/controllers/bench_test.rb +8 -10
  48. data/lib/dev_system/dev/controllers/command/bench_command.rb +20 -12
  49. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +8 -10
  50. data/lib/dev_system/dev/controllers/command/echo_command.rb +5 -7
  51. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +8 -10
  52. data/lib/dev_system/dev/controllers/command/generate_command.rb +22 -12
  53. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +8 -10
  54. data/lib/dev_system/dev/controllers/command/not_found_command.rb +27 -0
  55. data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +12 -0
  56. data/lib/dev_system/dev/controllers/command/terminal_command.rb +22 -0
  57. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +12 -0
  58. data/lib/dev_system/dev/controllers/command/test_command.rb +64 -49
  59. data/lib/dev_system/dev/controllers/command/test_command_test.rb +8 -10
  60. data/lib/dev_system/dev/controllers/command/version_command.rb +4 -6
  61. data/lib/dev_system/dev/controllers/command/version_command_test.rb +8 -10
  62. data/lib/dev_system/dev/controllers/command.rb +11 -13
  63. data/lib/dev_system/dev/controllers/command_test.rb +8 -10
  64. data/lib/dev_system/dev/controllers/generator.rb +5 -7
  65. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +35 -37
  66. data/lib/dev_system/dev/controllers/generator_test.rb +8 -10
  67. data/lib/dev_system/dev/controllers/generators/app_generator.rb +122 -47
  68. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +8 -10
  69. data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
  70. data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
  71. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
  72. data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
  73. data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
  74. data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
  75. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +27 -0
  76. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +12 -0
  77. data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
  78. data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
  79. data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
  80. data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
  81. data/lib/dev_system/dev/controllers/shell/file_shell.rb +56 -26
  82. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +143 -7
  83. data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
  84. data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
  85. data/lib/dev_system/dev/controllers/shell.rb +26 -14
  86. data/lib/dev_system/dev/controllers/shell_test.rb +42 -9
  87. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +11 -13
  88. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +8 -10
  89. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +6 -8
  90. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +8 -10
  91. data/lib/dev_system/dev/controllers/terminal.rb +11 -13
  92. data/lib/dev_system/dev/controllers/terminal_test.rb +8 -10
  93. data/lib/dev_system/dev/dev_box.rb +33 -16
  94. data/lib/dev_system/dev/dev_box_test.rb +12 -14
  95. data/lib/dev_system/dev/panels/bench_panel.rb +3 -0
  96. data/lib/dev_system/dev/panels/bench_panel_test.rb +12 -0
  97. data/lib/dev_system/dev/panels/command_panel.rb +24 -6
  98. data/lib/dev_system/dev/panels/command_panel_test.rb +15 -17
  99. data/lib/dev_system/dev/panels/generator_panel.rb +3 -0
  100. data/lib/dev_system/dev/panels/generator_panel_test.rb +12 -0
  101. data/lib/dev_system/dev/panels/log_panel.rb +9 -6
  102. data/lib/dev_system/dev/panels/log_panel_test.rb +11 -13
  103. data/lib/dev_system/dev/panels/shell_panel.rb +3 -0
  104. data/lib/dev_system/dev/panels/shell_panel_test.rb +12 -0
  105. data/lib/dev_system/dev/panels/terminal_panel.rb +3 -0
  106. data/lib/dev_system/dev/panels/terminal_panel_test.rb +12 -0
  107. data/lib/happy_system/happy/controllers/axo.rb +4 -5
  108. data/lib/happy_system/happy/happy_box.rb +6 -9
  109. data/lib/happy_system/happy/happy_box_test.rb +11 -13
  110. data/lib/happy_system/happy/panels/axo_panel.rb +1 -3
  111. data/lib/lerb.rb +106 -0
  112. data/lib/liza/base/box.rb +71 -26
  113. data/lib/liza/base/box_test.rb +7 -9
  114. data/lib/liza/base/controller.rb +19 -19
  115. data/lib/liza/base/controller_test.rb +7 -9
  116. data/lib/liza/base/panel.rb +40 -24
  117. data/lib/liza/base/panel_test.rb +10 -12
  118. data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
  119. data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
  120. data/lib/liza/meta/part.rb +12 -14
  121. data/lib/liza/meta/part_extension.rb +14 -11
  122. data/lib/liza/meta/part_test.rb +4 -6
  123. data/lib/liza/meta/system.rb +12 -14
  124. data/lib/liza/meta/system_test.rb +8 -10
  125. data/lib/liza/ruby_test.rb +7 -0
  126. data/lib/liza/ruby_tests/module_test.rb +21 -0
  127. data/lib/liza/ruby_tests/string_test.rb +59 -0
  128. data/lib/liza/test/test.rb +7 -8
  129. data/lib/liza/test/test_test.rb +168 -76
  130. data/lib/liza/test_parts/test_assertions_advanced_part.rb +125 -0
  131. data/lib/liza/test_parts/test_assertions_part.rb +81 -82
  132. data/lib/liza/test_parts/test_dsl_part.rb +44 -98
  133. data/lib/liza/test_parts/test_log_part.rb +122 -0
  134. data/lib/liza/test_parts/test_subject_part.rb +16 -18
  135. data/lib/liza/test_parts/test_tree_part.rb +137 -0
  136. data/lib/liza/unit.rb +108 -102
  137. data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
  138. data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
  139. data/lib/liza/unit_test.rb +69 -71
  140. data/lib/liza.rb +5 -0
  141. data/lib/lizarb/ruby/module.rb +17 -0
  142. data/lib/lizarb/ruby/string.rb +10 -2
  143. data/lib/lizarb/version.rb +1 -1
  144. data/lib/lizarb.rb +24 -2
  145. data/lib/net_system/dev/net_command.rb +10 -12
  146. data/lib/net_system/net/controllers/client/redis_client.rb +19 -21
  147. data/lib/net_system/net/controllers/client/redis_client_test.rb +20 -22
  148. data/lib/net_system/net/controllers/client/sqlite_client.rb +19 -21
  149. data/lib/net_system/net/controllers/client/sqlite_client_test.rb +20 -22
  150. data/lib/net_system/net/controllers/client.rb +1 -3
  151. data/lib/net_system/net/controllers/client_test.rb +8 -10
  152. data/lib/net_system/net/controllers/database/redis_db.rb +6 -8
  153. data/lib/net_system/net/controllers/database/redis_db_test.rb +15 -17
  154. data/lib/net_system/net/controllers/database/sqlite_db.rb +6 -8
  155. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +15 -17
  156. data/lib/net_system/net/controllers/database.rb +21 -23
  157. data/lib/net_system/net/controllers/database_test.rb +8 -10
  158. data/lib/net_system/net/controllers/record.rb +29 -0
  159. data/lib/net_system/net/controllers/record_test.rb +12 -0
  160. data/lib/net_system/net/net_box.rb +11 -16
  161. data/lib/net_system/net/net_box_test.rb +12 -14
  162. data/lib/net_system/net/panels/client_panel.rb +1 -3
  163. data/lib/net_system/net/panels/client_panel_test.rb +11 -13
  164. data/lib/net_system/net/panels/database_panel.rb +6 -8
  165. data/lib/net_system/net/panels/database_panel_test.rb +11 -13
  166. data/lib/web_system/dev/rack_command.rb +35 -0
  167. data/lib/web_system/dev/request_command.rb +143 -0
  168. data/lib/web_system/dev/web_command.rb +6 -39
  169. data/lib/web_system/web/controllers/rack.rb +6 -0
  170. data/lib/web_system/web/controllers/rack_test.rb +16 -0
  171. data/lib/web_system/web/controllers/request/client_error_request.rb +9 -12
  172. data/lib/web_system/web/controllers/request/not_found_request.rb +9 -12
  173. data/lib/web_system/web/controllers/request/server_error_request.rb +10 -13
  174. data/lib/web_system/web/controllers/request.rb +1 -3
  175. data/lib/web_system/web/controllers/request_test.rb +11 -13
  176. data/lib/web_system/web/panels/rack_panel.rb +42 -0
  177. data/lib/web_system/web/panels/rack_panel_test.rb +12 -0
  178. data/lib/web_system/web/panels/request_panel.rb +54 -37
  179. data/lib/web_system/web/panels/request_panel_test.rb +28 -9
  180. data/lib/web_system/web/web_box.rb +16 -8
  181. data/lib/web_system/web/web_box_test.rb +11 -13
  182. data/lizarb.gemspec +2 -2
  183. metadata +76 -28
  184. data/app/dev/commands/example_command.rb +0 -57
  185. data/app/dev/commands/example_command_test.rb +0 -43
  186. data/app/dev/commands/macro_child_command.rb +0 -32
  187. data/app/dev/commands/macro_child_command_test.rb +0 -7
  188. data/app/dev/commands/macro_parent_command.rb +0 -70
  189. data/app/dev/commands/macro_parent_command_test.rb +0 -7
  190. data/app/dev/commands/my_command.rb +0 -7
  191. data/app/dev/commands/my_command_test.rb +0 -7
  192. data/app/dev/generators/model_generator.rb +0 -46
  193. data/app/net/models/app_model_test.rb +0 -8
  194. data/app/net/models/post_model.rb +0 -4
  195. data/app/net/models/post_model_test.rb +0 -8
  196. data/app/net/models/user_model.rb +0 -4
  197. data/app/net/models/user_model_test.rb +0 -8
  198. data/app_new/.gitignore +0 -4
  199. data/app_new/Gemfile +0 -31
  200. data/app_new/Procfile +0 -3
  201. data/lib/dev_system/dev/controllers/command/dev_command.rb +0 -24
  202. data/lib/liza/test_parts/test_context_part.rb +0 -81
  203. data/lib/net_system/net/controllers/model.rb +0 -31
  204. data/lib/net_system/net/controllers/model_test.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4e73803f6fe207c86ff2e6799e3bdbe50979bbe9fb409750c067ef6ce299c5b
4
- data.tar.gz: 46c590ae60a43c0fd0b901f800da5f8761cc70baae0ace96e64a772941c6512f
3
+ metadata.gz: 53e926fac5423110d8a9468bac9598dbe3a88922c61ac584311dc2b9a49ce81f
4
+ data.tar.gz: 0a2e15f3cd064944b01d02a8761fca520a3167172c7193c00f7c5d807e0e88ba
5
5
  SHA512:
6
- metadata.gz: 1c83f9babff78a0487784c8c62bf98cf3dd44e64a01267c57bcb1bd4938c980ec09759f4069ef6819088511e25ef6e29f6acc3920ae950c71d00e43d362970c9
7
- data.tar.gz: 043bbe7ac4dc5102f3a2b8b261ff13e7a8784d6217a5474b40d8110005b4060d281cf73f938172e0487564c80427d7f63f3e2c1df6c9a3b252f6fd214052070a
6
+ metadata.gz: ba9279ab0d31e64b01d41d764542a73465171497950a681119ecc2a2c8f01a66f04172dc67617b03c92a04302c8772c88209f5803053cf1c405216ac5cb003d9
7
+ data.tar.gz: 5b27e32f1f16dd6c2536c4ad6046bb782a9eb20a8e8c9f68d7b6ab412950a464367193b435e801f9c3b442120414ad0cf7b8f034c3fae40b9050efebcf2cfe17
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.2
1
+ 3.2.0
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.2.0
data/Gemfile CHANGED
@@ -25,4 +25,5 @@ group :web do
25
25
  gem "rack", "~> 3.0"
26
26
  gem "rackup", "~> 0.2.2"
27
27
  gem "puma", "~> 5.6"
28
+ gem "htmlbeautifier", "~> 1.4"
28
29
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lizarb (1.0.1)
4
+ lizarb (1.0.3)
5
5
  colorize (~> 0.8)
6
6
  dotenv (~> 2.8)
7
7
  zeitwerk (~> 2.6)
@@ -13,7 +13,9 @@ GEM
13
13
  colorize (0.8.1)
14
14
  connection_pool (2.3.0)
15
15
  dotenv (2.8.1)
16
+ htmlbeautifier (1.4.2)
16
17
  method_source (1.0.0)
18
+ mini_portile2 (2.8.1)
17
19
  nio4r (2.5.8)
18
20
  pry (0.14.1)
19
21
  coderay (~> 1.1)
@@ -29,16 +31,17 @@ GEM
29
31
  redis-client (>= 0.9.0)
30
32
  redis-client (0.10.0)
31
33
  connection_pool
32
- sqlite3 (1.5.3-arm64-darwin)
33
- sqlite3 (1.5.3-x86_64-linux)
34
+ sqlite3 (1.5.4)
35
+ mini_portile2 (~> 2.8.0)
34
36
  webrick (1.7.0)
35
- zeitwerk (2.6.1)
37
+ zeitwerk (2.6.7)
36
38
 
37
39
  PLATFORMS
38
40
  arm64-darwin-21
39
41
  x86_64-linux
40
42
 
41
43
  DEPENDENCIES
44
+ htmlbeautifier (~> 1.4)
42
45
  lizarb!
43
46
  pry (~> 0.14.1)
44
47
  puma (~> 5.6)
data/README.md CHANGED
@@ -6,97 +6,56 @@ Liza is a light, experimental framework primarily developed to help study the Ru
6
6
 
7
7
  Install the gem by executing:
8
8
 
9
- $ gem install lizarb
9
+ gem install lizarb
10
10
 
11
11
  You will get the following three shims:
12
12
 
13
- $ lizarb version
14
- $ liza version
13
+ lizarb version
14
+ liza version
15
+ lrb version
15
16
 
16
- ## Try
17
-
18
- Try Liza with an interactive prompt
19
-
20
- $ liza dev
21
-
22
- ## Running Tests
23
-
24
- Run your Liza tests
25
-
26
- $ liza test
27
-
28
- ## Happy
29
-
30
- Try Liza and build an ASCII game
17
+ ## Create a liza app
31
18
 
32
- $ liza happy axo
19
+ So you can run your experiments:
33
20
 
34
- ## Networking
21
+ liza new
35
22
 
36
- Try Liza to connect with Sqlite and Redis
23
+ Then enter your automagically generated liza app:
37
24
 
38
- $ liza net
25
+ cd app_1
26
+ bundle install
39
27
 
40
- ```ruby
28
+ Now you're ready to go and try some stuff!
41
29
 
42
- NetBox.clients.get :sqlite
43
- NetBox.clients.get :redis_url
44
-
45
- NetBox.databases.sql
46
- NetBox.databases.sqlite
47
- NetBox.databases.redis
48
-
49
- RedisDb.current
50
- SqliteDb.current
51
-
52
- RedisDb.current.call "TIME"
53
- SqliteDb.current.call "SELECT name, sql FROM sqlite_master WHERE type = 'table';"
54
-
55
- ```
56
-
57
- ## Web Server
30
+ ## Try
58
31
 
59
- Try Liza with the Rack Web Server
32
+ Try Liza with an interactive terminal
60
33
 
61
- $ liza web
34
+ liza terminal
62
35
 
63
- http://localhost:3000/
64
-
65
- http://localhost:3000/xxxxxxx
66
-
67
- http://localhost:3000/api/xxxxxxx
68
-
69
- http://localhost:3000/api/auth/sign_up
70
-
71
- http://localhost:3000/api/auth/sign_in
72
-
73
- http://localhost:3000/api/auth/account
74
-
75
- http://localhost:3000/api/auth/sign_out
76
-
77
- http://localhost:3000/assets/app.css
78
-
79
- http://localhost:3000/assets/app.js
36
+ ## Running Tests
80
37
 
81
- ## Usage
38
+ Run your Liza tests
82
39
 
83
- TODO: Write usage instructions here
40
+ liza test
84
41
 
85
42
  ## Development
86
43
 
87
44
  To install dependencies, run this bash script:
88
45
 
89
- $ bin/setup
46
+ bin/setup
90
47
 
91
48
  For development experiments, use the local executable script
92
49
 
93
- $ exe/lizarb test
50
+ exe/lizarb test
94
51
 
95
52
  To build and install lizarb in your local machine
96
53
 
97
- $ bundle exec rake install
54
+ bundle exec rake install
55
+
56
+ For systems in development, see [README_SYSTEMS.md](https://github.com/rubyonrails-brasil/lizarb/blob/master/README_SYSTEMS.md).
98
57
 
99
- ## Release
58
+ ## Release
100
59
 
101
60
  To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
102
61
 
data/README_SYSTEMS.md ADDED
@@ -0,0 +1,80 @@
1
+ # Liza - Systems in Development
2
+
3
+ These systems operate at a very small capacity, and will be fleshed out in the future.
4
+
5
+ ## Happy
6
+
7
+ Try Liza and build an ASCII game
8
+
9
+ liza happy axo
10
+
11
+ ## Networking
12
+
13
+ Try Liza to connect with Sqlite and Redis
14
+
15
+ liza net
16
+
17
+ ```ruby
18
+
19
+ NetBox.clients.get :sqlite
20
+ NetBox.clients.get :redis_url
21
+
22
+ NetBox.databases.sql
23
+ NetBox.databases.sqlite
24
+ NetBox.databases.redis
25
+
26
+ RedisDb.current
27
+ SqliteDb.current
28
+
29
+ RedisDb.current.call "TIME"
30
+ SqliteDb.current.call "SELECT name, sql FROM sqlite_master WHERE type = 'table';"
31
+
32
+ ```
33
+
34
+ ## Rack Web Server
35
+
36
+ Try Liza with the Rack Web Server
37
+
38
+ liza rack
39
+
40
+ http://localhost:3000/
41
+
42
+ http://localhost:3000/xxxxxxx
43
+
44
+ http://localhost:3000/api/xxxxxxx
45
+
46
+ http://localhost:3000/api/auth/sign_up
47
+
48
+ http://localhost:3000/api/auth/sign_in
49
+
50
+ http://localhost:3000/api/auth/account
51
+
52
+ http://localhost:3000/api/auth/sign_out
53
+
54
+ http://localhost:3000/assets/app.css
55
+
56
+ http://localhost:3000/assets/app.js
57
+
58
+ ## Web Request
59
+
60
+ Try Liza with the Rack Web Server
61
+
62
+ liza request get /
63
+
64
+ liza request post /
65
+
66
+ liza request get /xxxxxxx
67
+
68
+ liza request get /api/xxxxxxx
69
+
70
+ liza request get /api/auth/sign_up
71
+
72
+ liza request get /api/auth/sign_in
73
+
74
+ liza request get /api/auth/account
75
+
76
+ liza request get /api/auth/sign_out
77
+
78
+ liza request get /assets/app.css
79
+
80
+ liza request get /assets/app.js
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- task default: %i[]
4
+ task default: %i[] do
5
+ system "lizarb test"
6
+ end
@@ -70,6 +70,24 @@ class LoopsBench < AppBench
70
70
  end
71
71
  end
72
72
 
73
+ mark "HASH_INT.each_pair do |i, iv|" do
74
+ HASH_INT.each_pair do |i, iv|
75
+ a = "1"
76
+ end
77
+ end
78
+
79
+ mark "HASH_STR.each_pair do |i, iv|" do
80
+ HASH_STR.each_pair do |i, iv|
81
+ a = "1"
82
+ end
83
+ end
84
+
85
+ mark "HASH_SYM.each_pair do |i, iv|" do
86
+ HASH_SYM.each_pair do |i, iv|
87
+ a = "1"
88
+ end
89
+ end
90
+
73
91
  mark "RANGE.map do |i|" do
74
92
  RANGE.map do |i|
75
93
  a = "1"
@@ -112,6 +130,17 @@ class LoopsBench < AppBench
112
130
  end
113
131
  end
114
132
 
133
+ mark "1.upto N next" do
134
+ it = 1.upto N
135
+ begin
136
+ it.next while true
137
+ rescue StopIteration
138
+ end
139
+ # do |i|
140
+ # a = "1"
141
+ # end
142
+ end
143
+
115
144
  mark "loop break" do
116
145
  i = 0
117
146
 
@@ -129,6 +158,12 @@ class LoopsBench < AppBench
129
158
  end
130
159
  end
131
160
 
161
+ mark "while inline" do
162
+ i = 0
163
+
164
+ a = "1" while (i += 1) <= N
165
+ end
166
+
132
167
  mark "begin end while" do
133
168
  i = 0
134
169
 
@@ -0,0 +1,69 @@
1
+ class CalculatorCommand < NarrativeMethodCommand
2
+ class Error < Error; end
3
+
4
+ def self.sum(a, b)= a + b
5
+ def self.sub(a, b)= a - b
6
+ def self.mul(a, b)= a * b
7
+ def self.div(a, b)= a / b
8
+
9
+ # instance methods
10
+
11
+ def validate
12
+ log "Called #{self}.#{__method__}"
13
+ raise Invalid, "liza calculator 0 + 0" if @args.size != 3
14
+
15
+ @a = @args[0].to_f
16
+ @op = @args[1].to_sym
17
+ @b = @args[2].to_f
18
+
19
+ log "@a = #{@a}"
20
+ log "@op = #{@op}"
21
+ log "@b = #{@b}"
22
+
23
+ raise Invalid, "#{@op} is not a valid operator" unless [:+, :-, :*, :/].include? @op
24
+ end
25
+
26
+ def perform
27
+ log "Called #{self}.#{__method__}"
28
+ @result = \
29
+ case @op
30
+ when :+ then self.class.sum(@a, @b)
31
+ when :- then self.class.sub(@a, @b)
32
+ when :* then self.class.mul(@a, @b)
33
+ when :/ then self.class.div(@a, @b)
34
+ end
35
+ log "RESULT: #{@result}"
36
+ log render "success.txt"
37
+ end
38
+
39
+ end
40
+
41
+ __END__
42
+
43
+ # help.txt.erb
44
+
45
+ NAME:
46
+
47
+ liza calculator
48
+
49
+ DESCRIPTION:
50
+
51
+ Calculates the result of an arithmetic operation.
52
+
53
+ USAGE:
54
+
55
+ liza calculator <a> <op> <b>
56
+
57
+ where <a> and <b> are numbers and <op> is one of the following operators:
58
+
59
+ + addition
60
+ - subtraction
61
+ * multiplication
62
+ / division
63
+
64
+ EXAMPLES:
65
+
66
+ liza calculator 1 + 2
67
+ liza calculator 3 - 4
68
+ liza calculator 5 * 6
69
+ liza calculator 7 / 8
@@ -0,0 +1,58 @@
1
+ class CalculatorCommandTest < NarrativeMethodCommandTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == CalculatorCommand
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ test :subject_class, :sum do
13
+ assert subject_class.sum(1, 2) == 3
14
+ end
15
+
16
+ test :subject_class, :sub do
17
+ assert subject_class.sub(1, 2) == -1
18
+ end
19
+
20
+ test :subject_class, :mul do
21
+ assert subject_class.mul(1, 2) == 2
22
+ end
23
+
24
+ test :subject_class, :div do
25
+ assert subject_class.div(10, 2) == 5
26
+ end
27
+
28
+ test :validate, :valid do
29
+ subject = subject_class.new
30
+ subject.instance_variable_set :@args, ["1", "+", "2"]
31
+ subject.validate
32
+ assert subject.instance_variable_get(:@a) == 1
33
+ assert subject.instance_variable_get(:@op) == :+
34
+ assert subject.instance_variable_get(:@b) == 2
35
+ end
36
+
37
+ test :validate, :invalid do
38
+ subject = subject_class.new
39
+ subject.instance_variable_set :@args, ["1", "x", "2"]
40
+ begin
41
+ subject.validate
42
+ assert false
43
+ rescue CalculatorCommand::Invalid
44
+ assert true
45
+ else
46
+ assert false
47
+ end
48
+ end
49
+
50
+ test :perform do
51
+ subject = subject_class.new
52
+ subject.instance_variable_set :@args, ["1", "+", "2"]
53
+ subject.validate
54
+ subject.perform
55
+ assert subject.instance_variable_get(:@result) == 3
56
+ end
57
+
58
+ end
@@ -0,0 +1,70 @@
1
+ class CircleCommand < NarrativeMethodCommand
2
+ class Error < Error; end
3
+
4
+ def self.area(radius)
5
+ log "Called #{self}.#{__method__} with radius #{radius}"
6
+ log "The answer is #{radius**2}π"
7
+ Math::PI * radius**2
8
+ end
9
+
10
+ def self.circumference(radius)
11
+ log "Called #{self}.#{__method__} with radius #{radius}"
12
+ log "The answer is #{radius * 2}π"
13
+ 2 * Math::PI * radius
14
+ end
15
+
16
+ # instance methods
17
+
18
+ def validate
19
+ log "Called #{self}.#{__method__}"
20
+ raise Invalid, "liza circle <formula> <radius>" if @args.size != 2
21
+ raise Invalid, "liza circle <formula> <radius>" if @args[0] != "area" && @args[0] != "circumference"
22
+
23
+ @formula = @args[0].to_sym
24
+ @radius = @args[1].to_f
25
+
26
+ log "@formula = #{@formula}"
27
+ log "@radius = #{@radius}"
28
+
29
+ raise Invalid, "radius must be greater than 0" if @radius <= 0
30
+ end
31
+
32
+ def perform
33
+ log "Called #{self}.#{__method__}"
34
+
35
+ @result = \
36
+ case @formula
37
+ when :area then self.class.area(@radius)
38
+ when :circumference then self.class.circumference(@radius)
39
+ end
40
+ log "RESULT: #{@result}"
41
+ log render "success.txt"
42
+ end
43
+
44
+ end
45
+
46
+ __END__
47
+
48
+ # help.txt.erb
49
+
50
+ NAME:
51
+
52
+ liza circle
53
+
54
+ DESCRIPTION:
55
+
56
+ Calculates a circle formula based on the radius.
57
+
58
+ USAGE:
59
+
60
+ liza circle <formula> <radius>
61
+
62
+ FORMULAS:
63
+
64
+ area - calculates the area of a circle
65
+ circumference - calculates the circumference of a circle
66
+
67
+ EXAMPLES:
68
+
69
+ liza circle area 5
70
+ liza circle circumference 5
@@ -0,0 +1,76 @@
1
+ class CircleCommandTest < NarrativeMethodCommandTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == CircleCommand
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ test :subject_class, :area do
13
+ assert subject_class.area(1) == 3.141592653589793
14
+ end
15
+
16
+ test :subject_class, :circumference do
17
+ assert subject_class.circumference(1) == 6.283185307179586
18
+ end
19
+
20
+ test :validate, :valid, :area do
21
+ subject = subject_class.new
22
+ subject.instance_variable_set :@args, ["area", "1"]
23
+ subject.validate
24
+ assert subject.instance_variable_get(:@radius) == 1
25
+ end
26
+
27
+ test :validate, :invalid, :area do
28
+ subject = subject_class.new
29
+ subject.instance_variable_set :@args, ["area", "0"]
30
+ begin
31
+ subject.validate
32
+ assert false
33
+ rescue CircleCommand::Invalid
34
+ assert true
35
+ else
36
+ assert false
37
+ end
38
+ end
39
+
40
+ test :validate, :valid, :circumference do
41
+ subject = subject_class.new
42
+ subject.instance_variable_set :@args, ["circumference", "1"]
43
+ subject.validate
44
+ assert subject.instance_variable_get(:@radius) == 1
45
+ end
46
+
47
+ test :validate, :invalid, :circumference do
48
+ subject = subject_class.new
49
+ subject.instance_variable_set :@args, ["circumference", "0"]
50
+ begin
51
+ subject.validate
52
+ assert false
53
+ rescue CircleCommand::Invalid
54
+ assert true
55
+ else
56
+ assert false
57
+ end
58
+ end
59
+
60
+ test :perform, :area do
61
+ subject = subject_class.new
62
+ subject.instance_variable_set :@args, ["area", "1"]
63
+ subject.validate
64
+ subject.perform
65
+ assert subject.instance_variable_get(:@result) == 3.141592653589793
66
+ end
67
+
68
+ test :perform, :circumference do
69
+ subject = subject_class.new
70
+ subject.instance_variable_set :@args, ["circumference", "1"]
71
+ subject.validate
72
+ subject.perform
73
+ assert subject.instance_variable_get(:@result) == 6.283185307179586
74
+ end
75
+
76
+ end
@@ -0,0 +1,60 @@
1
+ class NarrativeMethodCommand < Liza::Command
2
+ class Error < StandardError; end
3
+ class Invalid < Error; end
4
+
5
+ def self.call(args)
6
+ log "Called #{self}.#{__method__} with args #{args}"
7
+ new.call(args)
8
+ end
9
+
10
+ # instance methods
11
+
12
+ def call(args)
13
+ log "Called #{self}.#{__method__} with args #{args}"
14
+ return help if args.empty?
15
+
16
+ @args = args
17
+ validate
18
+ perform
19
+ rescue StandardError => error
20
+ @error = error
21
+ handle
22
+ ensure
23
+ @result
24
+ end
25
+
26
+ def validate
27
+ raise NotImplementedError
28
+ end
29
+
30
+ def perform
31
+ raise NotImplementedError
32
+ end
33
+
34
+ def handle
35
+ log "Called #{self}.#{__method__}"
36
+ log render "error.txt"
37
+ end
38
+
39
+ def help
40
+ log "Called #{self}.#{__method__}"
41
+ log render "help.txt"
42
+ end
43
+ end
44
+
45
+ __END__
46
+
47
+ # success.txt.erb
48
+
49
+ RESULT:
50
+
51
+ class <%= @result.class %>
52
+ value <%= @result %>
53
+
54
+ # error.txt.erb
55
+
56
+ ERROR:
57
+
58
+ class <%= @error.class %>
59
+ message <%= @error.message %>
60
+ backtrace <%= @error.backtrace.select { |s| @stop = true if s.include?("/exe/lizarb:"); !defined? @stop }.join "\n " %>
@@ -0,0 +1,36 @@
1
+ class NarrativeMethodCommandTest < Liza::CommandTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == NarrativeMethodCommand
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ test :validate, :not_implemented do
13
+ subject = subject_class.new
14
+ begin
15
+ subject.validate
16
+ assert false
17
+ rescue NotImplementedError
18
+ assert true
19
+ else
20
+ assert false
21
+ end
22
+ end
23
+
24
+ test :perform, :not_implemented do
25
+ subject = subject_class.new
26
+ begin
27
+ subject.perform
28
+ assert false
29
+ rescue NotImplementedError
30
+ assert true
31
+ else
32
+ assert false
33
+ end
34
+ end
35
+
36
+ end