amrita2 1.9.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +112 -0
- data/init.rb +6 -0
- data/lib/amrita2/gettext.rb +116 -0
- data/lib/amrita2/macro.rb +153 -0
- data/lib/amrita2/rails_bridge.rb +172 -26
- data/lib/amrita2/template.rb +2634 -234
- data/lib/amrita2/testsupport.rb +171 -0
- data/lib/amrita2/version.rb +3 -3
- data/lib/amrita2.rb +1 -0
- data/sample/depot/app/controllers/admin_controller.rb +59 -0
- data/sample/depot/app/controllers/application.rb +20 -0
- data/sample/depot/app/controllers/info_controller.rb +19 -0
- data/sample/depot/app/controllers/login_controller.rb +85 -0
- data/sample/depot/app/controllers/store_controller.rb +68 -0
- data/sample/depot/app/helpers/admin_helper.rb +7 -0
- data/sample/depot/app/helpers/application_helper.rb +10 -0
- data/sample/depot/app/helpers/ar_form.rb +169 -0
- data/sample/depot/app/helpers/form_tag.rb +24 -0
- data/sample/depot/app/helpers/info_helper.rb +7 -0
- data/sample/depot/app/helpers/standard_form.rb +73 -0
- data/sample/depot/app/helpers/store_helper.rb +14 -0
- data/sample/depot/app/models/cart.rb +36 -0
- data/sample/depot/app/models/cart_item.rb +26 -0
- data/sample/depot/app/models/line_item.rb +34 -0
- data/sample/depot/app/models/order.rb +57 -0
- data/sample/depot/app/models/product.rb +41 -0
- data/sample/depot/app/models/user.rb +83 -0
- data/sample/depot/config/boot.rb +49 -0
- data/sample/depot/config/environment.rb +83 -0
- data/sample/depot/config/environments/development.rb +24 -0
- data/sample/depot/config/environments/production.rb +24 -0
- data/sample/depot/config/environments/test.rb +24 -0
- data/sample/depot/config/routes.rb +10 -0
- data/sample/depot/db/migrate/001_create_products.rb +18 -0
- data/sample/depot/db/migrate/002_add_price.rb +14 -0
- data/sample/depot/db/migrate/003_add_test_data.rb +68 -0
- data/sample/depot/db/migrate/004_add_sessions.rb +20 -0
- data/sample/depot/db/migrate/005_create_orders.rb +21 -0
- data/sample/depot/db/migrate/006_create_line_items.rb +27 -0
- data/sample/depot/db/migrate/007_create_users.rb +18 -0
- data/sample/depot/db/schema.rb +45 -0
- data/sample/depot/public/dispatch.rb +15 -0
- data/sample/depot/test/functional/admin_controller_test.rb +54 -0
- data/sample/depot/test/functional/info_controller_test.rb +23 -0
- data/sample/depot/test/functional/login_controller_test.rb +74 -0
- data/sample/depot/test/functional/store_controller_test.rb +57 -0
- data/sample/depot/test/integration/dsl_user_stories_test.rb +126 -0
- data/sample/depot/test/integration/user_stories_test.rb +70 -0
- data/sample/depot/test/performance/order_speed_test.rb +58 -0
- data/sample/depot/test/test_helper.rb +16 -0
- data/sample/depot/test/unit/cart_test.rb +39 -0
- data/sample/depot/test/unit/cart_test1.rb +31 -0
- data/sample/depot/test/unit/line_item_test.rb +15 -0
- data/sample/depot/test/unit/order_test.rb +15 -0
- data/sample/depot/test/unit/product_test.rb +98 -0
- data/sample/depot/vendor/plugins/amrita2/init.rb +6 -0
- data/sample/hello/hello.rb +22 -0
- data/sample/login_engine/app/controllers/application.rb +16 -0
- data/sample/login_engine/app/controllers/user_controller.rb +265 -0
- data/sample/login_engine/app/helpers/application_helper.rb +3 -0
- data/sample/login_engine/app/helpers/form_tag.rb +16 -0
- data/sample/login_engine/app/helpers/two_columns.rb +24 -0
- data/sample/login_engine/app/helpers/two_columns_form.rb +47 -0
- data/sample/login_engine/app/helpers/user_helper.rb +88 -0
- data/sample/login_engine/app/models/user.rb +7 -0
- data/sample/login_engine/app/models/user_notify.rb +75 -0
- data/sample/login_engine/config/boot.rb +45 -0
- data/sample/login_engine/config/environment.rb +140 -0
- data/sample/login_engine/config/environments/development.rb +21 -0
- data/sample/login_engine/config/environments/production.rb +18 -0
- data/sample/login_engine/config/environments/test.rb +19 -0
- data/sample/login_engine/config/routes.rb +23 -0
- data/sample/login_engine/db/migrate/001_create_users.rb +25 -0
- data/sample/login_engine/db/schema.rb +25 -0
- data/sample/login_engine/lib/config.rb +113 -0
- data/sample/login_engine/lib/hpricot_test_extension.rb +80 -0
- data/sample/login_engine/lib/login_engine/authenticated_system.rb +113 -0
- data/sample/login_engine/lib/login_engine/authenticated_user.rb +155 -0
- data/sample/login_engine/lib/login_engine.rb +62 -0
- data/sample/login_engine/public/dispatch.rb +10 -0
- data/sample/login_engine/test/functional/amrita2_test.rb +267 -0
- data/sample/login_engine/test/functional/user_controller_test.rb +544 -0
- data/sample/login_engine/test/mocks/mail.rb +14 -0
- data/sample/login_engine/test/mocks/time.rb +19 -0
- data/sample/login_engine/test/test_helper.rb +31 -0
- data/sample/login_engine/test/unit/user_test.rb +116 -0
- data/sample/login_engine/vendor/plugins/amrita2/init.rb +6 -0
- data/specs/attribute.rb +201 -0
- data/specs/datatypes.rb +231 -0
- data/specs/dictionary.rb +68 -0
- data/specs/erb_cdata.rb +187 -0
- data/specs/filters.rb +513 -0
- data/specs/gettext/erb_gettext.rb +42 -0
- data/specs/gettext/gettext_util.rb +65 -0
- data/specs/gettext/static_text.rb +103 -0
- data/specs/impl/code_generator.rb +87 -0
- data/specs/impl/dynamic_element.rb +92 -0
- data/specs/impl/hash_delegator.rb +57 -0
- data/specs/impl/parse_opt.rb +34 -0
- data/specs/impl/preprocess.rb +823 -0
- data/specs/impl/testsupport.rb +89 -0
- data/specs/inlineruby.rb +429 -0
- data/specs/intro.rb +654 -0
- data/specs/loop.rb +203 -0
- data/specs/macro.rb +532 -0
- data/specs/sample.rb +34 -0
- data/specs/sanitize.rb +110 -0
- data/specs/template.rb +189 -0
- data/specs/trace.rb +97 -0
- metadata +138 -19
- data/lib/amrita2/core.rb +0 -1897
- data/lib/amrita2/rd.rb +0 -314
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'amrita2'
|
3
|
+
require 'amrita2/testsupport'
|
4
|
+
require 'amrita2/template'
|
5
|
+
require 'amrita2/gettext'
|
6
|
+
require 'gettext/utils'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
include Amrita2
|
10
|
+
include Amrita2::Filters
|
11
|
+
include Amrita2::GetTextBridge
|
12
|
+
|
13
|
+
require File::dirname(__FILE__) + '/gettext_util'
|
14
|
+
|
15
|
+
$KCODE='u'
|
16
|
+
|
17
|
+
context "gettext erb element" do
|
18
|
+
include Amrita2::Runtime
|
19
|
+
include Amrita2GetTextTestSupport
|
20
|
+
|
21
|
+
specify "simple erb element" do
|
22
|
+
domain = "erb1"
|
23
|
+
temp = "/tmp/amrita_gettext_test.a2html"
|
24
|
+
Locale.set_current("ja", "JP", "utf8")
|
25
|
+
b = binding
|
26
|
+
test_gettext(
|
27
|
+
domain,
|
28
|
+
temp,
|
29
|
+
"<span><![CDATA[ <%=_('test message printed in ERB')%> ]]></span>",
|
30
|
+
[
|
31
|
+
%r[#: #{temp}:-],
|
32
|
+
%r[msgid "test message printed in ERB"],
|
33
|
+
],
|
34
|
+
b,
|
35
|
+
"ERBで出力したテストメッセージ"
|
36
|
+
) do |l|
|
37
|
+
l.sub!(%r[msgid "test message printed in ERB"\nmsgstr ""]m,
|
38
|
+
%[msgid "test message printed in ERB"\nmsgstr "ERBで出力したテストメッセージ"])
|
39
|
+
l
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
module Amrita2GetTextTestSupport
|
3
|
+
|
4
|
+
def redirect_stderr
|
5
|
+
stderr_sv = STDERR.dup
|
6
|
+
STDERR.reopen("/dev/null")
|
7
|
+
yield
|
8
|
+
STDERR.flush
|
9
|
+
STDERR.reopen(stderr_sv)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_gettext(domain, fname, template, po_matchers, data, ja_result)
|
13
|
+
FileUtils::rm_rf("locale")
|
14
|
+
FileUtils::rm_rf("po")
|
15
|
+
FileUtils::rm_rf(fname)
|
16
|
+
|
17
|
+
File::open(fname, "w") do |f|
|
18
|
+
f.puts template
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
redirect_stderr do
|
23
|
+
GetText.update_pofiles(domain,
|
24
|
+
[fname],
|
25
|
+
"#{domain} 1.0.0"
|
26
|
+
)
|
27
|
+
end
|
28
|
+
po = File::open("po/#{domain}.pot").read
|
29
|
+
|
30
|
+
po_matchers.each do |m|
|
31
|
+
po.should match(m)
|
32
|
+
end
|
33
|
+
|
34
|
+
FileUtils::mkdir_p("po/ja")
|
35
|
+
File::open("po/#{domain}.pot") do |potf|
|
36
|
+
File::open("po/ja/#{domain}.po", "w") do |pof|
|
37
|
+
l = yield(potf.read)
|
38
|
+
pof.puts l
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
redirect_stderr do
|
43
|
+
GetText.create_mofiles(true, "po", "locale")
|
44
|
+
end
|
45
|
+
|
46
|
+
Locale.set_current("ja", "JP", "utf8")
|
47
|
+
ENV['GETTEXT_PATH'] = "./locale"
|
48
|
+
|
49
|
+
t = Template.new(template) do |e, src, filters|
|
50
|
+
filters << Amrita2::Filters::GetTextFilter.new
|
51
|
+
end
|
52
|
+
|
53
|
+
t.text_domain = domain
|
54
|
+
if data.kind_of?(Binding)
|
55
|
+
eval "bindtextdomain(#{domain.inspect})", data
|
56
|
+
end
|
57
|
+
t.test_with(data) do |result|
|
58
|
+
result.strip.should_be_samexml_as ja_result
|
59
|
+
end
|
60
|
+
ensure
|
61
|
+
FileUtils::rm_rf("locale")
|
62
|
+
FileUtils::rm_rf("po")
|
63
|
+
FileUtils::rm_rf(fname)
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'amrita2'
|
3
|
+
require 'amrita2/testsupport'
|
4
|
+
require 'amrita2/template'
|
5
|
+
require 'amrita2/gettext'
|
6
|
+
require 'gettext/utils'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
include Amrita2
|
10
|
+
include Amrita2::Filters
|
11
|
+
include Amrita2::GetTextBridge
|
12
|
+
|
13
|
+
require File::dirname(__FILE__) + '/gettext_util'
|
14
|
+
|
15
|
+
$KCODE='u'
|
16
|
+
|
17
|
+
context "gettext static element" do
|
18
|
+
include Amrita2GetTextTestSupport
|
19
|
+
TEMPFILE='/tmp/test.a2html'
|
20
|
+
|
21
|
+
specify "every text becomes an entry of po" do
|
22
|
+
Locale.set_current("ja", "JP", "utf8")
|
23
|
+
test_gettext("test1",
|
24
|
+
TEMPFILE,
|
25
|
+
"<span>test message</span>",
|
26
|
+
[
|
27
|
+
%r[#: /tmp/test.a2html:-],
|
28
|
+
%r[msgid "test message"],
|
29
|
+
],
|
30
|
+
{},
|
31
|
+
"テストメッセージ"
|
32
|
+
) do |l|
|
33
|
+
l.sub!(%r[msgid "test message"\nmsgstr ""]m,
|
34
|
+
%[msgid "test message"\nmsgstr "テストメッセージ"])
|
35
|
+
l
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
specify "strip messages" do
|
40
|
+
Locale.set_current("ja", "JP", "utf8")
|
41
|
+
test_gettext("test1",
|
42
|
+
TEMPFILE,
|
43
|
+
"<span> test message </span>",
|
44
|
+
[
|
45
|
+
%r[#: /tmp/test.a2html:-],
|
46
|
+
%r[msgid "test message"],
|
47
|
+
],
|
48
|
+
{},
|
49
|
+
"テストメッセージ"
|
50
|
+
) do |l|
|
51
|
+
l.sub!(%r[msgid "test message"\nmsgstr ""]m,
|
52
|
+
%[msgid "test message"\nmsgstr "テストメッセージ"])
|
53
|
+
l
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
specify "two messages" do
|
58
|
+
test_gettext("test3",
|
59
|
+
TEMPFILE,
|
60
|
+
"<div><span> test message1 </span><span>test message2</span></div>",
|
61
|
+
[
|
62
|
+
%r[#: /tmp/test.a2html:-],
|
63
|
+
%r[msgid "test message1"],
|
64
|
+
%r[msgid "test message2"],
|
65
|
+
],
|
66
|
+
{},
|
67
|
+
"<div>あああいいい</div>"
|
68
|
+
) do |l|
|
69
|
+
l.sub!(%r[msgid "test message1"\nmsgstr ""]m,
|
70
|
+
%[msgid "test message1"\nmsgstr "あああ"])
|
71
|
+
l.sub!(%r[msgid "test message2"\nmsgstr ""]m,
|
72
|
+
%[msgid "test message2"\nmsgstr "いいい"])
|
73
|
+
l
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
context "format with gettext" do
|
80
|
+
include Amrita2GetTextTestSupport
|
81
|
+
|
82
|
+
specify "format1" do
|
83
|
+
Locale.set_current("ja", "JP", "utf8")
|
84
|
+
test_gettext(
|
85
|
+
"format1",
|
86
|
+
TEMPFILE,
|
87
|
+
"<span>%{filename} is %{filesize} byte</span>",
|
88
|
+
[
|
89
|
+
%r[#: #{TEMPFILE}:-],
|
90
|
+
%r[msgid "%\{filename\} is %\{filesize\} byte"],
|
91
|
+
],
|
92
|
+
{
|
93
|
+
:filename => "foo.rb",
|
94
|
+
:filesize => 100
|
95
|
+
},
|
96
|
+
"foo.rbの大きさは100バイトです"
|
97
|
+
) do |l|
|
98
|
+
l.sub!(%r[msgid "%\{filename\} is %\{filesize\} byte"\nmsgstr ""]m,
|
99
|
+
%[msgid "%\{filename\} is %\{filesize\} byte"\nmsgstr "%{filename}の大きさは%{filesize}バイトです"])
|
100
|
+
l
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
|
2
|
+
require 'amrita2'
|
3
|
+
|
4
|
+
context "" do
|
5
|
+
include Amrita2::Runtime
|
6
|
+
setup do
|
7
|
+
@g = Amrita2::Core::CodeGenerator.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def cg_result
|
11
|
+
__binding__ = binding
|
12
|
+
eval @g.result
|
13
|
+
end
|
14
|
+
|
15
|
+
def cg_result_for_class(value)
|
16
|
+
cls = Class.new
|
17
|
+
cls.module_eval @g.result
|
18
|
+
cls.new.render_with(value)
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "code" do
|
22
|
+
@g.code "1"
|
23
|
+
cg_result.should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
specify "put_constant" do
|
27
|
+
@g.with_stream do
|
28
|
+
@g.put_constant 1
|
29
|
+
end
|
30
|
+
cg_result.should == "1"
|
31
|
+
end
|
32
|
+
|
33
|
+
specify "if true" do
|
34
|
+
@g.with_stream do
|
35
|
+
@g.if_("true") do
|
36
|
+
@g.put_constant 2
|
37
|
+
end
|
38
|
+
end
|
39
|
+
cg_result.should == "2"
|
40
|
+
end
|
41
|
+
|
42
|
+
specify "if false " do
|
43
|
+
@g.with_stream do
|
44
|
+
@g.if_("false") do
|
45
|
+
@g.put_constant 2
|
46
|
+
end
|
47
|
+
end
|
48
|
+
cg_result.should == ""
|
49
|
+
end
|
50
|
+
|
51
|
+
specify "case " do
|
52
|
+
@g.with_stream do
|
53
|
+
@g.case_("1") do
|
54
|
+
@g.when_("String") do
|
55
|
+
@g.put_constant 1
|
56
|
+
end
|
57
|
+
@g.when_("Integer") do
|
58
|
+
@g.put_constant 2
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
cg_result.should == "2"
|
63
|
+
end
|
64
|
+
|
65
|
+
specify "def method" do
|
66
|
+
@g.def_method("render_with", "value") do
|
67
|
+
@g.put_constant("<")
|
68
|
+
@g.code("value +=1")
|
69
|
+
@g.put_expression("(value * 2).to_s")
|
70
|
+
@g.put_constant(">")
|
71
|
+
end
|
72
|
+
cg_result_for_class(3).should == "<8>"
|
73
|
+
end
|
74
|
+
|
75
|
+
specify "multi stream" do
|
76
|
+
@g.with_stream do
|
77
|
+
@g.put_constant("abc")
|
78
|
+
@g.with_stream(:aaa) do
|
79
|
+
@g.put_constant("123")
|
80
|
+
@g.put_constant("456")
|
81
|
+
end
|
82
|
+
@g.put_constant("def")
|
83
|
+
@g.put_stream(:aaa)
|
84
|
+
end
|
85
|
+
cg_result.should == "abcdef123456"
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
|
2
|
+
require 'rexml/element'
|
3
|
+
require 'amrita2'
|
4
|
+
|
5
|
+
include Amrita2
|
6
|
+
|
7
|
+
context "check hpricot" do
|
8
|
+
specify "no child" do
|
9
|
+
text = %q[<span am:src='aaa' />]
|
10
|
+
e = Hpricot.make(text)[0]
|
11
|
+
e.enum_for(:each_child).to_a.size.should == 0
|
12
|
+
end
|
13
|
+
|
14
|
+
specify "one child" do
|
15
|
+
text = %q[<span am:src='aaa'><span am:src='bbb' /></span>]
|
16
|
+
e = Hpricot.make(text)[0]
|
17
|
+
e.enum_for(:each_child).to_a.size.should == 1
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "two children" do
|
21
|
+
text = %q[<span am:src='aaa'><span am:src='bbb' /><span am:src='ccc' /></span>]
|
22
|
+
e = Hpricot.make(text, :xml=>true)[0]
|
23
|
+
e.children.size == 2
|
24
|
+
e.enum_for(:each_child).to_a.size.should == 2
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "has_dynamic?" do
|
29
|
+
specify "single" do
|
30
|
+
text = %q[<span am:src='aaa' />]
|
31
|
+
t = Amrita2::Template.new(text)
|
32
|
+
t.setup
|
33
|
+
t.root.has_dynamic?.should == true
|
34
|
+
t.root.children.first.has_dynamic?.should == false
|
35
|
+
end
|
36
|
+
|
37
|
+
specify "nest" do
|
38
|
+
text = %q[<span am:src='aaa'><span am:src='bbb' /></span>]
|
39
|
+
t = Template.new(text)
|
40
|
+
t.setup
|
41
|
+
t.root.has_dynamic?.should == true
|
42
|
+
t.root.children.first.has_dynamic?.should == true
|
43
|
+
t.root.children.first.children.first.has_dynamic?.should == false
|
44
|
+
end
|
45
|
+
|
46
|
+
specify "nest2" do
|
47
|
+
text = %q[<span am:src='aaa'><span am:src='bbb' /><span am:src='ccc' /></span>]
|
48
|
+
t = Template.new(text)
|
49
|
+
t.setup
|
50
|
+
t.root.has_dynamic?.should == true
|
51
|
+
aaa = t.root.children.first
|
52
|
+
aaa.element.children.size.should == 2
|
53
|
+
aaa.children.size.should == 2
|
54
|
+
bbb, ccc = *aaa.children
|
55
|
+
bbb.should be_dynamic
|
56
|
+
ccc.should be_dynamic
|
57
|
+
end
|
58
|
+
|
59
|
+
specify "has text" do
|
60
|
+
text = %q[<span am:src='aaa'>text</span>]
|
61
|
+
t = Template.new(text)
|
62
|
+
t.setup
|
63
|
+
t.root.has_dynamic?.should == true
|
64
|
+
t.root.children.first.has_dynamic?.should == false
|
65
|
+
end
|
66
|
+
|
67
|
+
specify "has erb" do
|
68
|
+
text = %q[<span am:src='aaa'><% 1 %></span>]
|
69
|
+
t = Template.new(text)
|
70
|
+
t.setup
|
71
|
+
t.root.has_dynamic?.should == true
|
72
|
+
t.root.children.first.has_dynamic?.should == true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "has_ruby?" do
|
77
|
+
specify "single" do
|
78
|
+
text = %q[<span am:src='aaa' />]
|
79
|
+
t = Amrita2::Template.new(text)
|
80
|
+
t.setup
|
81
|
+
t.root.has_ruby?.should == nil
|
82
|
+
t.root.children.first.has_ruby?.should == nil
|
83
|
+
end
|
84
|
+
|
85
|
+
specify "has erb" do
|
86
|
+
text = %q[<span am:src='aaa'><% 1 %></span>]
|
87
|
+
t = Template.new(text)
|
88
|
+
t.setup
|
89
|
+
t.root.has_ruby?.should == true
|
90
|
+
t.root.children.first.has_ruby?.should == true
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'amrita2'
|
2
|
+
|
3
|
+
context "Hash Delegator" do
|
4
|
+
include Amrita2
|
5
|
+
|
6
|
+
specify "delegate to Hash" do
|
7
|
+
h = { :one => 1 }
|
8
|
+
c = Amrita2::HashDelegator.new(h) do
|
9
|
+
{
|
10
|
+
:two=>2,
|
11
|
+
}
|
12
|
+
end
|
13
|
+
c.one.should == 1
|
14
|
+
c.two.should == 2
|
15
|
+
c[:one].should == 1
|
16
|
+
c[:two].should == 2
|
17
|
+
c.three.should be_nil
|
18
|
+
c[:three].should be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "delegate to Struct" do
|
22
|
+
s = Struct.new(:one).new(1)
|
23
|
+
c = Amrita2::HashDelegator.new(s) do
|
24
|
+
{
|
25
|
+
:two=>2,
|
26
|
+
}
|
27
|
+
end
|
28
|
+
c.one.should == 1
|
29
|
+
c.two.should == 2
|
30
|
+
c[:one].should == 1
|
31
|
+
c[:two].should == 2
|
32
|
+
proc { c.three }.should raise_error
|
33
|
+
c[:three].should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
specify "double delegate to Struct" do
|
37
|
+
s = Struct.new(:one).new(1)
|
38
|
+
c1 = Amrita2::HashDelegator.new(s) do
|
39
|
+
{
|
40
|
+
:two=>2,
|
41
|
+
}
|
42
|
+
end
|
43
|
+
c2 = Amrita2::HashDelegator.new(c1) do
|
44
|
+
{
|
45
|
+
:three=>3,
|
46
|
+
}
|
47
|
+
end
|
48
|
+
c2.one.should == 1
|
49
|
+
c2.two.should == 2
|
50
|
+
c2[:one].should == 1
|
51
|
+
c2[:two].should == 2
|
52
|
+
c2.three.should == 3
|
53
|
+
c2[:three].should == 3
|
54
|
+
proc { c2.four }.should raise_error
|
55
|
+
c2[:four].should be_nil
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'amrita2'
|
4
|
+
require 'amrita2/testsupport'
|
5
|
+
|
6
|
+
include Amrita2
|
7
|
+
include Amrita2::Util
|
8
|
+
|
9
|
+
context "parse_opt" do
|
10
|
+
include OptionSupport
|
11
|
+
setup do
|
12
|
+
doc = REXML::Document.new "<div class='aaa'><a href='bbb' title='ccc'>ddd</a></div>"
|
13
|
+
@e = doc.root
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "give simbols" do
|
17
|
+
parse_opt().should == {}
|
18
|
+
parse_opt(:aaa).should == {:aaa=>:aaa}
|
19
|
+
parse_opt(:aaa, :bbb).should == {:aaa=>:aaa, :bbb=>:bbb}
|
20
|
+
end
|
21
|
+
|
22
|
+
specify "give hash" do
|
23
|
+
parse_opt(:aaa=>:aaa).should == {:aaa=>:aaa}
|
24
|
+
parse_opt(:aaa=>"aaa").should == {:aaa=>"aaa"}
|
25
|
+
parse_opt(:aaa=>"aaa", :bbb=>:bbb).should == {:aaa=>"aaa", :bbb=>:bbb}
|
26
|
+
end
|
27
|
+
|
28
|
+
specify "give hash and simbol" do
|
29
|
+
parse_opt(:aaa, :bbb=>:bbb).should == {:aaa=>:aaa, :bbb=>:bbb}
|
30
|
+
parse_opt(:aaa, :bbb=>"bbb").should == {:aaa=>:aaa, :bbb=>"bbb" }
|
31
|
+
parse_opt(:xxx, :aaa=>"aaa", :bbb=>:bbb).should == {:aaa=>"aaa", :bbb=>:bbb, :xxx=>:xxx}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|