Skip to content

Commit f7bc54b

Browse files
authored
Merge pull request #82 from sue445/feature/refactor_test
Refactor test and sig
2 parents 3b8377f + 8c83edc commit f7bc54b

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

testdata/dummy/ext/dummy/tests.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ VALUE rb_dummy_tests_rb_funcall2(VALUE self, VALUE num, VALUE ndigits);
1111
VALUE rb_dummy_tests_rb_funcall3(VALUE self, VALUE num, VALUE ndigits);
1212
void rb_dummy_tests_rb_alias(VALUE self, VALUE dst, VALUE src);
1313
VALUE rb_dummy_tests_rb_class2name(VALUE self);
14-
void rb_dummy_tests_rb_attr(VALUE self, VALUE needReader, VALUE needWriter, VALUE honourVisibility);
14+
void rb_dummy_tests_rb_attr(VALUE self, VALUE name, VALUE needReader, VALUE needWriter, VALUE honourVisibility);
1515
VALUE rb_dummy_tests_rb_const_get(VALUE self, VALUE name);
1616
*/
1717
import "C"
@@ -93,12 +93,13 @@ func rb_dummy_tests_rb_class2name(klass C.VALUE) C.VALUE {
9393
}
9494

9595
//export rb_dummy_tests_rb_attr
96-
func rb_dummy_tests_rb_attr(klass C.VALUE, needReader C.VALUE, needWriter C.VALUE, honourVisibility C.VALUE) {
96+
func rb_dummy_tests_rb_attr(klass C.VALUE, name C.VALUE, needReader C.VALUE, needWriter C.VALUE, honourVisibility C.VALUE) {
97+
ivarName := ruby.Value2String(ruby.VALUE(name))
9798
intNeedReader := ruby.NUM2INT(ruby.VALUE(needReader))
9899
intNeedWriter := ruby.NUM2INT(ruby.VALUE(needWriter))
99100
intHonourVisibility := ruby.NUM2INT(ruby.VALUE(honourVisibility))
100101

101-
ruby.RbAttr(ruby.VALUE(klass), ruby.RbIntern("ivar2"), intNeedReader != 0, intNeedWriter != 0, intHonourVisibility != 0)
102+
ruby.RbAttr(ruby.VALUE(klass), ruby.RbIntern(ivarName), intNeedReader != 0, intNeedWriter != 0, intHonourVisibility != 0)
102103
}
103104

104105
//export rb_dummy_tests_rb_const_get
@@ -121,6 +122,6 @@ func defineMethodsToDummyTests(rb_mDummy ruby.VALUE) {
121122
ruby.RbDefineSingletonMethod(rb_cTests, "rb_funcall3", C.rb_dummy_tests_rb_funcall3, 2)
122123
ruby.RbDefineSingletonMethod(rb_cTests, "rb_alias", C.rb_dummy_tests_rb_alias, 2)
123124
ruby.RbDefineSingletonMethod(rb_cTests, "rb_class2name", C.rb_dummy_tests_rb_class2name, 0)
124-
ruby.RbDefineSingletonMethod(rb_cTests, "rb_attr", C.rb_dummy_tests_rb_attr, 3)
125+
ruby.RbDefineSingletonMethod(rb_cTests, "rb_attr", C.rb_dummy_tests_rb_attr, 4)
125126
ruby.RbDefineSingletonMethod(rb_cTests, "rb_const_get", C.rb_dummy_tests_rb_const_get, 1)
126127
}

testdata/dummy/sig/dummy/tests.rbs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Dummy
22
class Tests
3-
CONST: string
3+
CONST: untyped
44

55
@ivar: untyped
66
@ivar2: untyped
@@ -18,6 +18,7 @@ module Dummy
1818
def self.rb_funcall3: (Integer num, Integer ndigits) -> Integer
1919
def self.rb_alias: (string dst, string src) -> void
2020
def self.rb_class2name: () -> string
21-
def self.rb_attr: (Integer need_reader, Integer need_writer, Integer honour_visibility) -> void
21+
def self.rb_attr: (string name, Integer need_reader, Integer need_writer, Integer honour_visibility) -> void
22+
def self.rb_const_get: (string name) -> untyped
2223
end
2324
end

testdata/dummy/spec/dummy/tests_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898

9999
context "when attr_reader" do
100100
it "works" do
101-
Dummy::Tests.rb_attr(1, 0, 0)
101+
Dummy::Tests.rb_attr("ivar2", 1, 0, 0)
102102

103103
t = Dummy::Tests.new
104104
expect(t).to be_respond_to :ivar2
@@ -108,7 +108,7 @@
108108

109109
context "when attr_writer" do
110110
it "works" do
111-
Dummy::Tests.rb_attr(0, 1, 0)
111+
Dummy::Tests.rb_attr("ivar2", 0, 1, 0)
112112

113113
t = Dummy::Tests.new
114114
expect(t).not_to be_respond_to :ivar2
@@ -118,7 +118,7 @@
118118

119119
context "when attr_accessor" do
120120
it "works" do
121-
Dummy::Tests.rb_attr(1, 1, 0)
121+
Dummy::Tests.rb_attr("ivar2", 1, 1, 0)
122122

123123
t = Dummy::Tests.new
124124
expect(t).to be_respond_to :ivar2

0 commit comments

Comments
 (0)