ray 0.0.1 → 0.1.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/.yardopts +4 -0
- data/README.md +17 -21
- data/Rakefile +18 -139
- data/VERSION +1 -1
- data/ext/audio.cpp +723 -0
- data/ext/{color.c → color.cpp} +25 -13
- data/ext/drawable.cpp +91 -0
- data/ext/event.cpp +460 -0
- data/ext/extconf.rb +5 -104
- data/ext/font.cpp +190 -0
- data/ext/image.cpp +733 -0
- data/ext/input.cpp +74 -0
- data/ext/ray.cpp +168 -0
- data/ext/ray.hpp +356 -0
- data/ext/{rect.c → rect.cpp} +51 -37
- data/ext/shader.cpp +169 -0
- data/ext/shape.cpp +409 -0
- data/ext/sprite.cpp +306 -0
- data/ext/text.cpp +181 -0
- data/ext/vector.cpp +215 -0
- data/guide.md +619 -0
- data/lib/ray/audio.rb +0 -41
- data/lib/ray/color.rb +32 -10
- data/lib/ray/drawable.rb +16 -0
- data/lib/ray/dsl/event_listener.rb +25 -2
- data/lib/ray/dsl/event_runner.rb +33 -5
- data/lib/ray/dsl/event_translator.rb +66 -30
- data/lib/ray/dsl/handler.rb +3 -2
- data/lib/ray/dsl/matcher.rb +58 -14
- data/lib/ray/font.rb +38 -96
- data/lib/ray/font_set.rb +8 -8
- data/lib/ray/game.rb +87 -66
- data/lib/ray/helper.rb +105 -10
- data/lib/ray/image.rb +150 -24
- data/lib/ray/image_set.rb +3 -1
- data/lib/ray/input.rb +10 -0
- data/lib/ray/music_set.rb +5 -3
- data/lib/ray/ray.rb +21 -9
- data/lib/ray/rect.rb +48 -7
- data/lib/ray/rmagick.rb +41 -0
- data/lib/ray/scene.rb +99 -43
- data/lib/ray/scene_list.rb +67 -0
- data/lib/ray/shape.rb +132 -0
- data/lib/ray/sound_set.rb +4 -2
- data/lib/ray/sprite.rb +49 -111
- data/lib/ray/text.rb +101 -0
- data/lib/ray/text_helper.rb +37 -0
- data/lib/ray/turtle.rb +215 -0
- data/lib/ray/vector.rb +226 -0
- data/samples/audio/spacial.rb +44 -0
- data/samples/hello_world/hello.rb +9 -13
- data/samples/hello_world/hello_dsl.rb +8 -12
- data/samples/hello_world/text.rb +15 -0
- data/samples/opengl/binding.rb +38 -0
- data/samples/opengl/image.rb +32 -0
- data/samples/opengl/opengl.rb +34 -0
- data/samples/opengl/shader.rb +42 -0
- data/samples/pong/pong.rb +14 -10
- data/samples/run_scene.rb +53 -0
- data/samples/shaders/scene.rb +40 -0
- data/samples/shaders/shaders.rb +42 -0
- data/samples/shaders/shape.rb +34 -0
- data/samples/sokoban/sokoban.rb +18 -18
- data/samples/test/actual_scene.rb +41 -0
- data/samples/test/scene_riot.rb +39 -0
- data/samples/test/scene_spec.rb +32 -0
- data/samples/test/scene_test_unit.rb +25 -0
- data/samples/turtle/byzantium.rb +45 -0
- data/samples/turtle/hilbert.rb +48 -0
- data/samples/turtle/koch.rb +55 -0
- data/samples/turtle/mandala.rb +61 -0
- data/samples/turtle/tree.rb +57 -0
- data/test/audio_test.rb +69 -0
- data/test/color_test.rb +77 -0
- data/test/drawable_test.rb +19 -0
- data/test/dsl_test.rb +93 -0
- data/test/font_test.rb +57 -0
- data/test/helpers.rb +94 -0
- data/test/image_test.rb +82 -0
- data/test/ray_test.rb +25 -0
- data/test/rect_test.rb +121 -0
- data/{spec → test}/res/VeraMono.ttf +0 -0
- data/{spec → test}/res/aqua.bmp +0 -0
- data/{spec → test}/res/aqua.png +0 -0
- data/{spec → test}/res/aqua2.bmp +0 -0
- data/{spec → test}/res/not_a_jpeg.jpeg +0 -0
- data/{spec → test}/res/pop.wav +0 -0
- data/test/resource_set_test.rb +99 -0
- data/test/run_all.rb +7 -0
- data/test/shape_test.rb +101 -0
- data/test/sprite_test.rb +89 -0
- data/test/text_test.rb +78 -0
- data/test/turtle_test.rb +176 -0
- data/test/vector_test.rb +111 -0
- data/yard_ext.rb +0 -28
- metadata +95 -139
- data/.gitignore +0 -23
- data/.gitmodules +0 -3
- data/.rspec +0 -3
- data/ext/audio.c +0 -473
- data/ext/event.c +0 -557
- data/ext/font.c +0 -287
- data/ext/image.c +0 -933
- data/ext/joystick.c +0 -145
- data/ext/ray.c +0 -489
- data/ext/ray.h +0 -245
- data/ext/ray_osx.m +0 -161
- data/lib/ray/joystick.rb +0 -30
- data/psp/SDL_psp_main.c +0 -84
- data/psp/bigdecimal/README +0 -60
- data/psp/bigdecimal/bigdecimal.c +0 -4697
- data/psp/bigdecimal/bigdecimal.h +0 -216
- data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +0 -85
- data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +0 -84
- data/psp/bigdecimal/lib/bigdecimal/math.rb +0 -235
- data/psp/bigdecimal/lib/bigdecimal/newton.rb +0 -77
- data/psp/bigdecimal/lib/bigdecimal/util.rb +0 -65
- data/psp/digest/bubblebabble/bubblebabble.c +0 -142
- data/psp/digest/defs.h +0 -20
- data/psp/digest/digest.c +0 -643
- data/psp/digest/digest.h +0 -32
- data/psp/digest/lib/digest.rb +0 -50
- data/psp/digest/lib/md5.rb +0 -27
- data/psp/digest/lib/sha1.rb +0 -27
- data/psp/digest/md5/md5.c +0 -420
- data/psp/digest/md5/md5.h +0 -80
- data/psp/digest/md5/md5init.c +0 -40
- data/psp/digest/rmd160/rmd160.c +0 -457
- data/psp/digest/rmd160/rmd160.h +0 -56
- data/psp/digest/rmd160/rmd160init.c +0 -40
- data/psp/digest/sha1/sha1.c +0 -269
- data/psp/digest/sha1/sha1.h +0 -39
- data/psp/digest/sha1/sha1init.c +0 -40
- data/psp/digest/sha2/lib/sha2.rb +0 -73
- data/psp/digest/sha2/sha2.c +0 -919
- data/psp/digest/sha2/sha2.h +0 -109
- data/psp/digest/sha2/sha2init.c +0 -52
- data/psp/enumerator/enumerator.c +0 -298
- data/psp/etc/etc.c +0 -559
- data/psp/ext.c +0 -289
- data/psp/fcntl/fcntl.c +0 -187
- data/psp/lib/rbconfig.rb +0 -178
- data/psp/nkf/lib/kconv.rb +0 -367
- data/psp/nkf/nkf-utf8/config.h +0 -88
- data/psp/nkf/nkf-utf8/nkf.c +0 -6040
- data/psp/nkf/nkf-utf8/utf8tbl.c +0 -8500
- data/psp/nkf/nkf-utf8/utf8tbl.h +0 -34
- data/psp/nkf/nkf.c +0 -654
- data/psp/socket/addrinfo.h +0 -173
- data/psp/socket/getaddrinfo.c +0 -676
- data/psp/socket/getnameinfo.c +0 -270
- data/psp/socket/pspsocket.c +0 -71
- data/psp/socket/pspsocket.h +0 -28
- data/psp/socket/socket.c +0 -4662
- data/psp/socket/sockport.h +0 -76
- data/psp/stringio/stringio.c +0 -1306
- data/psp/strscan/strscan.c +0 -1320
- data/psp/syck/bytecode.c +0 -1166
- data/psp/syck/emitter.c +0 -1242
- data/psp/syck/gram.c +0 -1894
- data/psp/syck/gram.h +0 -79
- data/psp/syck/handler.c +0 -174
- data/psp/syck/implicit.c +0 -2990
- data/psp/syck/node.c +0 -408
- data/psp/syck/rubyext.c +0 -2367
- data/psp/syck/syck.c +0 -504
- data/psp/syck/syck.h +0 -456
- data/psp/syck/token.c +0 -2725
- data/psp/syck/yaml2byte.c +0 -257
- data/psp/syck/yamlbyte.h +0 -170
- data/psp/thread/thread.c +0 -1175
- data/psp/zlib/zlib.c +0 -3547
- data/script.rb +0 -10
- data/spec/ray/audio_spec.rb +0 -146
- data/spec/ray/color_spec.rb +0 -57
- data/spec/ray/event_spec.rb +0 -80
- data/spec/ray/font_spec.rb +0 -93
- data/spec/ray/image_set_spec.rb +0 -48
- data/spec/ray/image_spec.rb +0 -162
- data/spec/ray/joystick_spec.rb +0 -21
- data/spec/ray/matcher_spec.rb +0 -50
- data/spec/ray/ray_spec.rb +0 -88
- data/spec/ray/rect_spec.rb +0 -154
- data/spec/ray/resource_set_spec.rb +0 -105
- data/spec/ray/sprite_spec.rb +0 -163
- data/spec/spec.opts +0 -4
- data/spec/spec_helper.rb +0 -8
data/test/image_test.rb
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb'
|
|
2
|
+
|
|
3
|
+
context Ray::Image do
|
|
4
|
+
setup { Ray::Image }
|
|
5
|
+
|
|
6
|
+
context "created with a hash" do
|
|
7
|
+
setup { topic.new(:w => 50, :h => 70) }
|
|
8
|
+
|
|
9
|
+
asserts(:w).equals(50)
|
|
10
|
+
asserts(:h).equals(70)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
denies("creating from a file") {
|
|
14
|
+
topic.new(path_of("aqua.bmp"))
|
|
15
|
+
}.raises(RuntimeError)
|
|
16
|
+
|
|
17
|
+
asserts("creating from a non-existing file") {
|
|
18
|
+
topic.new(path_of("doesnt_exist.bmp"))
|
|
19
|
+
}.raises(RuntimeError)
|
|
20
|
+
|
|
21
|
+
denies("creating from an IO object") {
|
|
22
|
+
open(path_of("aqua.bmp")) { |io| topic.new(io) }
|
|
23
|
+
}.raises(RuntimeError)
|
|
24
|
+
|
|
25
|
+
asserts("creating from an invalid IO object") {
|
|
26
|
+
open(path_of("VeraMono.ttf")) { |io| topic.new(io) }
|
|
27
|
+
}.raises(RuntimeError)
|
|
28
|
+
|
|
29
|
+
denies "two different images are equal, despite their content" do
|
|
30
|
+
a = topic.new(:w => 10, :h => 10).fill(Ray::Color.red).update
|
|
31
|
+
b = topic.new(:w => 10, :h => 10).fill(Ray::Color.red).update
|
|
32
|
+
|
|
33
|
+
a == b
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
asserts "two images representing the same one are equal" do
|
|
37
|
+
Ray.screen == Ray.screen
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "an image" do
|
|
42
|
+
setup { Ray::Image.new(:w => 10, :h => 10).fill(Ray::Color.green).update }
|
|
43
|
+
|
|
44
|
+
asserts(:size).equals Ray::Vector2[10, 10]
|
|
45
|
+
|
|
46
|
+
asserts("#dup returns a copy of the receiver") { topic.dup != topic }
|
|
47
|
+
|
|
48
|
+
asserts("a pixel outside the image") { topic[10, 10] }.nil
|
|
49
|
+
asserts("a pixel inside the image is a Ray::Color") { topic[5, 5].is_a? Ray::Color }
|
|
50
|
+
|
|
51
|
+
asserts("setting a pixel outside the image") {
|
|
52
|
+
topic.lock { topic[10, 10] = Ray::Color.red }
|
|
53
|
+
}.raises(ArgumentError)
|
|
54
|
+
|
|
55
|
+
denies("setting a pixel outside the image") {
|
|
56
|
+
topic { topic[5, 5] = Ray::Color.red }
|
|
57
|
+
}.raises(RuntimeError)
|
|
58
|
+
|
|
59
|
+
asserts("setting a pixel in a non-locked image") {
|
|
60
|
+
topic[5, 5] = Ray::Color.red
|
|
61
|
+
}.raises(RuntimeError)
|
|
62
|
+
|
|
63
|
+
context "after having changed a pixel" do
|
|
64
|
+
hookup { topic.lock { topic[3, 2] = Ray::Color.green } }
|
|
65
|
+
asserts("the changed pixel") { topic[3, 2] }.equals(Ray::Color.green)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
asserts(:clip).equals(Ray::Rect.new(0, 0, 10, 10))
|
|
69
|
+
|
|
70
|
+
context "after having changed the clipping rect" do
|
|
71
|
+
hookup { topic.clip([5, 5, 3, 3]) }
|
|
72
|
+
asserts(:clip).equals(Ray::Rect.new(5, 5, 3, 3))
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
asserts("clip inside a block and otside the block") {
|
|
76
|
+
res = []
|
|
77
|
+
topic.clip([5, 5, 3, 3]) { res << topic.clip }
|
|
78
|
+
res << topic.clip
|
|
79
|
+
}.equals([Ray::Rect.new(5, 5, 3, 3), Ray::Rect.new(0, 0, 10, 10)])
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
run_tests if __FILE__ == $0
|
data/test/ray_test.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb'
|
|
2
|
+
|
|
3
|
+
context "a newly created window" do
|
|
4
|
+
setup { Ray.create_window(:w => 100, :h => 150) }
|
|
5
|
+
|
|
6
|
+
asserts "has the size given at creation" do
|
|
7
|
+
topic.w == 100 && topic.h == 150
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
asserts("equal to Ray.screen") { topic == Ray.screen }
|
|
11
|
+
|
|
12
|
+
asserts "can change pixels when locked" do
|
|
13
|
+
topic.lock do
|
|
14
|
+
topic[10, 15] = Ray::Color.green
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
topic[10, 15] == Ray::Color.green
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
asserts("changing pixel when not locked") {
|
|
21
|
+
topic[10, 15] = Ray::Color.blue
|
|
22
|
+
}.raises(RuntimeError)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
run_tests if __FILE__ == $0
|
data/test/rect_test.rb
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb'
|
|
2
|
+
|
|
3
|
+
context "a rect" do
|
|
4
|
+
setup { Ray::Rect.new(10, 15, 20, 30) }
|
|
5
|
+
|
|
6
|
+
asserts(:pos).equals(Ray::Vector2[10, 15])
|
|
7
|
+
asserts(:size).equals(Ray::Vector2[20, 30])
|
|
8
|
+
|
|
9
|
+
[:x, :y, :w, :h].each do |param|
|
|
10
|
+
context "after having changed #{param}" do
|
|
11
|
+
setup do |rect|
|
|
12
|
+
rect = Ray::Rect.new(10, 10, 10, 10)
|
|
13
|
+
rect.send("#{param}=", 5)
|
|
14
|
+
rect
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
asserts(param).equals(5)
|
|
18
|
+
|
|
19
|
+
asserts "the others components keep their values" do
|
|
20
|
+
[:x, :y, :w, :h].all? do |other|
|
|
21
|
+
other == param || topic.send(other) == 10
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "copied from another rect" do
|
|
28
|
+
setup do
|
|
29
|
+
@old_topic = topic
|
|
30
|
+
topic.dup
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
asserts "is equal to the original object" do
|
|
34
|
+
topic == @old_topic
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
asserts "is eql? to the original object" do
|
|
38
|
+
topic.eql? @old_topic
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
asserts(:hash).equals { @old_topic.hash }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "created with two integers" do
|
|
45
|
+
setup { Ray::Rect.new(30, 35) }
|
|
46
|
+
|
|
47
|
+
asserts(:w).equals(0)
|
|
48
|
+
asserts(:h).equals(0)
|
|
49
|
+
|
|
50
|
+
asserts(:x).equals(30)
|
|
51
|
+
asserts(:y).equals(35)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
asserts("creating a rect with a hash without x or y") {
|
|
55
|
+
Ray::Rect.new(:x => 10)
|
|
56
|
+
}.raises(ArgumentError)
|
|
57
|
+
|
|
58
|
+
asserts("creting a rect with a hash with width but not height") {
|
|
59
|
+
Ray::Rect.new(:x => 10, :y => 200, :width => 300)
|
|
60
|
+
}.raises(ArgumentError)
|
|
61
|
+
|
|
62
|
+
asserts("creating a rect with a hash with a size but without position") {
|
|
63
|
+
Ray::Rect.new(:width => 100, :height => 100)
|
|
64
|
+
}.raises(ArgumentError)
|
|
65
|
+
|
|
66
|
+
asserts "inside itself" do
|
|
67
|
+
topic.inside? Ray::Rect.new(10, 15, 20, 30)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
asserts "inside a rect inside itself" do
|
|
71
|
+
topic.inside? Ray::Rect.new(8, 13, 30, 40)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
asserts "not inside a rect only colliding with it" do
|
|
75
|
+
!Ray::Rect.new(5, 10, 20, 20).inside?(topic) &&
|
|
76
|
+
!Ray::Rect.new(11, 16, 40, 50).inside?(topic)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
asserts "not inside a rect outside the receiver" do
|
|
80
|
+
!Ray::Rect.new(1, 2, 3, 5).inside?(topic) &&
|
|
81
|
+
!Ray::Rect.new(100, 150, 350, 450).inside?(topic)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
asserts "not outside itself" do
|
|
85
|
+
not topic.outside? Ray::Rect.new(10, 15, 20, 30)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
asserts "outside a rect outside itself" do
|
|
89
|
+
Ray::Rect.new(1, 2, 3, 5).outside?(topic) &&
|
|
90
|
+
Ray::Rect.new(100, 150, 350, 450).outside?(topic)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
asserts "not outside a rect inside itself" do
|
|
94
|
+
not Ray::Rect.new(13, 17, 10, 20).outside?(topic)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
asserts "not outside a rect colliding with itself" do
|
|
98
|
+
!Ray::Rect.new(5, 10, 20, 20).outside?(topic) &&
|
|
99
|
+
!Ray::Rect.new(11, 16, 40, 50).outside?(topic)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
asserts "collides with itself" do
|
|
103
|
+
topic.collide? Ray::Rect.new(10, 15, 20, 30)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
asserts "doesn't collide with a rect outside itself" do
|
|
107
|
+
!Ray::Rect.new(1, 2, 3, 5).collide?(topic) &&
|
|
108
|
+
!Ray::Rect.new(100, 150, 350, 450).collide?(topic)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
asserts "collides with a rect inside itself" do
|
|
112
|
+
Ray::Rect.new(13, 17, 10, 20).collide?(topic)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
asserts "collides with rects colliding with itself" do
|
|
116
|
+
Ray::Rect.new(5, 10, 20, 20).collide?(topic) &&
|
|
117
|
+
Ray::Rect.new(11, 16, 40, 50).collide?(topic)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
run_tests if __FILE__ == $0
|
|
File without changes
|
data/{spec → test}/res/aqua.bmp
RENAMED
|
File without changes
|
data/{spec → test}/res/aqua.png
RENAMED
|
File without changes
|
data/{spec → test}/res/aqua2.bmp
RENAMED
|
File without changes
|
|
File without changes
|
data/{spec → test}/res/pop.wav
RENAMED
|
File without changes
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb'
|
|
2
|
+
|
|
3
|
+
context "a resource set" do
|
|
4
|
+
setup do
|
|
5
|
+
Module.new do
|
|
6
|
+
extend Ray::ResourceSet
|
|
7
|
+
|
|
8
|
+
def self.missing_pattern(*args)
|
|
9
|
+
args
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
add_set(/^string:(.+)$/) do |str|
|
|
13
|
+
str
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
asserts "uses the block it was passed to create objects" do
|
|
19
|
+
topic["string:test"] == "test"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
asserts "always returns the same object" do
|
|
23
|
+
topic["string:my string"].equal? topic["string:my string"]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
asserts "uses the missing_pattern method when a string isn't matched" do
|
|
27
|
+
topic["Hello world"] == ["Hello world"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
asserts("using it with another arguments") {
|
|
31
|
+
topic["foo", 3]
|
|
32
|
+
}.raises(ArgumentError)
|
|
33
|
+
|
|
34
|
+
asserts "can select objects from cache" do
|
|
35
|
+
first, sec = topic["string:first"], topic["string:sec"]
|
|
36
|
+
topic.select! { |key, val| key == "string:first" }
|
|
37
|
+
|
|
38
|
+
first.equal?(topic["string:first"]) && !sec.equal?(topic["string:sec"])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
asserts "can reject objects from cache" do
|
|
42
|
+
first, sec = topic["string:first"], topic["string:sec"]
|
|
43
|
+
topic.reject! { |key, val| key == "string:first" }
|
|
44
|
+
|
|
45
|
+
!first.equal?(topic["string:first"]) && sec.equal?(topic["string:sec"])
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "a resource set without missing_pattern" do
|
|
50
|
+
setup do
|
|
51
|
+
Module.new { extend Ray::ResourceSet }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
asserts("using an unmatched string") {
|
|
55
|
+
topic["anything"]
|
|
56
|
+
}.raises(Ray::NoPatternError)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "a resource set with more arugments" do
|
|
60
|
+
setup do
|
|
61
|
+
Module.new do
|
|
62
|
+
extend Ray::ResourceSet
|
|
63
|
+
|
|
64
|
+
need_argument_count 1
|
|
65
|
+
|
|
66
|
+
def self.missing_pattern(*args)
|
|
67
|
+
args
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
add_set(/^string:(.+)$/) do |str, times|
|
|
71
|
+
str * times
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
denies("using it with more arguments") {
|
|
77
|
+
topic["string:foo", 3]
|
|
78
|
+
}.raises(StandardError)
|
|
79
|
+
|
|
80
|
+
asserts "provides user arguments after captures" do
|
|
81
|
+
res = []
|
|
82
|
+
|
|
83
|
+
topic.add_set(/my_(.)/) do |char, times|
|
|
84
|
+
res << char
|
|
85
|
+
res << times
|
|
86
|
+
|
|
87
|
+
true
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
topic["my_a", 3]
|
|
91
|
+
res == ["a", 3]
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
asserts "passes all the arguments to missing_pattern" do
|
|
95
|
+
topic["a", 3] == ["a", 3]
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
run_tests if __FILE__ == $0
|
data/test/run_all.rb
ADDED
data/test/shape_test.rb
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb'
|
|
2
|
+
|
|
3
|
+
context "a shape" do
|
|
4
|
+
setup { Ray::Shape.new }
|
|
5
|
+
|
|
6
|
+
asserts(:pos).equals(Ray::Vector2[0, 0])
|
|
7
|
+
asserts(:point_count).equals(0)
|
|
8
|
+
asserts(:outline_width).equals(0)
|
|
9
|
+
asserts(:angle).equals(0)
|
|
10
|
+
asserts(:scale).equals(Ray::Vector2[1.0, 1.0])
|
|
11
|
+
|
|
12
|
+
asserts("setting the color of a point outside bounds") {
|
|
13
|
+
topic.set_color_of(0, Ray::Color.blue)
|
|
14
|
+
}.raises(ArgumentError)
|
|
15
|
+
|
|
16
|
+
asserts("setting the outline of a point outside bounds") {
|
|
17
|
+
topic.set_outline_of(0, Ray::Color.blue)
|
|
18
|
+
}.raises(ArgumentError)
|
|
19
|
+
|
|
20
|
+
asserts("setting the position of a point outside bounds") {
|
|
21
|
+
topic.set_position_of(0, [10, 10])
|
|
22
|
+
}.raises(ArgumentError)
|
|
23
|
+
|
|
24
|
+
asserts("color, outline, and position of a point outside bounds") {
|
|
25
|
+
[topic.color_of(0), topic.outline_of(0), topic.position_of(0)]
|
|
26
|
+
}.equals([nil, nil, nil])
|
|
27
|
+
|
|
28
|
+
context "with a point" do
|
|
29
|
+
hookup do
|
|
30
|
+
topic.add_point([5, 3], Ray::Color.red, Ray::Color.black)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
asserts(:point_count).equals(1)
|
|
34
|
+
|
|
35
|
+
asserts("position of the point") { topic.position_of(0) }.equals(Ray::Vector2[5, 3])
|
|
36
|
+
asserts("color of the point") { topic.color_of(0) }.equals(Ray::Color.red)
|
|
37
|
+
asserts("outline of the point") { topic.outline_of(0) }.equals(Ray::Color.black)
|
|
38
|
+
|
|
39
|
+
context "copied from another shape" do
|
|
40
|
+
setup do
|
|
41
|
+
@old_topic = topic
|
|
42
|
+
topic.dup
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
asserts(:point_count).equals(1)
|
|
46
|
+
|
|
47
|
+
asserts("position of the point") { topic.position_of(0) }.equals(Ray::Vector2[5, 3])
|
|
48
|
+
asserts("color of the point") { topic.color_of(0) }.equals(Ray::Color.red)
|
|
49
|
+
asserts("outline of the point") { topic.outline_of(0) }.equals(Ray::Color.black)
|
|
50
|
+
|
|
51
|
+
denies "is the same object as the original one" do
|
|
52
|
+
topic.equal? @old_topic
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context "with outline_width = 10" do
|
|
58
|
+
hookup { topic.outline_width = 10 }
|
|
59
|
+
asserts(:outline_width).equals(10)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context "with angle = 10" do
|
|
63
|
+
hookup { topic.angle = 10 }
|
|
64
|
+
asserts(:angle).equals(10)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context "with scale = [10, 5.5]" do
|
|
68
|
+
hookup { topic.scale = [10, 5.5] }
|
|
69
|
+
asserts(:scale).equals(Ray::Vector2[10, 5.5])
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context "with position = [3, 4]" do
|
|
73
|
+
hookup { topic.pos = [3, 4] }
|
|
74
|
+
asserts(:pos).equals(Ray::Vector2[3, 4])
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context "a shape point" do
|
|
79
|
+
setup do
|
|
80
|
+
shape = Ray::Shape.new(1) do |p|
|
|
81
|
+
p.pos = [10, 15]
|
|
82
|
+
p.color = Ray::Color.new(1, 2, 3)
|
|
83
|
+
p.outline = Ray::Color.new(4, 5, 6)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
shape[0]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
asserts(:pos).equals(Ray::Vector2[10, 15])
|
|
90
|
+
asserts(:color).equals(Ray::Color.new(1, 2, 3))
|
|
91
|
+
asserts(:outline).equals(Ray::Color.new(4, 5, 6))
|
|
92
|
+
|
|
93
|
+
asserts(:id).equals(0)
|
|
94
|
+
|
|
95
|
+
asserts("first position, color, and outline of the shape") {
|
|
96
|
+
shape = topic.shape
|
|
97
|
+
[shape.position_of(0), shape.color_of(0), shape.outline_of(0)]
|
|
98
|
+
}.equals([Ray::Vector2[10, 15], Ray::Color.new(1, 2, 3), Ray::Color.new(4, 5, 6)])
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
run_tests if __FILE__ == $0
|