• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonwindowsphpgamebathyscapheguic翻訳omegattwitterframeworkbtronvb.net計画中(planning stage)testdomarduinodirectxpreviewerゲームエンジン

超漢字アプリケーション開発用のProtocol Buffersコンパイラの開発


Commit MetaInfo

Revisão748d22adc3e2b518047007c3ad42872d0b1984df (tree)
Hora2015-03-09 02:19:39
Autorornse01 <ornse01@user...>
Commiterornse01

Mensagem de Log

add ASTField.owner_message

Mudança Sumário

Diff

--- a/src/protobuf/ast.rb
+++ b/src/protobuf/ast.rb
@@ -61,6 +61,13 @@ class Protobuf::ASTField < TreeNode
6161 @tag = tag
6262 super(nil)
6363 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
6471 end
6572
6673 class Protobuf::ASTMessage < TreeNode
--- a/src/protobuf/test_ast.rb
+++ b/src/protobuf/test_ast.rb
@@ -80,6 +80,26 @@ class ProtobufAstTest < Test::Unit::TestCase
8080 assert(message2.absolute_name == 'msg2', 'invalid absolute name 2') { }
8181 end
8282
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+
83103 def test_enum
84104 field0 = Protobuf::ASTEnumConstant.new "f1", 1
85105 field1 = Protobuf::ASTEnumConstant.new "f2", 2