2012-11-26 23:28:14 -05:00
|
|
|
require 'rdoc/test_case'
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
class TestRDocAttr < RDoc::TestCase
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
def setup
|
2012-11-26 23:28:14 -05:00
|
|
|
super
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
@a = RDoc::Attr.new nil, 'attr', 'RW', ''
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def test_aref
|
|
|
|
m = RDoc::Attr.new nil, 'attr', 'RW', nil
|
|
|
|
|
|
|
|
assert_equal 'attribute-i-attr', m.aref
|
|
|
|
end
|
|
|
|
|
2010-04-10 02:36:13 -04:00
|
|
|
def test_arglists
|
|
|
|
assert_nil @a.arglists
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_block_params
|
|
|
|
assert_nil @a.block_params
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_call_seq
|
|
|
|
assert_nil @a.call_seq
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def test_definition
|
|
|
|
assert_equal 'attr_accessor', @a.definition
|
|
|
|
|
|
|
|
@a.rw = 'R'
|
|
|
|
|
|
|
|
assert_equal 'attr_reader', @a.definition
|
|
|
|
|
|
|
|
@a.rw = 'W'
|
|
|
|
|
|
|
|
assert_equal 'attr_writer', @a.definition
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_full_name
|
|
|
|
assert_equal '(unknown)#attr', @a.full_name
|
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
def test_marshal_dump
|
2012-11-26 23:28:14 -05:00
|
|
|
tl = @store.add_file 'file.rb'
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
@a.comment = 'this is a comment'
|
|
|
|
@a.record_location tl
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
cm = tl.add_class RDoc::NormalClass, 'Klass'
|
2011-06-16 00:59:24 -04:00
|
|
|
cm.add_attribute @a
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
section = cm.sections.first
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
loaded = Marshal.load Marshal.dump @a
|
2012-11-26 23:28:14 -05:00
|
|
|
loaded.store = @store
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert_equal @a, loaded
|
|
|
|
|
|
|
|
comment = RDoc::Markup::Document.new(
|
|
|
|
RDoc::Markup::Paragraph.new('this is a comment'))
|
|
|
|
|
|
|
|
assert_equal comment, loaded.comment
|
|
|
|
assert_equal 'file.rb', loaded.file.relative_name
|
|
|
|
assert_equal 'Klass#attr', loaded.full_name
|
|
|
|
assert_equal 'attr', loaded.name
|
|
|
|
assert_equal 'RW', loaded.rw
|
|
|
|
assert_equal false, loaded.singleton
|
|
|
|
assert_equal :public, loaded.visibility
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal tl, loaded.file
|
|
|
|
assert_equal cm, loaded.parent
|
|
|
|
assert_equal section, loaded.section
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_marshal_dump_singleton
|
|
|
|
tl = @store.add_file 'file.rb'
|
|
|
|
|
|
|
|
@a.comment = 'this is a comment'
|
|
|
|
@a.record_location tl
|
|
|
|
|
|
|
|
cm = tl.add_class RDoc::NormalClass, 'Klass'
|
|
|
|
cm.add_attribute @a
|
|
|
|
|
|
|
|
section = cm.sections.first
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
@a.rw = 'R'
|
|
|
|
@a.singleton = true
|
|
|
|
@a.visibility = :protected
|
|
|
|
|
|
|
|
loaded = Marshal.load Marshal.dump @a
|
2012-11-26 23:28:14 -05:00
|
|
|
loaded.store = @store
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert_equal @a, loaded
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
comment = RDoc::Markup::Document.new(
|
|
|
|
RDoc::Markup::Paragraph.new('this is a comment'))
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
assert_equal comment, loaded.comment
|
|
|
|
assert_equal 'Klass::attr', loaded.full_name
|
|
|
|
assert_equal 'attr', loaded.name
|
|
|
|
assert_equal 'R', loaded.rw
|
|
|
|
assert_equal true, loaded.singleton
|
|
|
|
assert_equal :protected, loaded.visibility
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal tl, loaded.file
|
|
|
|
assert_equal cm, loaded.parent
|
|
|
|
assert_equal section, loaded.section
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_marshal_load_version_1
|
2012-11-26 23:28:14 -05:00
|
|
|
tl = @store.add_file 'file.rb'
|
|
|
|
cm = tl.add_class RDoc::NormalClass, 'Klass'
|
|
|
|
section = cm.sections.first
|
|
|
|
|
|
|
|
data = "\x04\bU:\x0FRDoc::Attr[\fi\x06I\"\tattr\x06:\x06EF" +
|
|
|
|
"\"\x0FKlass#attrI\"\aRW\x06;\x06F:\vpublic" +
|
|
|
|
"o:\eRDoc::Markup::Document\x06:\v@parts[\x06" +
|
|
|
|
"o:\x1CRDoc::Markup::Paragraph\x06;\t[\x06I" +
|
2011-06-16 00:59:24 -04:00
|
|
|
"\"\x16this is a comment\x06;\x06FF"
|
|
|
|
|
|
|
|
loaded = Marshal.load data
|
2012-11-26 23:28:14 -05:00
|
|
|
loaded.store = @store
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
comment = RDoc::Markup::Document.new(
|
|
|
|
RDoc::Markup::Paragraph.new('this is a comment'))
|
|
|
|
|
|
|
|
assert_equal comment, loaded.comment
|
|
|
|
assert_equal 'Klass#attr', loaded.full_name
|
|
|
|
assert_equal 'attr', loaded.name
|
|
|
|
assert_equal 'RW', loaded.rw
|
|
|
|
assert_equal false, loaded.singleton
|
|
|
|
assert_equal :public, loaded.visibility
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
# version 2
|
|
|
|
assert_nil loaded.file
|
|
|
|
|
|
|
|
# version 3
|
|
|
|
assert_equal cm, loaded.parent
|
|
|
|
assert_equal section, loaded.section
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_marshal_load_version_2
|
|
|
|
tl = @store.add_file 'file.rb'
|
|
|
|
cm = tl.add_class RDoc::NormalClass, 'Klass'
|
|
|
|
section = cm.sections.first
|
|
|
|
|
|
|
|
loaded = Marshal.load "\x04\bU:\x0FRDoc::Attr[\ri\aI\"\tattr\x06" +
|
|
|
|
":\x06ETI\"\x0FKlass#attr\x06;\x06TI\"\aRW\x06" +
|
|
|
|
";\x06T:\vpublico:\eRDoc::Markup::Document\a" +
|
|
|
|
":\v@parts[\x06o:\x1CRDoc::Markup::Paragraph\x06;" +
|
|
|
|
"\t[\x06I\"\x16this is a comment\x06;\x06T:\n" +
|
|
|
|
"@file0FI\"\ffile.rb\x06;\x06T"
|
|
|
|
loaded.store = @store
|
|
|
|
|
|
|
|
comment = doc(para('this is a comment'))
|
|
|
|
|
|
|
|
assert_equal comment, loaded.comment
|
|
|
|
assert_equal 'Klass#attr', loaded.full_name
|
|
|
|
assert_equal 'attr', loaded.name
|
|
|
|
assert_equal 'RW', loaded.rw
|
|
|
|
assert_equal false, loaded.singleton
|
|
|
|
assert_equal :public, loaded.visibility
|
|
|
|
assert_equal tl, loaded.file
|
|
|
|
|
|
|
|
# version 3
|
|
|
|
assert_equal cm, loaded.parent
|
|
|
|
assert_equal section, loaded.section
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
2010-04-10 02:36:13 -04:00
|
|
|
def test_params
|
|
|
|
assert_nil @a.params
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_singleton
|
|
|
|
refute @a.singleton
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_type
|
2010-12-19 22:22:49 -05:00
|
|
|
assert_equal 'instance', @a.type
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
@a.singleton = true
|
|
|
|
assert_equal 'class', @a.type
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|