lizarb 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.tool-versions +1 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +14 -3
  6. data/README.md +23 -64
  7. data/README_SYSTEMS.md +80 -0
  8. data/Rakefile +3 -1
  9. data/app/dev/benches/app_bench.rb +5 -0
  10. data/app/dev/benches/app_bench_test.rb +7 -0
  11. data/app/dev/benches/loops_bench.rb +183 -0
  12. data/app/dev/benches/loops_bench_test.rb +11 -0
  13. data/app/dev/commands/calculator_command.rb +69 -0
  14. data/app/dev/commands/calculator_command_test.rb +58 -0
  15. data/app/dev/commands/circle_command.rb +70 -0
  16. data/app/dev/commands/circle_command_test.rb +76 -0
  17. data/app/dev/commands/narrative_method_command.rb +60 -0
  18. data/app/dev/commands/narrative_method_command_test.rb +36 -0
  19. data/app/dev/commands/new_command.rb +1 -61
  20. data/app/dev/commands/quadratic_command.rb +66 -0
  21. data/app/dev/commands/quadratic_command_test.rb +47 -0
  22. data/app/dev/generators/bench_generator/bench.rb.erb +24 -0
  23. data/app/dev/generators/bench_generator/bench_test.rb.erb +12 -0
  24. data/app/dev/generators/bench_generator.rb +18 -0
  25. data/app/dev/generators/bench_generator_test.rb +12 -0
  26. data/app/dev/generators/command_generator/command.rb.erb +26 -0
  27. data/app/dev/generators/command_generator/command_test.rb.erb +12 -0
  28. data/app/dev/generators/command_generator.rb +18 -0
  29. data/app/dev/generators/command_generator_test.rb +12 -0
  30. data/app/dev/generators/record_generator.rb +46 -0
  31. data/app/dev/generators/record_generator_test.rb +12 -0
  32. data/app/dev/generators/request_generator.rb +63 -0
  33. data/app/dev/generators/request_generator_test.rb +12 -0
  34. data/app/net/databases/redis_db_test.rb +2 -2
  35. data/app/net/databases/sqlite_db_test.rb +2 -2
  36. data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
  37. data/app/net/{models/post_model_test.rb → records/app_record_test.rb} +2 -2
  38. data/app/net/records/post_record.rb +4 -0
  39. data/app/net/{models/app_model_test.rb → records/post_record_test.rb} +2 -2
  40. data/app/net/records/user_record.rb +4 -0
  41. data/app/net/{models/user_model_test.rb → records/user_record_test.rb} +2 -2
  42. data/app/net_box.rb +2 -2
  43. data/app/web/requests/api_request.rb +8 -7
  44. data/app/web/requests/assets_request.rb +12 -13
  45. data/app/web/requests/root_request.rb +6 -7
  46. data/app/web/requests/root_request_test.rb +1 -1
  47. data/app/web_box.rb +8 -0
  48. data/app_new/Procfile +1 -1
  49. data/exe/lrb +3 -0
  50. data/lib/app.rb +18 -14
  51. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +29 -0
  52. data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +14 -0
  53. data/lib/dev_system/dev/controllers/bench.rb +11 -0
  54. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +60 -0
  55. data/lib/dev_system/dev/controllers/{command/dev_command_test.rb → bench_test.rb} +2 -2
  56. data/lib/dev_system/dev/controllers/command/bench_command.rb +34 -0
  57. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
  58. data/lib/dev_system/dev/controllers/command/generate_command.rb +35 -0
  59. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
  60. data/lib/dev_system/dev/controllers/command/not_found_command.rb +29 -0
  61. data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +14 -0
  62. data/lib/dev_system/dev/controllers/command/terminal_command.rb +24 -0
  63. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +14 -0
  64. data/lib/dev_system/dev/controllers/command/test_command.rb +6 -2
  65. data/lib/dev_system/dev/controllers/generator.rb +11 -0
  66. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +54 -0
  67. data/lib/dev_system/dev/controllers/generator_test.rb +14 -0
  68. data/lib/dev_system/dev/controllers/generators/app_generator.rb +96 -0
  69. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
  70. data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
  71. data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
  72. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
  73. data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
  74. data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
  75. data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
  76. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +29 -0
  77. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +14 -0
  78. data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
  79. data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
  80. data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
  81. data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
  82. data/lib/dev_system/dev/controllers/shell/file_shell.rb +59 -0
  83. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +150 -0
  84. data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
  85. data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
  86. data/lib/dev_system/dev/controllers/shell.rb +31 -0
  87. data/lib/dev_system/dev/controllers/shell_test.rb +46 -0
  88. data/lib/dev_system/dev/controllers/{command/dev_command.rb → terminal/irb_terminal.rb} +2 -2
  89. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +14 -0
  90. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +12 -0
  91. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +14 -0
  92. data/lib/dev_system/dev/controllers/terminal.rb +19 -0
  93. data/lib/dev_system/dev/controllers/terminal_test.rb +14 -0
  94. data/lib/dev_system/dev/dev_box.rb +3 -0
  95. data/lib/dev_system/dev/panels/command_panel.rb +21 -1
  96. data/lib/dev_system/dev/panels/log_panel.rb +1 -1
  97. data/lib/lerb.rb +106 -0
  98. data/lib/liza/base/controller.rb +2 -0
  99. data/lib/liza/base/panel.rb +6 -5
  100. data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
  101. data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
  102. data/lib/liza/meta/part_extension.rb +6 -1
  103. data/lib/liza/ruby_test.rb +9 -0
  104. data/lib/liza/ruby_tests/module_test.rb +21 -0
  105. data/lib/liza/ruby_tests/string_test.rb +59 -0
  106. data/lib/liza/test/test.rb +3 -1
  107. data/lib/liza/test/test_test.rb +108 -15
  108. data/lib/liza/test_parts/test_assertions_advanced_part.rb +127 -0
  109. data/lib/liza/test_parts/test_assertions_part.rb +7 -6
  110. data/lib/liza/test_parts/test_dsl_part.rb +37 -89
  111. data/lib/liza/test_parts/test_log_part.rb +124 -0
  112. data/lib/liza/test_parts/test_subject_part.rb +6 -1
  113. data/lib/liza/test_parts/test_tree_part.rb +139 -0
  114. data/lib/liza/unit.rb +2 -0
  115. data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
  116. data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
  117. data/lib/liza.rb +40 -7
  118. data/lib/lizarb/ruby/class.rb +2 -0
  119. data/lib/lizarb/ruby/module.rb +17 -0
  120. data/lib/lizarb/ruby/proc.rb +12 -0
  121. data/lib/lizarb/ruby/string.rb +26 -2
  122. data/lib/lizarb/version.rb +1 -1
  123. data/lib/lizarb.rb +24 -2
  124. data/lib/net_system/net/controllers/{adapter/redis_adapter.rb → client/redis_client.rb} +2 -2
  125. data/lib/net_system/net/controllers/{adapter/redis_adapter_test.rb → client/redis_client_test.rb} +2 -2
  126. data/lib/net_system/net/controllers/{adapter/sqlite_adapter.rb → client/sqlite_client.rb} +2 -2
  127. data/lib/net_system/net/controllers/{adapter/sqlite_adapter_test.rb → client/sqlite_client_test.rb} +2 -2
  128. data/lib/net_system/net/controllers/client.rb +5 -0
  129. data/lib/net_system/net/controllers/{model_test.rb → client_test.rb} +2 -2
  130. data/lib/net_system/net/controllers/database/redis_db.rb +2 -2
  131. data/lib/net_system/net/controllers/database/redis_db_test.rb +1 -1
  132. data/lib/net_system/net/controllers/database/sqlite_db.rb +2 -2
  133. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +1 -1
  134. data/lib/net_system/net/controllers/database.rb +6 -6
  135. data/lib/net_system/net/controllers/record.rb +31 -0
  136. data/lib/net_system/net/controllers/{adapter_test.rb → record_test.rb} +2 -2
  137. data/lib/net_system/net/net_box.rb +5 -5
  138. data/lib/net_system/net/net_box_test.rb +1 -1
  139. data/lib/net_system/net/panels/client_panel.rb +5 -0
  140. data/lib/net_system/net/panels/{adapter_panel_test.rb → client_panel_test.rb} +2 -2
  141. data/lib/web_system/dev/rack_command.rb +26 -0
  142. data/lib/web_system/dev/request_command.rb +143 -0
  143. data/lib/web_system/dev/web_command.rb +3 -34
  144. data/lib/web_system/web/controllers/rack.rb +8 -0
  145. data/lib/web_system/web/controllers/rack_test.rb +18 -0
  146. data/lib/web_system/web/controllers/request/client_error_request.rb +0 -1
  147. data/lib/web_system/web/controllers/request/not_found_request.rb +0 -1
  148. data/lib/web_system/web/controllers/request/server_error_request.rb +0 -1
  149. data/lib/web_system/web/panels/rack_panel.rb +44 -0
  150. data/lib/web_system/web/panels/rack_panel_test.rb +14 -0
  151. data/lib/web_system/web/panels/request_panel.rb +51 -32
  152. data/lib/web_system/web/panels/request_panel_test.rb +28 -9
  153. data/lib/web_system/web/web_box.rb +12 -0
  154. data/lizarb.gemspec +2 -2
  155. data/tmp/.gitkeep +0 -0
  156. metadata +110 -31
  157. data/app/dev/commands/example_command.rb +0 -57
  158. data/app/dev/commands/example_command_test.rb +0 -43
  159. data/app/dev/commands/macro_child_command.rb +0 -32
  160. data/app/dev/commands/macro_child_command_test.rb +0 -7
  161. data/app/dev/commands/macro_parent_command.rb +0 -70
  162. data/app/dev/commands/macro_parent_command_test.rb +0 -7
  163. data/app/dev/commands/my_command.rb +0 -7
  164. data/app/dev/commands/my_command_test.rb +0 -7
  165. data/app/net/models/post_model.rb +0 -4
  166. data/app/net/models/user_model.rb +0 -4
  167. data/lib/liza/test_parts/test_context_part.rb +0 -81
  168. data/lib/net_system/net/controllers/adapter.rb +0 -5
  169. data/lib/net_system/net/controllers/model.rb +0 -31
  170. data/lib/net_system/net/panels/adapter_panel.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c859781b1927e69f516b2b6d057b19a4e8d6603945636ce0ec7306640fbd1956
4
- data.tar.gz: d5849f4bcbf610ee5a94df16dbd92feab78a4f724e2ac77eeae05e93aebfbef5
3
+ metadata.gz: ebe2ac1c0a6d2e86f70577662d985ea755707a6855e67bcc0fc1e3d8f89ac563
4
+ data.tar.gz: 47544f75a230d272e38bd50adacd388d4cb8a8710da689ae24ca0fe187e7d3f6
5
5
  SHA512:
6
- metadata.gz: 4e4ffd81acfddf2a8aadebc0fcc10911141b3a8fc55e164d050fc3c8156a7ee560a7a84133c12d19e1491ff9c720b8a6afd857b6c22bdf14844ac03550c2dc6e
7
- data.tar.gz: bd421065bc059d7ebeac4d3d805e2133a18d0bb31745bc95a4b62d785f2b2368fbd80482cd2a7cac2cec03a239dc58b988844c1a234f4a0aa9a84ef99fc77256
6
+ metadata.gz: 8427b2e5710ccff4f9031adc64b9ad9e3fcdc4dea4565f933dc34b91f72378230b7946e020074832c8e7f44c7c5085bc0c3dc503b98d9852a2fb207b685f41b1
7
+ data.tar.gz: a8fa9c03c1cfa03947e3be6a35b610192cb2a50f5111f175b3211ee1ca35fcafbc371583c53e3b006735873fd5c07897c8dd3edcf6fb0235fac49353e19a460d
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
@@ -7,6 +7,7 @@ gemspec
7
7
 
8
8
  group :dev do
9
9
  # gems you only want to load if DevSystem is loaded
10
+ gem "pry", "~> 0.14.1"
10
11
  end
11
12
 
12
13
  group :happy do
@@ -24,4 +25,5 @@ group :web do
24
25
  gem "rack", "~> 3.0"
25
26
  gem "rackup", "~> 0.2.2"
26
27
  gem "puma", "~> 5.6"
28
+ gem "htmlbeautifier", "~> 1.4"
27
29
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lizarb (1.0.0)
4
+ lizarb (1.0.2)
5
5
  colorize (~> 0.8)
6
6
  dotenv (~> 2.8)
7
7
  zeitwerk (~> 2.6)
@@ -9,10 +9,17 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
+ coderay (1.1.3)
12
13
  colorize (0.8.1)
13
14
  connection_pool (2.3.0)
14
15
  dotenv (2.8.1)
16
+ htmlbeautifier (1.4.2)
17
+ method_source (1.0.0)
18
+ mini_portile2 (2.8.1)
15
19
  nio4r (2.5.8)
20
+ pry (0.14.1)
21
+ coderay (~> 1.1)
22
+ method_source (~> 1.0)
16
23
  puma (5.6.5)
17
24
  nio4r (~> 2.0)
18
25
  rack (3.0.0)
@@ -24,15 +31,19 @@ GEM
24
31
  redis-client (>= 0.9.0)
25
32
  redis-client (0.10.0)
26
33
  connection_pool
27
- sqlite3 (1.5.2-x86_64-linux)
34
+ sqlite3 (1.5.4)
35
+ mini_portile2 (~> 2.8.0)
28
36
  webrick (1.7.0)
29
- zeitwerk (2.6.1)
37
+ zeitwerk (2.6.7)
30
38
 
31
39
  PLATFORMS
40
+ arm64-darwin-21
32
41
  x86_64-linux
33
42
 
34
43
  DEPENDENCIES
44
+ htmlbeautifier (~> 1.4)
35
45
  lizarb!
46
+ pry (~> 0.14.1)
36
47
  puma (~> 5.6)
37
48
  rack (~> 3.0)
38
49
  rackup (~> 0.2.2)
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.adapters.get :sqlite
43
- NetBox.adapters.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
@@ -0,0 +1,5 @@
1
+ class AppBench < Liza::Bench
2
+
3
+ # Set up your bench controllers per the DSL in http://guides.lizarb.org/controllers/bench.html
4
+
5
+ end
@@ -0,0 +1,7 @@
1
+ class AppBenchTest < Liza::BenchTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == AppBench
5
+ end
6
+
7
+ end
@@ -0,0 +1,183 @@
1
+ class LoopsBench < AppBench
2
+ main_dsl
3
+
4
+ setup do
5
+ N = 1_000_000
6
+ RANGE = 1..N
7
+ ARRAY = Array RANGE
8
+ HASH_INT = RANGE.map { |i| [i, i] }.to_h
9
+ HASH_STR = RANGE.map { |i| ["a#{i}", i] }.to_h
10
+ HASH_SYM = RANGE.map { |i| [:"a#{i}", i] }.to_h
11
+ end
12
+
13
+ mark "for i in RANGE" do
14
+ for i in RANGE
15
+ a = "1"
16
+ end
17
+ end
18
+
19
+ mark "for i in ARRAY" do
20
+ for i in ARRAY
21
+ a = "1"
22
+ end
23
+ end
24
+
25
+ mark "for i, iv in HASH_INT" do
26
+ for i, iv in HASH_INT
27
+ a = "1"
28
+ end
29
+ end
30
+
31
+ mark "for i, iv in HASH_STR" do
32
+ for i, iv in HASH_STR
33
+ a = "1"
34
+ end
35
+ end
36
+
37
+ mark "for i, iv in HASH_SYM" do
38
+ for i, iv in HASH_SYM
39
+ a = "1"
40
+ end
41
+ end
42
+
43
+ mark "RANGE.each do |i|" do
44
+ RANGE.each do |i|
45
+ a = "1"
46
+ end
47
+ end
48
+
49
+ mark "ARRAY.each do |i|" do
50
+ ARRAY.each do |i|
51
+ a = "1"
52
+ end
53
+ end
54
+
55
+ mark "HASH_INT.each do |i, iv|" do
56
+ HASH_INT.each do |i, iv|
57
+ a = "1"
58
+ end
59
+ end
60
+
61
+ mark "HASH_STR.each do |i, iv|" do
62
+ HASH_STR.each do |i, iv|
63
+ a = "1"
64
+ end
65
+ end
66
+
67
+ mark "HASH_SYM.each do |i, iv|" do
68
+ HASH_SYM.each do |i, iv|
69
+ a = "1"
70
+ end
71
+ end
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
+
91
+ mark "RANGE.map do |i|" do
92
+ RANGE.map do |i|
93
+ a = "1"
94
+ end
95
+ end
96
+
97
+ mark "ARRAY.map do |i|" do
98
+ ARRAY.map do |i|
99
+ a = "1"
100
+ end
101
+ end
102
+
103
+ mark "HASH_INT.map do |i, iv|" do
104
+ HASH_INT.map do |i, iv|
105
+ a = "1"
106
+ end
107
+ end
108
+
109
+ mark "HASH_STR.map do |i, iv|" do
110
+ HASH_STR.map do |i, iv|
111
+ a = "1"
112
+ end
113
+ end
114
+
115
+ mark "HASH_SYM.map do |i, iv|" do
116
+ HASH_SYM.map do |i, iv|
117
+ a = "1"
118
+ end
119
+ end
120
+
121
+ mark "N.times do |i|" do
122
+ N.times do |i|
123
+ a = "1"
124
+ end
125
+ end
126
+
127
+ mark "1.upto N do |i|" do
128
+ 1.upto N do |i|
129
+ a = "1"
130
+ end
131
+ end
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
+
144
+ mark "loop break" do
145
+ i = 0
146
+
147
+ loop do
148
+ a = "1"
149
+ break unless (i += 1) <= N
150
+ end
151
+ end
152
+
153
+ mark "while" do
154
+ i = 0
155
+
156
+ while (i += 1) <= N
157
+ a = "1"
158
+ end
159
+ end
160
+
161
+ mark "while inline" do
162
+ i = 0
163
+
164
+ a = "1" while (i += 1) <= N
165
+ end
166
+
167
+ mark "begin end while" do
168
+ i = 0
169
+
170
+ begin
171
+ a = "1"
172
+ end while (i += 1) <= N
173
+ end
174
+
175
+ mark "begin end until" do
176
+ i = 0
177
+
178
+ begin
179
+ a = "1"
180
+ end until (i += 1) == N
181
+ end
182
+
183
+ end
@@ -0,0 +1,11 @@
1
+ class LoopsBenchTest < AppBenchTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == LoopsBench
5
+ end
6
+
7
+ test :marks do
8
+ assert subject_class.marks.keys.count.positive?
9
+ end
10
+
11
+ end
@@ -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