超漢字アプリケーション開発用のProtocol Buffersコンパイラの開発
Revision | 748d22adc3e2b518047007c3ad42872d0b1984df (tree) |
---|---|
Time | 2015-03-09 02:19:39 |
Author | ornse01 <ornse01@user...> |
Commiter | ornse01 |
add ASTField.owner_message
@@ -61,6 +61,13 @@ class Protobuf::ASTField < TreeNode | ||
61 | 61 | @tag = tag |
62 | 62 | super(nil) |
63 | 63 | end |
64 | + | |
65 | + def owner_message | |
66 | + self | |
67 | + .enum_for(:ancestral_each) | |
68 | + .select{ |item| item.is_a? Protobuf::ASTMessage } | |
69 | + .first | |
70 | + end | |
64 | 71 | end |
65 | 72 | |
66 | 73 | class Protobuf::ASTMessage < TreeNode |
@@ -80,6 +80,26 @@ class ProtobufAstTest < Test::Unit::TestCase | ||
80 | 80 | assert(message2.absolute_name == 'msg2', 'invalid absolute name 2') { } |
81 | 81 | end |
82 | 82 | |
83 | + def test_field_owner_message | |
84 | + field0 = Protobuf::ASTField.new :required, :int32, "f1", 1 | |
85 | + field1 = Protobuf::ASTField.new :optional, :string, "f2", 2 | |
86 | + message0 = Protobuf::ASTMessage.new "msg0", [field0, field1] | |
87 | + field2 = Protobuf::ASTField.new :required, :int32, "f1", 1 | |
88 | + field3 = Protobuf::ASTField.new :optional, :string, "f2", 2 | |
89 | + message1 = Protobuf::ASTMessage.new "msg1", [field2, field3, message0] | |
90 | + field4 = Protobuf::ASTField.new :required, :int32, "f1", 1 | |
91 | + field5 = Protobuf::ASTField.new :optional, :string, "f2", 2 | |
92 | + message2 = Protobuf::ASTMessage.new "msg2", [field4, field5, message1] | |
93 | + root = Protobuf::ASTRoot.new [message2] | |
94 | + | |
95 | + assert(field0.owner_message == message0, 'invalid owner 0') { } | |
96 | + assert(field1.owner_message == message0, 'invalid owner 1') { } | |
97 | + assert(field2.owner_message == message1, 'invalid owner 2') { } | |
98 | + assert(field3.owner_message == message1, 'invalid owner 3') { } | |
99 | + assert(field4.owner_message == message2, 'invalid owner 4') { } | |
100 | + assert(field5.owner_message == message2, 'invalid owner 5') { } | |
101 | + end | |
102 | + | |
83 | 103 | def test_enum |
84 | 104 | field0 = Protobuf::ASTEnumConstant.new "f1", 1 |
85 | 105 | field1 = Protobuf::ASTEnumConstant.new "f2", 2 |