1require 'rdoc/test_case' 2 3class TestRDocAttr < RDoc::TestCase 4 5 def setup 6 super 7 8 @a = RDoc::Attr.new nil, 'attr', 'RW', '' 9 end 10 11 def test_aref 12 m = RDoc::Attr.new nil, 'attr', 'RW', nil 13 14 assert_equal 'attribute-i-attr', m.aref 15 end 16 17 def test_arglists 18 assert_nil @a.arglists 19 end 20 21 def test_block_params 22 assert_nil @a.block_params 23 end 24 25 def test_call_seq 26 assert_nil @a.call_seq 27 end 28 29 def test_definition 30 assert_equal 'attr_accessor', @a.definition 31 32 @a.rw = 'R' 33 34 assert_equal 'attr_reader', @a.definition 35 36 @a.rw = 'W' 37 38 assert_equal 'attr_writer', @a.definition 39 end 40 41 def test_full_name 42 assert_equal '(unknown)#attr', @a.full_name 43 end 44 45 def test_marshal_dump 46 tl = @store.add_file 'file.rb' 47 48 @a.comment = 'this is a comment' 49 @a.record_location tl 50 51 cm = tl.add_class RDoc::NormalClass, 'Klass' 52 cm.add_attribute @a 53 54 section = cm.sections.first 55 56 loaded = Marshal.load Marshal.dump @a 57 loaded.store = @store 58 59 assert_equal @a, loaded 60 61 comment = RDoc::Markup::Document.new( 62 RDoc::Markup::Paragraph.new('this is a comment')) 63 64 assert_equal comment, loaded.comment 65 assert_equal 'file.rb', loaded.file.relative_name 66 assert_equal 'Klass#attr', loaded.full_name 67 assert_equal 'attr', loaded.name 68 assert_equal 'RW', loaded.rw 69 assert_equal false, loaded.singleton 70 assert_equal :public, loaded.visibility 71 assert_equal tl, loaded.file 72 assert_equal cm, loaded.parent 73 assert_equal section, loaded.section 74 end 75 76 def test_marshal_dump_singleton 77 tl = @store.add_file 'file.rb' 78 79 @a.comment = 'this is a comment' 80 @a.record_location tl 81 82 cm = tl.add_class RDoc::NormalClass, 'Klass' 83 cm.add_attribute @a 84 85 section = cm.sections.first 86 87 @a.rw = 'R' 88 @a.singleton = true 89 @a.visibility = :protected 90 91 loaded = Marshal.load Marshal.dump @a 92 loaded.store = @store 93 94 assert_equal @a, loaded 95 96 comment = RDoc::Markup::Document.new( 97 RDoc::Markup::Paragraph.new('this is a comment')) 98 99 assert_equal comment, loaded.comment 100 assert_equal 'Klass::attr', loaded.full_name 101 assert_equal 'attr', loaded.name 102 assert_equal 'R', loaded.rw 103 assert_equal true, loaded.singleton 104 assert_equal :protected, loaded.visibility 105 assert_equal tl, loaded.file 106 assert_equal cm, loaded.parent 107 assert_equal section, loaded.section 108 end 109 110 def test_marshal_load_version_1 111 tl = @store.add_file 'file.rb' 112 cm = tl.add_class RDoc::NormalClass, 'Klass' 113 section = cm.sections.first 114 115 data = "\x04\bU:\x0FRDoc::Attr[\fi\x06I\"\tattr\x06:\x06EF" + 116 "\"\x0FKlass#attrI\"\aRW\x06;\x06F:\vpublic" + 117 "o:\eRDoc::Markup::Document\x06:\v@parts[\x06" + 118 "o:\x1CRDoc::Markup::Paragraph\x06;\t[\x06I" + 119 "\"\x16this is a comment\x06;\x06FF" 120 121 loaded = Marshal.load data 122 loaded.store = @store 123 124 comment = RDoc::Markup::Document.new( 125 RDoc::Markup::Paragraph.new('this is a comment')) 126 127 assert_equal comment, loaded.comment 128 assert_equal 'Klass#attr', loaded.full_name 129 assert_equal 'attr', loaded.name 130 assert_equal 'RW', loaded.rw 131 assert_equal false, loaded.singleton 132 assert_equal :public, loaded.visibility 133 134 # version 2 135 assert_nil loaded.file 136 137 # version 3 138 assert_equal cm, loaded.parent 139 assert_equal section, loaded.section 140 141 assert loaded.display? 142 end 143 144 def test_marshal_load_version_2 145 tl = @store.add_file 'file.rb' 146 cm = tl.add_class RDoc::NormalClass, 'Klass' 147 section = cm.sections.first 148 149 loaded = Marshal.load "\x04\bU:\x0FRDoc::Attr[\ri\aI\"\tattr\x06" + 150 ":\x06ETI\"\x0FKlass#attr\x06;\x06TI\"\aRW\x06" + 151 ";\x06T:\vpublico:\eRDoc::Markup::Document\a" + 152 ":\v@parts[\x06o:\x1CRDoc::Markup::Paragraph\x06;" + 153 "\t[\x06I\"\x16this is a comment\x06;\x06T:\n" + 154 "@file0FI\"\ffile.rb\x06;\x06T" 155 loaded.store = @store 156 157 comment = doc(para('this is a comment')) 158 159 assert_equal comment, loaded.comment 160 assert_equal 'Klass#attr', loaded.full_name 161 assert_equal 'attr', loaded.name 162 assert_equal 'RW', loaded.rw 163 assert_equal false, loaded.singleton 164 assert_equal :public, loaded.visibility 165 assert_equal tl, loaded.file 166 167 # version 3 168 assert_equal cm, loaded.parent 169 assert_equal section, loaded.section 170 171 assert loaded.display? 172 end 173 174 def test_params 175 assert_nil @a.params 176 end 177 178 def test_singleton 179 refute @a.singleton 180 end 181 182 def test_type 183 assert_equal 'instance', @a.type 184 185 @a.singleton = true 186 assert_equal 'class', @a.type 187 end 188 189end 190 191