wee 0.1.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/INSTALL +7 -0
- data/README +268 -0
- data/Rakefile +26 -0
- data/TODO +116 -0
- data/benchmark/Centrino1300/result.2000.counter.action +45 -0
- data/benchmark/Centrino1300/result.2000.counter.render +43 -0
- data/benchmark/Centrino1300/result.2000.filehandler +43 -0
- data/benchmark/Centrino600/result.2000.counter.action +47 -0
- data/benchmark/Centrino600/result.2000.counter.render +45 -0
- data/benchmark/Centrino600/result.2000.filehandler +43 -0
- data/benchmark/Makefile +48 -0
- data/benchmark/bench.sh +24 -0
- data/benchmark/counter.rb +96 -0
- data/benchmark/filehandler.rb +6 -0
- data/doc/rdoc/classes/Array.html +172 -0
- data/doc/rdoc/classes/Cache.html +126 -0
- data/doc/rdoc/classes/Cache/StorageCache.html +320 -0
- data/doc/rdoc/classes/Cache/Strategy.html +128 -0
- data/doc/rdoc/classes/Cache/Strategy/CapacityBounded.html +269 -0
- data/doc/rdoc/classes/Cache/Strategy/LFU.html +238 -0
- data/doc/rdoc/classes/Cache/Strategy/LFU/Item.html +111 -0
- data/doc/rdoc/classes/Cache/Strategy/LRU.html +238 -0
- data/doc/rdoc/classes/Cache/Strategy/LRU/Item.html +111 -0
- data/doc/rdoc/classes/Cache/Strategy/Unbounded.html +225 -0
- data/doc/rdoc/classes/Cache/Strategy/Unbounded/Item.html +111 -0
- data/doc/rdoc/classes/Enumerable.html +146 -0
- data/doc/rdoc/classes/LiteralMethod.html +196 -0
- data/doc/rdoc/classes/Object.html +178 -0
- data/doc/rdoc/classes/String.html +172 -0
- data/doc/rdoc/classes/Struct.html +174 -0
- data/doc/rdoc/classes/Wee.html +160 -0
- data/doc/rdoc/classes/Wee/AnswerDecoration.html +182 -0
- data/doc/rdoc/classes/Wee/Application.html +337 -0
- data/doc/rdoc/classes/Wee/Brush.html +245 -0
- data/doc/rdoc/classes/Wee/Brush/ActionCallbackMixin.html +149 -0
- data/doc/rdoc/classes/Wee/Brush/ActionMixin.html +146 -0
- data/doc/rdoc/classes/Wee/Brush/ActionURLCallbackMixin.html +157 -0
- data/doc/rdoc/classes/Wee/Brush/AnchorTag.html +210 -0
- data/doc/rdoc/classes/Wee/Brush/AssignMixin.html +141 -0
- data/doc/rdoc/classes/Wee/Brush/CallbackMixin.html +141 -0
- data/doc/rdoc/classes/Wee/Brush/FormTag.html +225 -0
- data/doc/rdoc/classes/Wee/Brush/GenericEncodedTextBrush.html +176 -0
- data/doc/rdoc/classes/Wee/Brush/GenericTagBrush.html +283 -0
- data/doc/rdoc/classes/Wee/Brush/GenericTextBrush.html +176 -0
- data/doc/rdoc/classes/Wee/Brush/ImageButtonTag.html +195 -0
- data/doc/rdoc/classes/Wee/Brush/InputCallbackMixin.html +149 -0
- data/doc/rdoc/classes/Wee/Brush/InputTag.html +172 -0
- data/doc/rdoc/classes/Wee/Brush/Page.html +193 -0
- data/doc/rdoc/classes/Wee/Brush/SelectListTag.html +267 -0
- data/doc/rdoc/classes/Wee/Brush/SelectOptionTag.html +177 -0
- data/doc/rdoc/classes/Wee/Brush/SubmitButtonTag.html +154 -0
- data/doc/rdoc/classes/Wee/Brush/TableDataTag.html +173 -0
- data/doc/rdoc/classes/Wee/Brush/TableHeaderTag.html +146 -0
- data/doc/rdoc/classes/Wee/Brush/TableRowTag.html +277 -0
- data/doc/rdoc/classes/Wee/Brush/TableTag.html +146 -0
- data/doc/rdoc/classes/Wee/Brush/TextAreaTag.html +229 -0
- data/doc/rdoc/classes/Wee/Brush/TextInputTag.html +154 -0
- data/doc/rdoc/classes/Wee/Callback.html +231 -0
- data/doc/rdoc/classes/Wee/CallbackRegistry.html +308 -0
- data/doc/rdoc/classes/Wee/CallbackStream.html +227 -0
- data/doc/rdoc/classes/Wee/Canvas.html +235 -0
- data/doc/rdoc/classes/Wee/Component.html +933 -0
- data/doc/rdoc/classes/Wee/Context.html +111 -0
- data/doc/rdoc/classes/Wee/Decoration.html +338 -0
- data/doc/rdoc/classes/Wee/Delegate.html +247 -0
- data/doc/rdoc/classes/Wee/ErrorPage.html +175 -0
- data/doc/rdoc/classes/Wee/ErrorResponse.html +180 -0
- data/doc/rdoc/classes/Wee/GenericResponse.html +162 -0
- data/doc/rdoc/classes/Wee/HtmlCanvas.html +751 -0
- data/doc/rdoc/classes/Wee/HtmlWriter.html +351 -0
- data/doc/rdoc/classes/Wee/LiteralMethodCallback.html +180 -0
- data/doc/rdoc/classes/Wee/MethodCallback.html +193 -0
- data/doc/rdoc/classes/Wee/Page.html +111 -0
- data/doc/rdoc/classes/Wee/Presenter.html +521 -0
- data/doc/rdoc/classes/Wee/RedirectResponse.html +150 -0
- data/doc/rdoc/classes/Wee/RefreshResponse.html +157 -0
- data/doc/rdoc/classes/Wee/RenderingContext.html +111 -0
- data/doc/rdoc/classes/Wee/Request.html +268 -0
- data/doc/rdoc/classes/Wee/RequestHandler.html +336 -0
- data/doc/rdoc/classes/Wee/Response.html +260 -0
- data/doc/rdoc/classes/Wee/Session.html +469 -0
- data/doc/rdoc/classes/Wee/SimpleIdGenerator.html +198 -0
- data/doc/rdoc/classes/Wee/Snapshot.html +211 -0
- data/doc/rdoc/classes/Wee/StateHolder.html +149 -0
- data/doc/rdoc/classes/Wee/StateRegistry.html +434 -0
- data/doc/rdoc/classes/Wee/StateRegistry/Snapshot.html +320 -0
- data/doc/rdoc/classes/Wee/StateRegistry/WithObject.html +153 -0
- data/doc/rdoc/classes/Wee/Utils.html +111 -0
- data/doc/rdoc/classes/Wee/Utils/LRUCache.html +148 -0
- data/doc/rdoc/classes/Wee/ValueHolder.html +220 -0
- data/doc/rdoc/classes/Wee/WEBrickAdaptor.html +330 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/INSTALL.html +118 -0
- data/doc/rdoc/files/README.html +466 -0
- data/doc/rdoc/files/lib/cache/cache_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/adaptors/webrick_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/application_rb.html +112 -0
- data/doc/rdoc/files/lib/wee/callback_rb.html +107 -0
- data/doc/rdoc/files/lib/wee/component_ext_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/component_rb.html +109 -0
- data/doc/rdoc/files/lib/wee/context_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/core/callback_rb.html +115 -0
- data/doc/rdoc/files/lib/wee/core/component_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/core/decoration_rb.html +133 -0
- data/doc/rdoc/files/lib/wee/core/presenter_rb.html +112 -0
- data/doc/rdoc/files/lib/wee/core/snapshot_rb.html +113 -0
- data/doc/rdoc/files/lib/wee/core/valueholder_rb.html +110 -0
- data/doc/rdoc/files/lib/wee/core_rb.html +131 -0
- data/doc/rdoc/files/lib/wee/decoration_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/holder_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/html_canvas_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/html_writer_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/idgen_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/page_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/presenter_rb.html +112 -0
- data/doc/rdoc/files/lib/wee/renderer/html/brushes_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/renderer/html/canvas_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/renderer/html/writer_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/rendering/html/brushes_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/rendering/html/canvas_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/rendering/html/writer_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/request_rb.html +113 -0
- data/doc/rdoc/files/lib/wee/requesthandler_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/response_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/session_rb.html +109 -0
- data/doc/rdoc/files/lib/wee/snapshot_ext_rb.html +101 -0
- data/doc/rdoc/files/lib/wee/snapshot_rb.html +107 -0
- data/doc/rdoc/files/lib/wee/state_registry_rb.html +110 -0
- data/doc/rdoc/files/lib/wee/stuff_rb.html +144 -0
- data/doc/rdoc/files/lib/wee/utils/cache_rb.html +108 -0
- data/doc/rdoc/files/lib/wee/webrick_rb.html +108 -0
- data/doc/rdoc/files/lib/wee_rb.html +132 -0
- data/doc/rdoc/fr_class_index.html +93 -0
- data/doc/rdoc/fr_file_index.html +51 -0
- data/doc/rdoc/fr_method_index.html +242 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/examples/ObjectSpaceBrowser.rb +199 -0
- data/examples/calendar.rb +366 -0
- data/examples/cc.rb +94 -0
- data/examples/draw.rb +91 -0
- data/examples/example.rb +223 -0
- data/examples/test.rb +66 -0
- data/examples/window.rb +53 -0
- data/lib/cache/cache.rb +9 -0
- data/lib/wee.rb +18 -8
- data/lib/wee/adaptors/webrick.rb +73 -0
- data/lib/wee/application.rb +69 -71
- data/lib/wee/context.rb +2 -12
- data/lib/wee/core.rb +15 -0
- data/lib/wee/core/callback.rb +108 -0
- data/lib/wee/core/component.rb +314 -0
- data/lib/wee/core/decoration.rb +129 -0
- data/lib/wee/core/presenter.rb +132 -0
- data/lib/wee/core/snapshot.rb +21 -0
- data/lib/wee/core/valueholder.rb +19 -0
- data/lib/wee/idgen.rb +13 -0
- data/lib/wee/page.rb +1 -1
- data/lib/wee/renderer/html/brushes.rb +435 -0
- data/lib/wee/renderer/html/canvas.rb +148 -0
- data/lib/wee/{html_writer.rb → renderer/html/writer.rb} +31 -16
- data/lib/wee/request.rb +57 -0
- data/lib/wee/requesthandler.rb +77 -0
- data/lib/wee/response.rb +77 -0
- data/lib/wee/session.rb +70 -64
- data/lib/wee/{snapshot.rb → snapshot_ext.rb} +4 -4
- data/test/components/calltest.rb +16 -0
- data/test/components/counter.rb +17 -0
- data/test/components/messagebox.rb +15 -0
- data/test/components/page.rb +14 -0
- data/test/components/page_decoration.rb +7 -0
- data/test/stress.rb +64 -0
- data/test/test_component.rb +106 -0
- data/test/test_html_canvas.rb +25 -0
- data/test/test_html_writer.rb +27 -0
- data/test/test_request.rb +13 -0
- data/test/utils/cross.rb +65 -0
- data/test/utils/generic_plotter.rb +28 -0
- data/test/utils/gnuplot.rb +31 -0
- data/test/utils/measure_memory.rb +9 -0
- data/test/utils/memory_plotter.rb +10 -0
- data/test/utils/object_plotter.rb +10 -0
- data/test/utils/webrick_background.rb +31 -0
- data/wee.gemspec +22 -0
- metadata +222 -18
- data/lib/wee/component.rb +0 -126
- data/lib/wee/delegate_decoration.rb +0 -22
- data/lib/wee/handler_registry.rb +0 -89
- data/lib/wee/holder.rb +0 -14
- data/lib/wee/html_canvas.rb +0 -379
- data/lib/wee/state_registry.rb +0 -173
- data/lib/wee/stuff.rb +0 -29
- data/lib/wee/webrick.rb +0 -15
@@ -7,7 +7,7 @@ class Object
|
|
7
7
|
snap
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def restore_snapshot(snap)
|
11
11
|
instance_variables.each do |iv|
|
12
12
|
instance_variable_set(iv, snap[iv])
|
13
13
|
end
|
@@ -19,7 +19,7 @@ class Array
|
|
19
19
|
dup
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def restore_snapshot(snap)
|
23
23
|
replace(snap)
|
24
24
|
end
|
25
25
|
end
|
@@ -29,7 +29,7 @@ class String
|
|
29
29
|
dup
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def restore_snapshot(snap)
|
33
33
|
replace(snap)
|
34
34
|
end
|
35
35
|
end
|
@@ -41,7 +41,7 @@ class Struct
|
|
41
41
|
snap
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def restore_snapshot(snap)
|
45
45
|
snap.each_pair {|k,v| send(k.to_s + "=", v)}
|
46
46
|
end
|
47
47
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Counter < Wee::Component
|
2
|
+
def initialize(cnt=0)
|
3
|
+
super()
|
4
|
+
@cnt = ValueHolder.new(cnt)
|
5
|
+
end
|
6
|
+
|
7
|
+
def backtrack_state(snap)
|
8
|
+
super
|
9
|
+
snap.add(@cnt)
|
10
|
+
end
|
11
|
+
|
12
|
+
def render
|
13
|
+
r.h1(@cnt.value.to_s)
|
14
|
+
r.anchor.callback { @cnt.value -= 1 }.with("--")
|
15
|
+
r.anchor.callback { @cnt.value += 1 }.with("++")
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class MessageBox < Wee::Component
|
2
|
+
def initialize(text)
|
3
|
+
super()
|
4
|
+
@text = text
|
5
|
+
end
|
6
|
+
|
7
|
+
def render
|
8
|
+
r.bold(@text)
|
9
|
+
r.form do
|
10
|
+
r.submit_button.value('OK').callback { answer true }
|
11
|
+
r.space
|
12
|
+
r.submit_button.value('Cancel').callback { answer false }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/test/stress.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
$LOAD_PATH.unshift '../lib'
|
2
|
+
require 'wee'
|
3
|
+
require 'wee/utils/cache'
|
4
|
+
require 'wee/adaptors/webrick'
|
5
|
+
require 'utils/webrick_background'
|
6
|
+
require 'utils/memory_plotter'
|
7
|
+
require 'utils/object_plotter'
|
8
|
+
require 'utils/cross'
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
require 'web/unit' # require narf-lib
|
12
|
+
|
13
|
+
require 'components/messagebox'
|
14
|
+
require 'components/calltest'
|
15
|
+
require 'components/page'
|
16
|
+
|
17
|
+
NUM_SESSIONS = 5
|
18
|
+
|
19
|
+
class DummyLog < WEBrick::BasicLog
|
20
|
+
def initialize() super(self) end
|
21
|
+
def <<(*args) end
|
22
|
+
end
|
23
|
+
|
24
|
+
class MySession < Wee::Session
|
25
|
+
def initialize
|
26
|
+
super do
|
27
|
+
self.root_component = Page.new(CallTest.new)
|
28
|
+
self.page_store = Wee::Utils::LRUCache.new(10) # backtrack up to 10 pages
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
app = Wee::Application.new {|app|
|
34
|
+
app.default_request_handler { MySession.new }
|
35
|
+
app.id_generator = Wee::SimpleIdGenerator.new(rand(1_000_000))
|
36
|
+
}
|
37
|
+
|
38
|
+
Wee::WEBrickAdaptor.register('/app' => app).start(:Logger => DummyLog.new, :AccessLog => [])
|
39
|
+
|
40
|
+
MemoryPlotter.new(5, $$).run
|
41
|
+
ObjectPlotter.new(5, Object, Array, String, Bignum).run
|
42
|
+
ObjectPlotter.new(5, Thread, Continuation, Proc).run
|
43
|
+
|
44
|
+
$URLBASE = 'http://localhost:2000'
|
45
|
+
|
46
|
+
class StressSession
|
47
|
+
def initialize
|
48
|
+
@r = Web::Unit::Response.get('/app').redirect.redirect
|
49
|
+
end
|
50
|
+
|
51
|
+
def step
|
52
|
+
%w(OK Cancel).each {|b|
|
53
|
+
@r = @r.click('show').redirect.submit('OK').redirect.submit(b).redirect
|
54
|
+
}
|
55
|
+
(%w(OK Cancel) ** %w(OK Cancel)).each { |b1, b2|
|
56
|
+
@r = @r.click('show').redirect.submit('Cancel').redirect.submit(b1).redirect.submit(b2).redirect
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
sessions = (1..NUM_SESSIONS).map { StressSession.new }
|
62
|
+
loop do
|
63
|
+
sessions.each {|s| s.step }
|
64
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
module Wee; end
|
3
|
+
require 'wee/core'
|
4
|
+
|
5
|
+
class Test_Component < Test::Unit::TestCase
|
6
|
+
def test_add_remove_one_decoration
|
7
|
+
c = Wee::Component.new
|
8
|
+
d = Wee::Decoration.new
|
9
|
+
|
10
|
+
assert_same c, c.decoration
|
11
|
+
assert_nil d.owner
|
12
|
+
|
13
|
+
c.add_decoration(d)
|
14
|
+
|
15
|
+
assert_same d, c.decoration
|
16
|
+
assert_same c, d.owner
|
17
|
+
assert_same d, d.owner.decoration
|
18
|
+
|
19
|
+
assert_same d, c.remove_decoration(d)
|
20
|
+
|
21
|
+
assert_same c, c.decoration
|
22
|
+
assert_nil d.owner
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_add_remove_multiple_decorations
|
26
|
+
c = Wee::Component.new
|
27
|
+
d1 = Wee::Decoration.new
|
28
|
+
d2 = Wee::Decoration.new
|
29
|
+
d3 = Wee::Decoration.new
|
30
|
+
|
31
|
+
c.add_decoration(d1)
|
32
|
+
c.add_decoration(d2)
|
33
|
+
c.add_decoration(d3)
|
34
|
+
|
35
|
+
assert_same d3, c.decoration
|
36
|
+
assert_same d2, d3.owner
|
37
|
+
assert_same d1, d2.owner
|
38
|
+
assert_same c, d1.owner
|
39
|
+
|
40
|
+
assert_same d2, c.remove_decoration(d2)
|
41
|
+
|
42
|
+
assert_same d3, c.decoration
|
43
|
+
assert_same d1, d3.owner
|
44
|
+
assert_nil d2.owner
|
45
|
+
assert_same c, d1.owner
|
46
|
+
|
47
|
+
assert_same d1, c.remove_decoration(d1)
|
48
|
+
assert_same d3, c.decoration
|
49
|
+
assert_same c, d3.owner
|
50
|
+
assert_nil d1.owner
|
51
|
+
|
52
|
+
# try to remove an already removed decoration
|
53
|
+
assert_nil c.remove_decoration(d2)
|
54
|
+
assert_nil c.remove_decoration(d1)
|
55
|
+
|
56
|
+
assert_same d3, c.remove_decoration(d3)
|
57
|
+
assert_same c, c.decoration
|
58
|
+
assert_nil d3.owner
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_each_decoration
|
62
|
+
require 'enumerator'
|
63
|
+
c = Wee::Component.new
|
64
|
+
d1 = Wee::Decoration.new
|
65
|
+
d2 = Wee::Decoration.new
|
66
|
+
d3 = Wee::Decoration.new
|
67
|
+
|
68
|
+
c.add_decoration(d1)
|
69
|
+
c.add_decoration(d2)
|
70
|
+
c.add_decoration(d3)
|
71
|
+
|
72
|
+
assert_equal [d3, d2, d1], c.to_enum(:each_decoration).to_a
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_remove_decoration_if
|
76
|
+
c = Wee::Component.new
|
77
|
+
d1 = Wee::Decoration.new
|
78
|
+
d2 = Wee::Decoration.new
|
79
|
+
d3 = Wee::Decoration.new
|
80
|
+
d4 = Wee::Decoration.new
|
81
|
+
|
82
|
+
c.add_decoration(d1)
|
83
|
+
c.add_decoration(d2)
|
84
|
+
c.add_decoration(d3)
|
85
|
+
c.add_decoration(d4)
|
86
|
+
|
87
|
+
def d1.a() end
|
88
|
+
def d3.a() end
|
89
|
+
c.remove_decoration_if {|d| d.respond_to?(:a)}
|
90
|
+
assert_equal [d4, d2], c.to_enum(:each_decoration).to_a
|
91
|
+
|
92
|
+
def d4.a() end
|
93
|
+
c.remove_decoration_if {|d| d.respond_to?(:a)}
|
94
|
+
assert_equal [d2], c.to_enum(:each_decoration).to_a
|
95
|
+
|
96
|
+
c.remove_decoration_if {|d| d.respond_to?(:a)}
|
97
|
+
assert_equal [d2], c.to_enum(:each_decoration).to_a
|
98
|
+
|
99
|
+
def d2.a() end
|
100
|
+
c.remove_decoration_if {|d| d.respond_to?(:a)}
|
101
|
+
assert_equal [], c.to_enum(:each_decoration).to_a
|
102
|
+
|
103
|
+
assert_equal c, c.decoration
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
module Wee; end
|
3
|
+
require 'wee/renderer/html/writer'
|
4
|
+
require 'wee/renderer/html/brushes'
|
5
|
+
require 'wee/renderer/html/canvas'
|
6
|
+
require 'wee/context'
|
7
|
+
|
8
|
+
class Test_HtmlCanvas < Test::Unit::TestCase
|
9
|
+
def test_simple
|
10
|
+
rctx = Wee::RenderingContext.new
|
11
|
+
rctx.document = Wee::HtmlWriter.new(doc='')
|
12
|
+
|
13
|
+
c = Wee::HtmlCanvas.new(rctx)
|
14
|
+
c.form.action("foo").with {
|
15
|
+
c.table {
|
16
|
+
c.table_row.id("myrow").with {
|
17
|
+
c.table_data.align_top.with("Hello world")
|
18
|
+
}
|
19
|
+
}
|
20
|
+
c.space
|
21
|
+
}
|
22
|
+
|
23
|
+
assert_equal %[<form action="foo" method="POST"><table><tr id="myrow"><td align="top">Hello world</td></tr></table> </form>], doc
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
module Wee; end
|
3
|
+
require 'wee/renderer/html/writer'
|
4
|
+
|
5
|
+
class Test_HtmlWriter < Test::Unit::TestCase
|
6
|
+
def test_document
|
7
|
+
w = Wee::HtmlWriter.new(doc='')
|
8
|
+
w.start_tag('html')
|
9
|
+
w.start_tag('body')
|
10
|
+
w.start_tag('a', 'href' => 'http://...')
|
11
|
+
w.text('link')
|
12
|
+
w.end_tag('a')
|
13
|
+
w.end_tag('body')
|
14
|
+
w.end_tag('html')
|
15
|
+
|
16
|
+
assert_equal true, w.valid?
|
17
|
+
assert_equal '<html><body><a href="http://...">link</a></body></html>', doc
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_merge_start_end_tag
|
21
|
+
w = Wee::HtmlWriter.new(doc='')
|
22
|
+
w.start_tag('a', 'href' => '')
|
23
|
+
w.end_tag('a')
|
24
|
+
assert_equal true, w.valid?
|
25
|
+
assert_equal '<a href=""/>', doc
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
module Wee; end
|
3
|
+
require 'wee/request'
|
4
|
+
|
5
|
+
class Test_Request < Test::Unit::TestCase
|
6
|
+
def test_parse
|
7
|
+
req = Wee::Request.new('/app', '/app/...@req_handler_id/page_id', nil, nil)
|
8
|
+
assert_equal 'req_handler_id', req.request_handler_id
|
9
|
+
assert_equal 'page_id', req.page_id
|
10
|
+
assert_equal '/app/@a/b?c', req.build_url('a', 'b', 'c')
|
11
|
+
assert_equal '/app/@req_handler_id/b', req.build_url('req_handler_id', 'b')
|
12
|
+
end
|
13
|
+
end
|
data/test/utils/cross.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# Cross product for Enumerable's
|
3
|
+
#
|
4
|
+
|
5
|
+
# TODO: use ** for [1,2,3].cross([4,5,6])
|
6
|
+
|
7
|
+
require 'generator'
|
8
|
+
|
9
|
+
module Enumerable
|
10
|
+
def **(otherEnumerable)
|
11
|
+
res = Array.new
|
12
|
+
self.each do |i|
|
13
|
+
otherEnumerable.each do |j|
|
14
|
+
res << [i,j]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
return res
|
18
|
+
end
|
19
|
+
|
20
|
+
def cross(*enums, &block)
|
21
|
+
Enumerable.cross(self, *enums, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.cross(*enums, &block)
|
25
|
+
raise if enums.empty?
|
26
|
+
gens = enums.map{|e| Generator.new(e)}
|
27
|
+
return [] if gens.any? {|g| g.end?}
|
28
|
+
sz = gens.size
|
29
|
+
res = []
|
30
|
+
tuple = Array.new(sz)
|
31
|
+
|
32
|
+
loop do
|
33
|
+
# fill tuple
|
34
|
+
(0 ... sz).each { |i|
|
35
|
+
tuple[i] = gens[i].current
|
36
|
+
}
|
37
|
+
if block.nil?
|
38
|
+
res << tuple.dup
|
39
|
+
else
|
40
|
+
block.call(tuple.dup)
|
41
|
+
end
|
42
|
+
|
43
|
+
# step forward
|
44
|
+
gens[-1].next
|
45
|
+
(sz-1).downto(0) { |i|
|
46
|
+
if gens[i].end?
|
47
|
+
if i > 0
|
48
|
+
gens[i].rewind
|
49
|
+
gens[i-1].next
|
50
|
+
else
|
51
|
+
return res
|
52
|
+
end
|
53
|
+
end
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
if __FILE__ == $0
|
60
|
+
p Enumerable.cross([1,2,3], [4], ["apple", "banana"])
|
61
|
+
|
62
|
+
[1,2,3].cross([4,5,6]) {|elem| p elem }
|
63
|
+
|
64
|
+
p Enumerable.cross([1,2], [3,4], [5,6], [7,8])
|
65
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'utils/gnuplot'
|
2
|
+
|
3
|
+
class GenericPlotter
|
4
|
+
def initialize(interval, dataset_configs)
|
5
|
+
@interval = interval
|
6
|
+
@datasets = dataset_configs
|
7
|
+
@datasets.each_with_index {|cfg, i|
|
8
|
+
cfg[:params] ||= 'with lines'
|
9
|
+
cfg[:title] ||= i.to_s
|
10
|
+
cfg[:data] ||= []
|
11
|
+
}
|
12
|
+
@gnuplot = GnuPlot.spawn
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
Thread.start {
|
17
|
+
@time = 0
|
18
|
+
loop do
|
19
|
+
@datasets.each do |cfg|
|
20
|
+
cfg[:proc].call(cfg[:data], @time)
|
21
|
+
end
|
22
|
+
@gnuplot.plot(@datasets)
|
23
|
+
sleep @interval
|
24
|
+
@time += @interval
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|