nudge 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/VERSION +1 -1
  2. data/spec/instructions/bool/bool_duplicate_spec.rb +50 -0
  3. data/spec/instructions/bool/bool_from_float_spec.rb +41 -0
  4. data/spec/instructions/bool/bool_from_int_spec.rb +41 -0
  5. data/spec/instructions/bool/bool_pop_spec.rb +47 -0
  6. data/spec/instructions/bool/bool_rotate_spec.rb +60 -0
  7. data/spec/instructions/bool/bool_swap_spec.rb +64 -0
  8. data/spec/instructions/code/code_depth_spec.rb +39 -0
  9. data/spec/instructions/code/code_duplicate_spec.rb +50 -0
  10. data/spec/instructions/code/code_flush_spec.rb +37 -0
  11. data/spec/instructions/code/code_from_bool_spec.rb +37 -0
  12. data/spec/instructions/code/code_from_float_spec.rb +37 -0
  13. data/spec/instructions/code/code_from_int_spec.rb +37 -0
  14. data/spec/instructions/code/code_pop_spec.rb +47 -0
  15. data/spec/instructions/code/code_rotate_spec.rb +60 -0
  16. data/spec/instructions/code/code_swap_spec.rb +58 -0
  17. data/spec/instructions/float/float_duplicate_spec.rb +50 -0
  18. data/spec/instructions/float/float_from_bool_spec.rb +42 -0
  19. data/spec/instructions/float/float_from_int_spec.rb +37 -0
  20. data/spec/instructions/float/float_pop_spec.rb +47 -0
  21. data/spec/instructions/float/float_rotate_spec.rb +60 -0
  22. data/spec/instructions/float/float_swap_spec.rb +64 -0
  23. data/spec/instructions/int/int_duplicate_spec.rb +50 -0
  24. data/spec/instructions/int/int_from_bool_spec.rb +43 -0
  25. data/spec/instructions/int/int_from_float_spec.rb +37 -0
  26. data/spec/instructions/int/int_pop_spec.rb +47 -0
  27. data/spec/instructions/int/int_rotate_spec.rb +60 -0
  28. data/spec/instructions/int/int_swap_spec.rb +64 -0
  29. data/spec/instructions/name/name_duplicate_spec.rb +50 -0
  30. data/spec/instructions/name/name_pop_spec.rb +47 -0
  31. data/spec/instructions/name/name_rotate_spec.rb +60 -0
  32. data/spec/instructions/name/name_swap_spec.rb +58 -0
  33. data/spec/interpreter/interpreter_spec.rb +0 -2
  34. metadata +66 -16
  35. data/spec/instructions/code/code_stack_spec.rb +0 -386
  36. data/spec/instructions/split_these/bool_stack_spec.rb +0 -95
  37. data/spec/instructions/split_these/conversions_spec.rb +0 -103
  38. data/spec/instructions/split_these/float_stack_spec.rb +0 -92
  39. data/spec/instructions/split_these/int_stack_spec.rb +0 -81
  40. data/spec/instructions/split_these/name_stack_spec.rb +0 -84
  41. /data/spec/instructions/code/{code_fromname_spec.rb → code_from_name_spec.rb} +0 -0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -0,0 +1,50 @@
1
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
2
+ include Nudge
3
+
4
+
5
+ describe BoolDuplicateInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = BoolDuplicateInstruction.new(@context)
12
+ end
13
+
14
+
15
+ describe "\#go" do
16
+ before(:each) do
17
+ @i1 = BoolDuplicateInstruction.new(@context)
18
+ @bool1 = ValuePoint.new("bool", false)
19
+ end
20
+
21
+ describe "\#preconditions?" do
22
+ it "should check that there are enough parameters" do
23
+ 2.times {@context.stacks[:bool].push(@bool1)}
24
+ @i1.preconditions?.should == true
25
+ end
26
+
27
+ it "should raise an error if the preconditions aren't met" do
28
+ @context.clear_stacks # there are no params at all
29
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
30
+ end
31
+
32
+ it "should successfully run #go only if all preconditions are met" do
33
+ 3.times {@context.stacks[:bool].push(@bool1)}
34
+ @i1.should_receive(:cleanup)
35
+ @i1.go
36
+ end
37
+ end
38
+
39
+
40
+ describe "\#cleanup" do
41
+ it "should swap the top two values" do
42
+ @context.push(:bool,"false")
43
+ @i1.go
44
+ @context.depth(:bool).should == 2
45
+ @context.pop_value(:bool).should == false
46
+ @context.pop_value(:bool).should == false
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ #encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
3
+ include Nudge
4
+
5
+ describe BoolFromFloatInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = BoolFromFloatInstruction.new(@context)
12
+ @context.clear_stacks
13
+ end
14
+
15
+ it "should check that there are enough parameters" do
16
+ @context.push(:float, "1.2")
17
+ @i1.preconditions?.should == true
18
+ end
19
+
20
+ it "should raise an error if the preconditions aren't met" do
21
+ @context.clear_stacks # there are no params at all
22
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
23
+ end
24
+
25
+ it "should successfully run #go only if all preconditions are met" do
26
+ @context.push(:float, "-91.0")
27
+ @i1.should_receive(:cleanup)
28
+ @i1.go
29
+ end
30
+
31
+ it "should create and push the new (expected) value to the right place" do
32
+ @context.push(:float, "0.0")
33
+ @i1.go
34
+ @context.depth(:bool).should == 1
35
+ @context.peek_value(:bool).should == false
36
+
37
+ @context.push(:float, "1.0")
38
+ @i1.go
39
+ @context.peek_value(:bool).should == true
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ #encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
3
+ include Nudge
4
+
5
+ describe BoolFromIntInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = BoolFromIntInstruction.new(@context)
12
+ @context.clear_stacks
13
+ end
14
+
15
+ it "should check that there are enough parameters" do
16
+ @context.push(:int, "12")
17
+ @i1.preconditions?.should == true
18
+ end
19
+
20
+ it "should raise an error if the preconditions aren't met" do
21
+ @context.clear_stacks # there are no params at all
22
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
23
+ end
24
+
25
+ it "should successfully run #go only if all preconditions are met" do
26
+ @context.push(:int, "-91")
27
+ @i1.should_receive(:cleanup)
28
+ @i1.go
29
+ end
30
+
31
+ it "should create and push the new (expected) value to the right place" do
32
+ @context.push(:int, "0")
33
+ @i1.go
34
+ @context.depth(:bool).should == 1
35
+ @context.peek_value(:bool).should == false
36
+
37
+ @context.push(:int, "1912")
38
+ @i1.go
39
+ @context.peek_value(:bool).should == true
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
2
+ include Nudge
3
+
4
+ describe BoolPopInstruction do
5
+
6
+ it_should_behave_like "every Nudge Instruction"
7
+
8
+ before(:each) do
9
+ @context = Interpreter.new
10
+ @i1 = BoolPopInstruction.new(@context)
11
+ end
12
+
13
+
14
+ describe "\#go" do
15
+ before(:each) do
16
+ @i1 = BoolPopInstruction.new(@context)
17
+ @bool1 = ValuePoint.new("bool", false)
18
+ end
19
+
20
+ describe "\#preconditions?" do
21
+ it "should check that there are enough parameters" do
22
+ 2.times {@context.stacks[:bool].push(@bool1)}
23
+ @i1.preconditions?.should == true
24
+ end
25
+
26
+ it "should raise an error if the preconditions aren't met" do
27
+ @context.clear_stacks # there are no params at all
28
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
29
+ end
30
+
31
+ it "should successfully run #go only if all preconditions are met" do
32
+ 3.times {@context.stacks[:bool].push(@bool1)}
33
+ @i1.should_receive(:cleanup)
34
+ @i1.go
35
+ end
36
+ end
37
+
38
+ describe "\#derive" do
39
+ it "should pop one item" do
40
+ 2.times {@context.stacks[:bool].push(@bool1)}
41
+ @i1.go
42
+ @context.stacks[:bool].depth.should == 1
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
2
+ include Nudge
3
+
4
+
5
+ describe BoolRotateInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = BoolRotateInstruction.new(@context)
12
+ end
13
+
14
+
15
+ describe "\#go" do
16
+ before(:each) do
17
+ @i1 = BoolRotateInstruction.new(@context)
18
+ @bool1 = ValuePoint.new("bool", false)
19
+ end
20
+
21
+ describe "\#preconditions?" do
22
+ it "should check that there are enough parameters" do
23
+ 3.times {@context.stacks[:bool].push(@bool1)}
24
+ @i1.preconditions?.should == true
25
+ end
26
+
27
+ it "should raise an error if the preconditions aren't met" do
28
+ @context.clear_stacks # there are no params at all
29
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
30
+ end
31
+
32
+ it "should successfully run #go only if all preconditions are met" do
33
+ 3.times {@context.stacks[:bool].push(@bool1)}
34
+ @i1.should_receive(:cleanup)
35
+ @i1.go
36
+ end
37
+ end
38
+
39
+ describe "\#derive" do
40
+ it "should pop all the arguments" do
41
+ 3.times {@context.stacks[:bool].push(@bool1)}
42
+ @i1.stub!(:cleanup) # and do nothing
43
+ @i1.go
44
+ @context.stacks[:bool].depth.should == 0
45
+ end
46
+ end
47
+
48
+ describe "\#cleanup" do
49
+ it "should move around the top three values" do
50
+ @context.push(:bool,"true")
51
+ @context.push(:bool,"true")
52
+ @context.push(:bool,"false")
53
+ @i1.go
54
+ @context.pop_value(:bool).should == true
55
+ @context.pop_value(:bool).should == false
56
+ @context.pop_value(:bool).should == true
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,64 @@
1
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
2
+ include Nudge
3
+
4
+
5
+ describe BoolSwapInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = BoolSwapInstruction.new(@context)
12
+ end
13
+
14
+
15
+ describe "\#go" do
16
+ before(:each) do
17
+ @i1 = BoolSwapInstruction.new(@context)
18
+ @bool1 = ValuePoint.new("bool", false)
19
+ end
20
+
21
+ describe "\#preconditions?" do
22
+ it "should check that there are enough parameters" do
23
+ 2.times {@context.stacks[:bool].push(@bool1)}
24
+ @i1.preconditions?.should == true
25
+ end
26
+
27
+ it "should raise an error if the preconditions aren't met" do
28
+ @context.clear_stacks # there are no params at all
29
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
30
+ end
31
+
32
+ it "should successfully run #go only if all preconditions are met" do
33
+ 3.times {@context.stacks[:bool].push(@bool1)}
34
+ @i1.should_receive(:cleanup)
35
+ @i1.go
36
+ end
37
+ end
38
+
39
+ describe "\#derive" do
40
+ it "should pop all the arguments" do
41
+ 2.times {@context.stacks[:bool].push(@bool1)}
42
+ @i1.stub!(:cleanup) # and do nothing
43
+ @i1.go
44
+ @context.stacks[:bool].depth.should == 0
45
+ end
46
+ end
47
+
48
+ describe "\#cleanup" do
49
+ it "should swap the top two values" do
50
+ @context.push(:bool,"false")
51
+ @context.push(:bool,"true")
52
+ @i1.go
53
+ @context.pop_value(:bool).should == false
54
+ @context.pop_value(:bool).should == true
55
+
56
+ @context.push(:bool,"true")
57
+ @context.push(:bool,"false")
58
+ @i1.go
59
+ @context.pop_value(:bool).should == true
60
+ @context.pop_value(:bool).should == false
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
2
+ include Nudge
3
+
4
+
5
+ describe CodeDepthInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = CodeDepthInstruction.new(@context)
12
+ end
13
+
14
+
15
+ describe "\#go" do
16
+ before(:each) do
17
+ @i1 = CodeDepthInstruction.new(@context)
18
+ @context.clear_stacks
19
+ @code1 = ValuePoint.new("code", "do nothing")
20
+ end
21
+
22
+ describe "\#preconditions?" do
23
+ it "should check that the :code stack responds to #depth" do
24
+ @i1.preconditions?.should == true
25
+ end
26
+ end
27
+
28
+ describe "\#cleanup" do
29
+ it "should count the items on the stack and push it onto the :int stack" do
30
+ @context.stacks[:int].depth.should == 0
31
+ @i1.go
32
+ @context.stacks[:int].peek.value.should == 0
33
+ 7.times {@context.stacks[:code].push @code1}
34
+ @i1.go
35
+ @context.stacks[:int].peek.value.should == 7
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
2
+ include Nudge
3
+
4
+
5
+ describe CodeDuplicateInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = CodeDuplicateInstruction.new(@context)
12
+ end
13
+
14
+
15
+ describe "\#go" do
16
+ before(:each) do
17
+ @i1 = CodeDuplicateInstruction.new(@context)
18
+ @code1 = ValuePoint.new("code", "do a")
19
+ end
20
+
21
+ describe "\#preconditions?" do
22
+ it "should check that there are enough parameters" do
23
+ 2.times {@context.stacks[:code].push(@code1)}
24
+ @i1.preconditions?.should == true
25
+ end
26
+
27
+ it "should raise an error if the preconditions aren't met" do
28
+ @context.clear_stacks # there are no params at all
29
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
30
+ end
31
+
32
+ it "should successfully run #go only if all preconditions are met" do
33
+ 3.times {@context.stacks[:code].push(@code1)}
34
+ @i1.should_receive(:cleanup)
35
+ @i1.go
36
+ end
37
+ end
38
+
39
+
40
+ describe "\#cleanup" do
41
+ it "should swap the top two values" do
42
+ @context.push(:code,"do x")
43
+ @i1.go
44
+ @context.depth(:code).should == 2
45
+ @context.pop_value(:code).should == "do x"
46
+ @context.pop_value(:code).should == "do x"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
2
+ include Nudge
3
+
4
+
5
+ describe CodeFlushInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = CodeFlushInstruction.new(@context)
12
+ end
13
+
14
+
15
+ describe "\#go" do
16
+ before(:each) do
17
+ @i1 = CodeFlushInstruction.new(@context)
18
+ @context.clear_stacks
19
+ @code1 = ValuePoint.new("code", "do x")
20
+ end
21
+
22
+ describe "\#preconditions?" do
23
+ it "should check that the :int stack responds to #depth" do
24
+ @i1.preconditions?.should == true
25
+ end
26
+ end
27
+
28
+ describe "\#cleanup" do
29
+ it "should remove all items on the stack" do
30
+ 11.times {@context.stacks[:code].push(@code1)}
31
+ @context.stacks[:code].depth.should == 11
32
+ @i1.go
33
+ @context.stacks[:code].depth.should == 0
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ #encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
3
+ include Nudge
4
+
5
+ describe CodeFromBoolInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = CodeFromBoolInstruction.new(@context)
12
+ @context.clear_stacks
13
+ end
14
+
15
+ it "should check that there are enough parameters" do
16
+ @context.push(:bool, "false")
17
+ @i1.preconditions?.should == true
18
+ end
19
+
20
+ it "should raise an error if the preconditions aren't met" do
21
+ @context.clear_stacks # there are no params at all
22
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
23
+ end
24
+
25
+ it "should successfully run #go only if all preconditions are met" do
26
+ @context.push(:bool, "true")
27
+ @i1.should_receive(:cleanup)
28
+ @i1.go
29
+ end
30
+
31
+ it "should create and push the new (expected) value to the right place" do
32
+ @context.push(:bool, "false")
33
+ @i1.go
34
+ @context.depth(:code).should == 1
35
+ @context.peek_value(:code).should == "value «bool»\n«bool» false"
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ #encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
3
+ include Nudge
4
+
5
+ describe CodeFromFloatInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = CodeFromFloatInstruction.new(@context)
12
+ @context.clear_stacks
13
+ end
14
+
15
+ it "should check that there are enough parameters" do
16
+ @context.push(:float, "1.2")
17
+ @i1.preconditions?.should == true
18
+ end
19
+
20
+ it "should raise an error if the preconditions aren't met" do
21
+ @context.clear_stacks # there are no params at all
22
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
23
+ end
24
+
25
+ it "should successfully run #go only if all preconditions are met" do
26
+ @context.push(:float, "-91.0")
27
+ @i1.should_receive(:cleanup)
28
+ @i1.go
29
+ end
30
+
31
+ it "should create and push the new (expected) value to the right place" do
32
+ @context.push(:float, "0.0")
33
+ @i1.go
34
+ @context.depth(:code).should == 1
35
+ @context.peek_value(:code).should == "value «float»\n«float» 0.0"
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ #encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
3
+ include Nudge
4
+
5
+ describe CodeFromIntInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = CodeFromIntInstruction.new(@context)
12
+ @context.clear_stacks
13
+ end
14
+
15
+ it "should check that there are enough parameters" do
16
+ @context.push(:int, "99")
17
+ @i1.preconditions?.should == true
18
+ end
19
+
20
+ it "should raise an error if the preconditions aren't met" do
21
+ @context.clear_stacks # there are no params at all
22
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
23
+ end
24
+
25
+ it "should successfully run #go only if all preconditions are met" do
26
+ @context.push(:int, "-91")
27
+ @i1.should_receive(:cleanup)
28
+ @i1.go
29
+ end
30
+
31
+ it "should create and push the new (expected) value to the right place" do
32
+ @context.push(:int, "-718")
33
+ @i1.go
34
+ @context.depth(:code).should == 1
35
+ @context.peek_value(:code).should == "value «int»\n«int» -718"
36
+ end
37
+ end
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
2
+ include Nudge
3
+
4
+ describe CodePopInstruction do
5
+
6
+ it_should_behave_like "every Nudge Instruction"
7
+
8
+ before(:each) do
9
+ @context = Interpreter.new
10
+ @i1 = CodePopInstruction.new(@context)
11
+ end
12
+
13
+
14
+ describe "\#go" do
15
+ before(:each) do
16
+ @i1 = CodePopInstruction.new(@context)
17
+ @code1 = ValuePoint.new("code", "block {}")
18
+ end
19
+
20
+ describe "\#preconditions?" do
21
+ it "should check that there are enough parameters" do
22
+ 2.times {@context.stacks[:code].push(@code1)}
23
+ @i1.preconditions?.should == true
24
+ end
25
+
26
+ it "should raise an error if the preconditions aren't met" do
27
+ @context.clear_stacks # there are no params at all
28
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
29
+ end
30
+
31
+ it "should successfully run #go only if all preconditions are met" do
32
+ 3.times {@context.stacks[:code].push(@code1)}
33
+ @i1.should_receive(:cleanup)
34
+ @i1.go
35
+ end
36
+ end
37
+
38
+ describe "\#derive" do
39
+ it "should pop one item" do
40
+ 2.times {@context.stacks[:code].push(@code1)}
41
+ @i1.go
42
+ @context.stacks[:code].depth.should == 1
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), "../../spec_helper")
2
+ include Nudge
3
+
4
+
5
+ describe CodeRotateInstruction do
6
+
7
+ it_should_behave_like "every Nudge Instruction"
8
+
9
+ before(:each) do
10
+ @context = Interpreter.new
11
+ @i1 = CodeRotateInstruction.new(@context)
12
+ end
13
+
14
+
15
+ describe "\#go" do
16
+ before(:each) do
17
+ @i1 = CodeRotateInstruction.new(@context)
18
+ @code1 = ValuePoint.new("code", "ref a")
19
+ end
20
+
21
+ describe "\#preconditions?" do
22
+ it "should check that there are enough parameters" do
23
+ 3.times {@context.stacks[:code].push(@code1)}
24
+ @i1.preconditions?.should == true
25
+ end
26
+
27
+ it "should raise an error if the preconditions aren't met" do
28
+ @context.clear_stacks # there are no params at all
29
+ lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
30
+ end
31
+
32
+ it "should successfully run #go only if all preconditions are met" do
33
+ 3.times {@context.stacks[:code].push(@code1)}
34
+ @i1.should_receive(:cleanup)
35
+ @i1.go
36
+ end
37
+ end
38
+
39
+ describe "\#derive" do
40
+ it "should pop all the arguments" do
41
+ 3.times {@context.stacks[:code].push(@code1)}
42
+ @i1.stub!(:cleanup) # and do nothing
43
+ @i1.go
44
+ @context.stacks[:code].depth.should == 0
45
+ end
46
+ end
47
+
48
+ describe "\#cleanup" do
49
+ it "should move around the top three values" do
50
+ @context.push(:code,"ref c")
51
+ @context.push(:code,"ref b")
52
+ @context.push(:code,"ref a")
53
+ @i1.go
54
+ @context.pop_value(:code).should == "ref c"
55
+ @context.pop_value(:code).should == "ref a"
56
+ @context.pop_value(:code).should == "ref b"
57
+ end
58
+ end
59
+ end
60
+ end