pushdown 0.1.0.pre.20210714190141 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env rspec -cfd
2
+
3
+ require_relative '../../spec_helper'
4
+
5
+ require 'pushdown/transition/pop'
6
+ require 'pushdown/state'
7
+
8
+
9
+ RSpec.describe( Pushdown::Transition::Pop ) do
10
+
11
+ let( :state_class ) do
12
+ Class.new( Pushdown::State )
13
+ end
14
+
15
+ let( :state_a ) { state_class.new }
16
+ let( :state_b ) { state_class.new }
17
+ let( :state_c ) { state_class.new }
18
+
19
+ let( :state_data ) { Object.new }
20
+
21
+ let( :stack ) do
22
+ return [ state_a, state_b, state_c ]
23
+ end
24
+
25
+
26
+ it "pops the last state from the stack when applied" do
27
+ stack = [ state_a, state_b, state_c ]
28
+ transition = described_class.new( :pop_test )
29
+
30
+ new_stack = transition.apply( stack )
31
+
32
+ expect( new_stack ).to eq([ state_a, state_b ])
33
+ end
34
+
35
+
36
+ it "passes state data through the transition callbacks" do
37
+ transition = described_class.new( :pop_test, state_data )
38
+
39
+ expect( state_c ).to receive( :on_stop ).with( state_data ).
40
+ and_return( state_data ).once.ordered
41
+ expect( state_b ).to receive( :on_resume ).with( state_data ).once.ordered
42
+
43
+ transition.apply( stack )
44
+ end
45
+
46
+
47
+ it "errors if applied to a stack that has only one state" do
48
+ stack = [ state_a ]
49
+ transition = described_class.new( :pop_test )
50
+
51
+ expect {
52
+ transition.apply( stack )
53
+ }.to raise_error( Pushdown::TransitionError, /can't pop/i )
54
+ end
55
+
56
+
57
+ it "errors if applied to an empty stack" do
58
+ stack = []
59
+ transition = described_class.new( :pop_test )
60
+
61
+ expect {
62
+ transition.apply( stack )
63
+ }.to raise_error( Pushdown::TransitionError, /can't pop/i )
64
+ end
65
+
66
+ end
67
+
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env rspec -cfd
2
+
3
+ require_relative '../../spec_helper'
4
+
5
+ require 'pushdown'
6
+ require 'pushdown/transition/push'
7
+
8
+
9
+ RSpec.describe( Pushdown::Transition::Push ) do
10
+
11
+ let( :state_class ) do
12
+ Class.new( Pushdown::State )
13
+ end
14
+ let( :other_state_class ) do
15
+ Class.new( Pushdown::State )
16
+ end
17
+
18
+ let( :state_a ) { state_class.new }
19
+ let( :state_b ) { state_class.new }
20
+ let( :state_c ) { other_state_class.new }
21
+
22
+ let( :stack ) do
23
+ return [ state_a, state_b ]
24
+ end
25
+
26
+ let( :state_data ) { Object.new }
27
+
28
+
29
+ it "pushes a new state onto the stack when applied" do
30
+ transition = described_class.new( :push_test, other_state_class )
31
+
32
+ new_stack = transition.apply( stack )
33
+
34
+ expect( new_stack ).to be_an( Array )
35
+ expect( new_stack.length ).to eq( 3 )
36
+ expect( new_stack.last ).to be_a( other_state_class )
37
+ end
38
+
39
+
40
+ it "passes state data through the transition callbacks" do
41
+ transition = described_class.new( :push_test, other_state_class, state_data )
42
+
43
+ expect( state_b ).to receive( :on_pause ).
44
+ with( state_data ).once.and_return( state_data ).ordered
45
+
46
+ expect( other_state_class ).to receive( :new ).and_return( state_c )
47
+ expect( state_c ).to receive( :on_start ).with( state_data ).once.ordered
48
+
49
+ transition.apply( stack )
50
+ end
51
+
52
+ end
53
+
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env rspec -cfd
2
+
3
+ require_relative '../../spec_helper'
4
+
5
+ require 'pushdown/transition/replace'
6
+ require 'pushdown/state'
7
+
8
+ RSpec.describe( Pushdown::Transition::Replace ) do
9
+
10
+ let( :state_class ) do
11
+ Class.new( Pushdown::State )
12
+ end
13
+ let( :other_state_class ) do
14
+ Class.new( Pushdown::State )
15
+ end
16
+
17
+ let( :state_a ) { state_class.new }
18
+ let( :state_b ) { state_class.new }
19
+ let( :state_c ) { state_class.new }
20
+ let( :state_d ) { other_state_class.new }
21
+
22
+ let( :stack ) do
23
+ return [ state_a, state_b, state_c ]
24
+ end
25
+
26
+ let( :state_data ) { Object.new }
27
+
28
+
29
+ it "replaces the current stack members with a single new instance of a state when applied" do
30
+ transition = described_class.new( :replace_test, other_state_class )
31
+
32
+ new_stack = transition.apply( stack )
33
+
34
+ expect( new_stack ).to be_an( Array )
35
+ expect( new_stack.length ).to eq( 1 )
36
+ expect( new_stack.last ).to be_a( other_state_class )
37
+ end
38
+
39
+
40
+ it "passes state data through the transition callbacks" do
41
+ transition = described_class.new( :replace_test, other_state_class, state_data )
42
+
43
+ expect( state_c ).to receive( :on_stop ).
44
+ with( state_data ).once.and_return( state_data ).ordered
45
+ expect( state_b ).to receive( :on_stop ).
46
+ with( state_data ).once.and_return( state_data ).ordered
47
+ expect( state_a ).to receive( :on_stop ).
48
+ with( state_data ).once.and_return( state_data ).ordered
49
+
50
+ expect( other_state_class ).to receive( :new ).and_return( state_c )
51
+ expect( state_c ).to receive( :on_start ).with( state_data ).once.ordered
52
+
53
+ transition.apply( stack )
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env rspec -cfd
2
+
3
+ require_relative '../../spec_helper'
4
+
5
+ require 'pushdown/transition/switch'
6
+ require 'pushdown/state'
7
+
8
+ RSpec.describe( Pushdown::Transition::Switch ) do
9
+
10
+ let( :state_class ) do
11
+ Class.new( Pushdown::State )
12
+ end
13
+ let( :other_state_class ) do
14
+ Class.new( Pushdown::State )
15
+ end
16
+
17
+ let( :state_a ) { state_class.new }
18
+ let( :state_b ) { state_class.new }
19
+ let( :state_c ) { other_state_class.new }
20
+
21
+ let( :stack ) do
22
+ return [ state_a, state_b ]
23
+ end
24
+
25
+ let( :state_data ) { Object.new }
26
+
27
+
28
+ it "pops the current state off the stack and adds a new state when applied" do
29
+ transition = described_class.new( :switch_test, other_state_class )
30
+
31
+ new_stack = transition.apply( stack )
32
+
33
+ expect( new_stack ).to be_an( Array )
34
+ expect( new_stack.length ).to eq( 2 )
35
+ expect( new_stack.last ).to be_a( other_state_class )
36
+ end
37
+
38
+
39
+ it "passes state data through the transition callbacks" do
40
+ transition = described_class.new( :switch_test, other_state_class, state_data )
41
+
42
+ expect( state_b ).to receive( :on_stop ).
43
+ with( state_data ).once.and_return( state_data ).ordered
44
+
45
+ expect( other_state_class ).to receive( :new ).and_return( state_c )
46
+ expect( state_c ).to receive( :on_start ).with( state_data ).once.ordered
47
+
48
+ transition.apply( stack )
49
+ end
50
+
51
+ end
52
+
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env rspec -cfd
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ require 'pushdown/transition'
6
+ require 'pushdown/state'
7
+
8
+
9
+ RSpec.describe( Pushdown::Transition ) do
10
+
11
+ let( :state_class ) do
12
+ Class.new( Pushdown::State )
13
+ end
14
+
15
+ let( :state_a ) { state_class.new }
16
+ let( :state_b ) { state_class.new }
17
+
18
+
19
+ it "is an abstract class" do
20
+ expect {
21
+ described_class.new( :change_state )
22
+ }.to raise_error( NoMethodError )
23
+ end
24
+
25
+
26
+ describe 'complete concrete subclass' do
27
+
28
+ let( :subclass ) do
29
+ Class.new( described_class ) do
30
+
31
+ def initialize( name, new_state, *args )
32
+ super( name, *args )
33
+ @new_state = new_state
34
+ end
35
+
36
+ attr_reader :new_state
37
+
38
+ def apply( stack )
39
+ stack.push( self.new_state.new )
40
+ return stack
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+ it "can be instantiated" do
47
+ result = subclass.new( :change_state, state_class )
48
+ expect( result ).to be_a( described_class )
49
+ expect( result.name ).to eq( :change_state )
50
+ end
51
+
52
+
53
+ it "requires a name to be instantiated" do
54
+ expect {
55
+ subclass.new
56
+ }.to raise_error( ArgumentError, /wrong number of arguments/i )
57
+ end
58
+
59
+
60
+ it "can alter the stack" do
61
+ stack = [ state_a, state_b ]
62
+ transition = subclass.new( :go_home, state_class )
63
+
64
+ result = transition.apply( stack )
65
+
66
+ expect( result ).to be_an( Array )
67
+ expect( result.length ).to eq( 3 )
68
+ expect( result.last ).to be_a( state_class )
69
+ end
70
+
71
+ end
72
+
73
+
74
+ describe 'incomplete concrete subclass' do
75
+
76
+ let( :subclass ) { Class.new(described_class) }
77
+
78
+
79
+ it "raises an error when applied to a stack" do
80
+ stack = [ state_a, state_b ]
81
+ transition = subclass.new( :change_state )
82
+
83
+ expect {
84
+ transition.apply( stack )
85
+ }.to raise_error( NotImplementedError, /apply/i )
86
+ end
87
+
88
+ end
89
+
90
+ end
91
+
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,8 @@ require 'rspec'
7
7
 
8
8
  require 'loggability/spechelpers'
9
9
 
10
+ require 'pushdown'
11
+
10
12
 
11
13
  ### Mock with RSpec
12
14
  RSpec.configure do |config|
@@ -23,6 +25,8 @@ RSpec.configure do |config|
23
25
  config.run_all_when_everything_filtered = true
24
26
  config.shared_context_metadata_behavior = :apply_to_host_groups
25
27
  # config.warnings = true
28
+
29
+ config.include( Loggability::SpecHelpers )
26
30
  end
27
31
 
28
32
 
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,15 +1,82 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.20210714190141
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2021-07-14 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIID+DCCAmCgAwIBAgIBAzANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
14
+ REM9RmFlcmllTVVEL0RDPW9yZzAeFw0yMDEyMjQyMDU1MjlaFw0yMTEyMjQyMDU1
15
+ MjlaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
16
+ hkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAvyVhkRzvlEs0fe7145BYLfN6njX9ih5H
17
+ L60U0p0euIurpv84op9CNKF9tx+1WKwyQvQP7qFGuZxkSUuWcP/sFhD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QddBmB+k8EicXyGNl4b5L4XpL7fIQu+Y96TB3JEJlShxFD9
34
+ k9FjI4d9EP54gS/4
35
+ -----END CERTIFICATE-----
36
+ date: 2021-08-27 00:00:00.000000000 Z
12
37
  dependencies:
38
+ - !ruby/object:Gem::Dependency
39
+ name: loggability
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '0.18'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: '0.18'
52
+ - !ruby/object:Gem::Dependency
53
+ name: pluggability
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '0.7'
59
+ type: :runtime
60
+ prerelease: false
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: '0.7'
66
+ - !ruby/object:Gem::Dependency
67
+ name: e2mmap
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.1'
73
+ type: :runtime
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.1'
13
80
  - !ruby/object:Gem::Dependency
14
81
  name: rake-deveiate
15
82
  requirement: !ruby/object:Gem::Requirement
@@ -32,22 +99,36 @@ executables: []
32
99
  extensions: []
33
100
  extra_rdoc_files: []
34
101
  files:
35
- - ".simplecov"
36
102
  - History.md
103
+ - LICENSE.txt
37
104
  - README.md
38
- - Rakefile
39
105
  - lib/pushdown.rb
106
+ - lib/pushdown/automaton.rb
107
+ - lib/pushdown/exceptions.rb
108
+ - lib/pushdown/state.rb
109
+ - lib/pushdown/transition.rb
110
+ - lib/pushdown/transition/pop.rb
111
+ - lib/pushdown/transition/push.rb
112
+ - lib/pushdown/transition/replace.rb
113
+ - lib/pushdown/transition/switch.rb
114
+ - spec/pushdown/automaton_spec.rb
115
+ - spec/pushdown/state_spec.rb
116
+ - spec/pushdown/transition/pop_spec.rb
117
+ - spec/pushdown/transition/push_spec.rb
118
+ - spec/pushdown/transition/replace_spec.rb
119
+ - spec/pushdown/transition/switch_spec.rb
120
+ - spec/pushdown/transition_spec.rb
40
121
  - spec/pushdown_spec.rb
41
122
  - spec/spec_helper.rb
42
123
  homepage: http://hg.sr.ht/~ged/Pushdown
43
124
  licenses:
44
125
  - BSD-3-Clause
45
126
  metadata:
46
- bug_tracker_uri: http://todo.sr.ht/~ged/Pushdown
47
- changelog_uri: http://deveiate.org/code/pushdown/History_md.html
48
- documentation_uri: http://deveiate.org/code/pushdown
49
127
  homepage_uri: http://hg.sr.ht/~ged/Pushdown
128
+ documentation_uri: http://deveiate.org/code/pushdown
129
+ changelog_uri: http://deveiate.org/code/pushdown/History_md.html
50
130
  source_uri: http://hg.sr.ht/~ged/Pushdown
131
+ bug_tracker_uri: http://todo.sr.ht/~ged/Pushdown
51
132
  post_install_message:
52
133
  rdoc_options: []
53
134
  require_paths:
@@ -59,9 +140,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
140
  version: '0'
60
141
  required_rubygems_version: !ruby/object:Gem::Requirement
61
142
  requirements:
62
- - - ">"
143
+ - - ">="
63
144
  - !ruby/object:Gem::Version
64
- version: 1.3.1
145
+ version: '0'
65
146
  requirements: []
66
147
  rubygems_version: 3.1.6
67
148
  signing_key: