seh 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,134 @@
1
+ require 'spec_helper'
2
+ require 'seh/event_type'
3
+
4
+ module Seh
5
+ describe EventType do
6
+ before :each do
7
+ @type = :some_type
8
+ @type1 = :type1
9
+ @type2 = :type2
10
+ @type3 = :type3
11
+ @type4 = :type4
12
+ end
13
+
14
+ context "with a single basic type" do
15
+ subject { EventType.new :some_type }
16
+
17
+ it { subject.match([@type]).should be_true }
18
+ it { subject.match([@type, :another, :bar]).should be_true }
19
+ it { subject.match([:foo, :bar, @type]).should be_true }
20
+
21
+ it { subject.match([nil]).should be_false }
22
+ it { subject.match([:wrong_type]).should be_false }
23
+ it { subject.match([:wrong_type, :bar, :bazz]).should be_false }
24
+ it { subject.match([]).should be_false }
25
+ end
26
+
27
+ context "with nil type which should match everything" do
28
+ subject { EventType.new nil }
29
+ it { subject.match([nil]).should be_true }
30
+ it { subject.match([]).should be_true }
31
+ it { subject.match([@type]).should be_true }
32
+ it { subject.match([@type, :another, :bar]).should be_true }
33
+ it { subject.match([:foo, :bar, @type]).should be_true }
34
+ it { subject.match([:wrong_type, :bar, :bazz]).should be_true }
35
+ end
36
+
37
+ context "And with only basic types nested" do
38
+ subject { EventType::And.new @type1, @type2, @type3 }
39
+
40
+ it { subject.match([@type1,@type3,@type2]).should be_true }
41
+ it { subject.match([@type1,@type3,@type2,:another_type]).should be_true }
42
+
43
+ it { subject.match([@type1]).should be_false }
44
+ it { subject.match([@type2]).should be_false }
45
+ it { subject.match([@type3]).should be_false }
46
+ it { subject.match([@type1,@type2]).should be_false }
47
+ it { subject.match([@type3,@type2]).should be_false }
48
+
49
+ it { subject.match([nil]).should be_false }
50
+ it { subject.match([]).should be_false }
51
+ end
52
+
53
+ context "Or with only basic types nested" do
54
+ subject { EventType::Or.new @type1, @type2, @type3 }
55
+
56
+ it { subject.match([@type1]).should be_true }
57
+ it { subject.match([@type2]).should be_true }
58
+ it { subject.match([@type3]).should be_true }
59
+ it { subject.match([@type1,@type2,@type3]).should be_true }
60
+ it { subject.match([@type1,:another_type]).should be_true }
61
+
62
+ it { subject.match([:another_type, :another_again_type]).should be_false }
63
+ it { subject.match([nil]).should be_false }
64
+ it { subject.match([]).should be_false }
65
+ end
66
+
67
+ context "Not with only a basic type nested" do
68
+ subject { EventType::Not.new @type1 }
69
+
70
+ it { subject.match([nil]).should be_true }
71
+ it { subject.match([]).should be_true }
72
+ it { subject.match([@type2,@type3]).should be_true }
73
+
74
+ it { subject.match([@type1]).should be_false }
75
+ it { subject.match([@type1,:another_type]).should be_false }
76
+ end
77
+
78
+ context "And with two nested Nots" do
79
+ subject { EventType::And.new @type2, EventType::Not.new(@type1), EventType::Not.new(@type3) }
80
+
81
+ it { subject.match([@type2]).should be_true }
82
+ it { subject.match([@type2,:bar]).should be_true }
83
+
84
+ it { subject.match([@type1,@type2]).should be_false }
85
+ it { subject.match([@type3,@type2]).should be_false }
86
+ it { subject.match([@type3,@type1]).should be_false }
87
+ it { subject.match([@type1]).should be_false }
88
+ it { subject.match([:another_type]).should be_false }
89
+ it { subject.match([nil]).should be_false }
90
+ it { subject.match([]).should be_false }
91
+ end
92
+
93
+ context "Or with a nested And" do
94
+ subject { EventType::Or.new @type2, EventType::And.new(@type1,@type3) }
95
+ it { subject.match([@type2]).should be_true }
96
+ it { subject.match([@type1,@type3]).should be_true }
97
+ it { subject.match([@type1,@type3,@type2]).should be_true }
98
+
99
+ it { subject.match([@type1]).should be_false }
100
+ it { subject.match([@type3]).should be_false }
101
+ it { subject.match([:another_type]).should be_false }
102
+ it { subject.match([nil]).should be_false }
103
+ it { subject.match([]).should be_false }
104
+ end
105
+
106
+ context "A more complicated nested example" do
107
+ subject do
108
+ EventType::Or.new(
109
+ @type,
110
+ EventType::And.new(@type1,@type2),
111
+ EventType::And.new(@type2,@type3),
112
+ EventType::And.new(@type4,EventType::Not.new(@type3)),
113
+ EventType::Or.new(:success)
114
+ )
115
+ end
116
+
117
+ it { subject.match([:success]).should be_true }
118
+ it { subject.match([:success,@type3]).should be_true }
119
+ it { subject.match([@type]).should be_true }
120
+ it { subject.match([@type1,@type2]).should be_true }
121
+ it { subject.match([@type2,@type3]).should be_true }
122
+ it { subject.match([@type4]).should be_true }
123
+
124
+ it { subject.match([@type1,@type3]).should be_false }
125
+ it { subject.match([@type4,@type3]).should be_false }
126
+ it { subject.match([@type1]).should be_false }
127
+ it { subject.match([@type2]).should be_false }
128
+ it { subject.match([@type3]).should be_false }
129
+ it { subject.match([:another_type]).should be_false }
130
+ it { subject.match([nil]).should be_false }
131
+ it { subject.match([]).should be_false }
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'seh'
3
+
4
+ describe Seh do
5
+ context "with data to test EventType aliases" do
6
+ before :each do
7
+ @x = :one
8
+ @y = :two
9
+ @z = :three
10
+ @result = double Seh::EventType
11
+ end
12
+ it "delegates Seh::and to EventType" do
13
+ Seh::EventType::And.should_receive(:new).with(@x,@y,@z).once.and_return @result
14
+ Seh::and(@x,@y,@z).should eq(@result)
15
+ end
16
+ it "delegates Seh::or to EventType" do
17
+ Seh::EventType::Or.should_receive(:new).with(@x,@y,@z).once.and_return @result
18
+ Seh::or(@x,@y,@z).should eq(@result)
19
+ end
20
+ it "delegates Seh::not to EventType" do
21
+ Seh::EventType::Not.should_receive(:new).with(@x).once.and_return @result
22
+ Seh::not(@x).should eq(@result)
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,21 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-19 00:00:00.000000000Z
12
+ date: 2013-01-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: ! 'Structured event handler. Pure ruby event handling similar to w3c
15
- dom events; alpha wip. Lots of bells and whistles to support complex event handling
16
- as required by stuff like video games. Event handling in a synchronous specific
17
- order. Events ''bubble'', and event targets can have multiple parents and common
18
- ancestors. Staged event callbacks: event.before { ''the united states of'' }; event.after
19
- { ''america'' }. Staged callbacks allow an ancestor to influence affect of event
20
- on a descendant: ancestor.before { |event| event.damage *= 2 }; descendant.after
21
- { |event| player.health -= event.damage }. Events use ''tag-style'' types: event.type
22
- :hostile ; event.type :spell. Handle only events which pass a filter: player.bind(
23
- Seh::and :hostile, Seh::not( :spell ) ) { |event| ''Hostile non-spell!!'' }. Optional
24
- event failure: event.fail; event.success { ''yay!'' }; event.failure { ''oops!''
25
- }. Event inherits from OpenStruct for dynamic properties: event.omgs = ''omgs a
26
- dynamic attribute'''
14
+ description: Structured event handler. Pure ruby event handling similar to w3c dom
15
+ events. Synchronous, local event handling for complex emergent behaviors as required
16
+ by something like a game engine. v0.3.0 improves a lot on v0.1.0.
27
17
  email:
28
18
  - ryan.berckmans@gmail.com
29
19
  executables: []
@@ -34,14 +24,30 @@ files:
34
24
  - .rvmrc
35
25
  - .yardopts
36
26
  - Gemfile
27
+ - Gemfile.lock
37
28
  - README.md
38
29
  - Rakefile
30
+ - examples/epic_battle.rb
31
+ - examples/event.rb
32
+ - examples/event/damage.rb
33
+ - examples/event/hostile.rb
34
+ - examples/event/melee_attack.rb
35
+ - examples/event_color.rb
36
+ - examples/mob.rb
39
37
  - lib/seh.rb
40
38
  - lib/seh/event.rb
39
+ - lib/seh/event_bind.rb
40
+ - lib/seh/event_bind_disconnector.rb
41
41
  - lib/seh/event_target.rb
42
42
  - lib/seh/event_type.rb
43
43
  - lib/seh/version.rb
44
44
  - seh.gemspec
45
+ - spec/seh/event_bind_disconnector_spec.rb
46
+ - spec/seh/event_bind_spec.rb
47
+ - spec/seh/event_spec.rb
48
+ - spec/seh/event_target_spec.rb
49
+ - spec/seh/event_type_spec.rb
50
+ - spec/seh_spec.rb
45
51
  - spec/spec_helper.rb
46
52
  homepage: https://github.com/ryanberckmans/seh
47
53
  licenses: []
@@ -63,9 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
69
  version: '0'
64
70
  requirements: []
65
71
  rubyforge_project: seh
66
- rubygems_version: 1.8.5
72
+ rubygems_version: 1.8.24
67
73
  signing_key:
68
74
  specification_version: 3
69
- summary: Structured event handler. Pure ruby event handling similar to w3c dom events;
70
- alpha wip.
75
+ summary: Structured event handler. Pure ruby event handling similar to w3c dom events.
71
76
  test_files: []