mrubyc-test 0.7.0.pre.rc0 → 0.7.0.pre.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3999a4b4fc42b7080d1e1923475b9b175c0bfefb9f7438aab342a61d2693de38
4
- data.tar.gz: d734e7f81126a95414c4aff68175f57410653a45e15b4b3d72f5a6ef1cc69e9c
3
+ metadata.gz: a7ba5b056b71ff5fc5377dda272e651a3784dfdc7627f3a746e7ce6bb30ff975
4
+ data.tar.gz: 2d587b1e8d998ba84434634ff0f7599ccec2bd69b41a41ac80693b057593fb67
5
5
  SHA512:
6
- metadata.gz: a28f63efee86b0222ad4c316cf90023fefa18331179f591251d45f5f7145c3bdb102650386a93332869e5bb454f4e8fec6fb5a414233d516e8279aff0a3e6c28
7
- data.tar.gz: e8ffe7d3cd5f3414bf91d37a2dcd8f5da9dc79261f9fc733dda0faf085bdca5f13f4c93452b43b583848560cb3fb7aeb10454c8571c0d398e975c984fc84d812
6
+ metadata.gz: a0c73ee66679987cc53adc9631e500f3cec3a70107807c3bebede1f3310dc2846db4e367a9eb215172b72c2535ddd7353a350bf50eeb45760d911ed7366ba6a5
7
+ data.tar.gz: a8a29d343d482ce81c2d83221f788d3cf9997739cafee556b2d3cd0342dee43d6e8a28880d5504e00fdc9465e68013e3da3c63dac754bd397ea72b4ad443e0c8
data/README.md CHANGED
@@ -119,17 +119,17 @@ end
119
119
  ```ruby
120
120
  class Sample
121
121
  def do_other_thing
122
- is_to_be_hit()
122
+ is_to_be_hit(1, 2) # Two args for example
123
123
  end
124
124
  end
125
125
  ```
126
126
 
127
- You can test whether `#is_to_be_hit` method will be called:
127
+ You can test whether `#is_to_be_hit(v1, v2)` method will be called:
128
128
 
129
129
  ```ruby
130
130
  def mock_case
131
131
  sample_obj = Sample.new
132
- mock(sample_obj).is_to_be_hit
132
+ mock(sample_obj).is_to_be_hit(2) # `2` should be count of parameters
133
133
  sample_obj.do_other_thing
134
134
  end
135
135
  ```
@@ -13,9 +13,12 @@ module Mrubyc
13
13
  puts "loading #{model_file}"
14
14
  load model_file
15
15
  class_name = File.basename(model_file, '.rb').camelize
16
- begin
17
- model_class = Module.const_get(class_name)
18
- rescue NameError => e
16
+ model_class = if Module.const_defined?(class_name)
17
+ Module.const_get(class_name)
18
+ elsif Module.const_defined?(class_name.upcase)
19
+ Module.const_get(class_name.upcase)
20
+ end
21
+ unless model_class
19
22
  print "\e[33m"
20
23
  puts "[WARN] #{model_file} doesn't have corresponding class `#{class_name}`."
21
24
  print "\e[m"
@@ -17,11 +17,13 @@ module Mrubyc
17
17
  end
18
18
 
19
19
  def method_missing(method_name, *args)
20
+ param_size = args[0] || 0
20
21
  @@double_method_locations << {
21
22
  type: @type,
22
23
  class: @klass,
23
24
  method_name: method_name,
24
25
  args: args.to_s,
26
+ method_parameters: Array.new(param_size).map.with_index{|_, i| ('a'.ord + i).chr }.join(','),
25
27
  block: (block_given? ? yield : nil),
26
28
  label: @location.label,
27
29
  path: @location.absolute_path || @location.path,
@@ -31,6 +31,7 @@ module Mrubyc
31
31
  instance_variables: nil, # TODO
32
32
  method_name: double[:method_name].to_s,
33
33
  args: double[:args],
34
+ method_parameters: double[:method_parameters],
34
35
  return_value: double[:block],
35
36
  line: double[:line]
36
37
  }
@@ -1,5 +1,5 @@
1
1
  module Mrubyc
2
2
  module Test
3
- VERSION = "0.7.0-rc0"
3
+ VERSION = "0.7.0-rc1"
4
4
  end
5
5
  end
@@ -16,8 +16,8 @@ class Object
16
16
  'Array'
17
17
  when FalseClass
18
18
  'FalseClass'
19
- when Fixnum
20
- 'Fixnum'
19
+ when Integer
20
+ 'Integer'
21
21
  when Float
22
22
  'Float'
23
23
  when Hash
@@ -4,19 +4,37 @@
4
4
  #include "models.c"
5
5
  #include "test.c"
6
6
 
7
- #define MEMORY_SIZE (1024*64)-1
7
+ #define MEMORY_SIZE (1024*640)-1
8
8
  static uint8_t my_memory_pool[MEMORY_SIZE];
9
9
 
10
- int exit_code;
10
+ int exit_code = 0;
11
11
 
12
- static void c_exit(mrb_vm *vm, mrb_value *v, int argc){
12
+ static void c_exit(struct VM *vm, mrbc_value v[], int argc)
13
+ {
13
14
  exit_code = GET_INT_ARG(1);
14
15
  }
15
16
 
17
+ //================================================================
18
+ /*! Object#instance_variable_get
19
+ */
20
+ static void c_instance_variable_get(struct VM *vm, mrbc_value v[], int argc)
21
+ {
22
+ mrbc_kv_handle *kvh = &v[0].instance->ivar;
23
+ const char *name = (const char *)GET_STRING_ARG(1);
24
+ for(int i = 0; i < kvh->n_stored; i++) {
25
+ if (strncmp(&name[1], symid_to_str(kvh->data[i].sym_id), strlen(name) - 1) == 0) {
26
+ SET_RETURN(kvh->data[i].value);
27
+ return;
28
+ }
29
+ }
30
+ SET_NIL_RETURN();
31
+ }
32
+
16
33
  //================================================================
17
34
  /*! DEBUG PRINT
18
35
  */
19
- static void c_debugprint(mrb_vm *vm, mrb_value *v, int argc){
36
+ static void c_debugprint(struct VM *vm, mrbc_value v[], int argc)
37
+ {
20
38
  console_putchar('\n');
21
39
  for( int i = 0; i < 79; i++ ) { console_putchar('='); }
22
40
  console_putchar('\n');
@@ -34,6 +52,7 @@ int main(void) {
34
52
  mrbc_init(my_memory_pool, MEMORY_SIZE);
35
53
  mrbc_define_method(0, mrbc_class_object, "debugprint", c_debugprint);
36
54
  mrbc_define_method(0, mrbc_class_object, "exit", c_exit);
55
+ mrbc_define_method(0, mrbc_class_object, "instance_variable_get", c_instance_variable_get);
37
56
  mrbc_create_task( models, 0 );
38
57
  mrbc_create_task( test, 0 );
39
58
  mrbc_run();
@@ -108,7 +108,7 @@ end
108
108
  <% end -%>
109
109
  <% test_case[:mocks].each do |mock| -%>
110
110
  class <%= mock[:class_name] %>
111
- def <%= mock[:method_name] %>
111
+ def <%= mock[:method_name] %>(<%= mock[:method_parameters] %>)
112
112
  $mock.actual.add_by_key :<%= mock[:method_name] %>
113
113
  end
114
114
  end
@@ -126,7 +126,7 @@ end
126
126
  end
127
127
  <% test_case[:mocks].each do |mock| -%>
128
128
  class <%= mock[:class_name] %>Double
129
- def <%= mock[:method_name] %>
129
+ def <%= mock[:method_name] %>(_param_size = 0)
130
130
  $mock.expected.add_by_key :<%= mock[:method_name] %>
131
131
  end
132
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mrubyc-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.pre.rc0
4
+ version: 0.7.0.pre.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASUMI Hitoshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-23 00:00:00.000000000 Z
11
+ date: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler