gobstones 0.0.1.1 → 0.0.2

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.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -3
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG +22 -2
  6. data/Gemfile +3 -3
  7. data/Gemfile.lock +32 -27
  8. data/bin/gobstones +1 -1
  9. data/examples/.gitkeep +0 -0
  10. data/gobstones.gemspec +2 -2
  11. data/lib/gobstones/cli/board_template +1 -1
  12. data/lib/gobstones/cli/printer.rb +1 -1
  13. data/lib/gobstones/cli/runner.rb +8 -2
  14. data/lib/gobstones/extensions/all.rb +2 -1
  15. data/lib/gobstones/extensions/boolean.rb +1 -1
  16. data/lib/gobstones/extensions/fixnum.rb +1 -1
  17. data/lib/gobstones/extensions/string.rb +9 -0
  18. data/lib/gobstones/lang/all.rb +1 -1
  19. data/lib/gobstones/lang/commands/all.rb +3 -2
  20. data/lib/gobstones/lang/commands/boom_cmd.rb +6 -3
  21. data/lib/gobstones/lang/commands/command_block.rb +1 -1
  22. data/lib/gobstones/lang/commands/conditional_cmd.rb +5 -1
  23. data/lib/gobstones/lang/commands/ir_al_origen_cmd.rb +1 -1
  24. data/lib/gobstones/lang/commands/mover_cmd.rb +4 -2
  25. data/lib/gobstones/lang/commands/multiple_assignment.rb +35 -0
  26. data/lib/gobstones/lang/commands/poner_cmd.rb +8 -4
  27. data/lib/gobstones/lang/commands/procedure_call.rb +1 -9
  28. data/lib/gobstones/lang/commands/repeat_with_cmd.rb +10 -6
  29. data/lib/gobstones/lang/commands/sacar_cmd.rb +9 -7
  30. data/lib/gobstones/lang/commands/{assignments.rb → single_assignment.rb} +5 -3
  31. data/lib/gobstones/lang/commands/skip_cmd.rb +2 -2
  32. data/lib/gobstones/lang/commands/vaciar_tablero_cmd.rb +1 -1
  33. data/lib/gobstones/lang/commands/while_cmd.rb +1 -1
  34. data/lib/gobstones/lang/definitions/all.rb +1 -1
  35. data/lib/gobstones/lang/definitions/definition.rb +47 -5
  36. data/lib/gobstones/lang/definitions/definition_call.rb +17 -5
  37. data/lib/gobstones/lang/definitions/function.rb +9 -0
  38. data/lib/gobstones/lang/definitions/main.rb +1 -1
  39. data/lib/gobstones/lang/definitions/no_return_statement.rb +7 -3
  40. data/lib/gobstones/lang/definitions/procedure.rb +5 -20
  41. data/lib/gobstones/lang/definitions/return_from_function.rb +12 -2
  42. data/lib/gobstones/lang/definitions/return_from_main.rb +5 -1
  43. data/lib/gobstones/lang/definitions/var_tuple.rb +13 -1
  44. data/lib/gobstones/lang/expressions/all.rb +1 -1
  45. data/lib/gobstones/lang/expressions/arithmetic_expressions.rb +1 -1
  46. data/lib/gobstones/lang/expressions/boolean_expressions.rb +3 -2
  47. data/lib/gobstones/lang/expressions/enclosed_by_parens_expression.rb +17 -0
  48. data/lib/gobstones/lang/expressions/function_call.rb +1 -1
  49. data/lib/gobstones/lang/expressions/one_arg_expression.rb +16 -4
  50. data/lib/gobstones/lang/expressions/primitive_functions.rb +18 -12
  51. data/lib/gobstones/lang/expressions/two_arg_expression.rb +7 -3
  52. data/lib/gobstones/lang/expressions/type_bound_functions.rb +1 -1
  53. data/lib/gobstones/lang/expressions/var_name.rb +9 -3
  54. data/lib/gobstones/lang/literals/all.rb +1 -1
  55. data/lib/gobstones/lang/literals/colors.rb +1 -1
  56. data/lib/gobstones/lang/literals/literal.rb +31 -21
  57. data/lib/gobstones/lang/literals/number.rb +1 -1
  58. data/lib/gobstones/lang/program.rb +13 -4
  59. data/lib/gobstones/modules/equal_by_class.rb +1 -1
  60. data/lib/gobstones/parser/ast/ast.rb +12 -8
  61. data/lib/gobstones/parser/grammar/gobstones.treetop +4 -4
  62. data/lib/gobstones/parser/parse_error.rb +1 -1
  63. data/lib/gobstones/runner/all.rb +1 -2
  64. data/lib/gobstones/runner/board.rb +13 -4
  65. data/lib/gobstones/runner/cell.rb +10 -0
  66. data/lib/gobstones/runner/errors/all.rb +1 -1
  67. data/lib/gobstones/runner/errors/definition_not_found_error.rb +1 -1
  68. data/lib/gobstones/runner/execution_context.rb +66 -16
  69. data/lib/gobstones/runner/head.rb +17 -3
  70. data/spec/gobstones_lang_test_objects.rb +75 -0
  71. data/spec/lang/commands/boom_cmd_spec.rb +3 -3
  72. data/spec/lang/commands/cmd_block_spec.rb +14 -14
  73. data/spec/lang/commands/if_cmd_spec.rb +21 -20
  74. data/spec/lang/commands/ir_al_origen_cmd_spec.rb +3 -3
  75. data/spec/lang/commands/mover_cmd_spec.rb +12 -14
  76. data/spec/lang/commands/multiple_assignment_spec.rb +37 -0
  77. data/spec/lang/commands/poner_cmd_spec.rb +13 -14
  78. data/spec/lang/commands/procedure_call_spec.rb +19 -24
  79. data/spec/lang/commands/procedure_spec.rb +32 -36
  80. data/spec/lang/commands/repeat_with_cmd_spec.rb +39 -20
  81. data/spec/lang/commands/sacar_cmd_spec.rb +17 -16
  82. data/spec/lang/commands/single_assignment_spec.rb +13 -0
  83. data/spec/lang/commands/skip_cmd_spec.rb +2 -2
  84. data/spec/lang/commands/vaciar_tablero_cmd_spec.rb +7 -6
  85. data/spec/lang/commands/while_cmd_spec.rb +21 -15
  86. data/spec/lang/definitions/no_return_statement_spec.rb +10 -0
  87. data/spec/lang/definitions/var_tuple_spec.rb +16 -0
  88. data/spec/lang/expressions/arithmetic_expressions_spec.rb +15 -15
  89. data/spec/lang/expressions/boolean_expressions_spec.rb +35 -25
  90. data/spec/lang/expressions/comparison_expressions_spec.rb +25 -28
  91. data/spec/lang/expressions/enclosed_by_parens_expression_spec.rb +11 -0
  92. data/spec/lang/expressions/function_call_spec.rb +29 -0
  93. data/spec/lang/expressions/primitive_functions_spec.rb +60 -62
  94. data/spec/lang/expressions/type_bound_functions_spec.rb +13 -13
  95. data/spec/lang/expressions/var_name_spec.rb +20 -8
  96. data/spec/lang/literals/booleans_spec.rb +5 -7
  97. data/spec/lang/literals/colors_spec.rb +4 -4
  98. data/spec/lang/literals/directions_spec.rb +12 -12
  99. data/spec/lang/literals/numbers_spec.rb +2 -2
  100. data/spec/matchers/parse_matcher.rb +9 -10
  101. data/spec/parser/arithmetic_expressions_spec.rb +19 -19
  102. data/spec/parser/assignments_spec.rb +24 -10
  103. data/spec/parser/boolean_expressions_spec.rb +18 -18
  104. data/spec/parser/command_block_spec.rb +17 -19
  105. data/spec/parser/data_types_spec.rb +23 -23
  106. data/spec/parser/function_calls_spec.rb +13 -12
  107. data/spec/parser/function_definitions_spec.rb +13 -18
  108. data/spec/parser/gobstones_program_spec.rb +15 -15
  109. data/spec/parser/if_command_spec.rb +13 -12
  110. data/spec/parser/main_definition_spec.rb +12 -12
  111. data/spec/parser/nested_expressions_spec.rb +16 -20
  112. data/spec/parser/primitive_expressions_spec.rb +27 -33
  113. data/spec/parser/procedure_calls_spec.rb +12 -12
  114. data/spec/parser/procedure_definitions_spec.rb +10 -16
  115. data/spec/parser/repeat_with_command_spec.rb +7 -10
  116. data/spec/parser/simple_commands_spec.rb +10 -10
  117. data/spec/parser/treetop_parser_spec.rb +11 -10
  118. data/spec/parser/var_tuple_spec.rb +7 -11
  119. data/spec/parser/while_command_spec.rb +9 -9
  120. data/spec/runner/board_spec.rb +23 -27
  121. data/spec/runner/cell_spec.rb +34 -38
  122. data/spec/runner/execution_context_spec.rb +38 -24
  123. data/spec/runner/head_spec.rb +54 -63
  124. data/spec/spec_helper.rb +4 -1
  125. data/spec/type_checker_spec.rb +13 -13
  126. metadata +33 -18
  127. data/lib/gobstones/lang/expressions/parentheses_expression.rb +0 -13
  128. data/spec/lang/commands/assignments_spec.rb +0 -13
@@ -0,0 +1,11 @@
1
+ describe EnclosedByParensExpression do
2
+
3
+ let(:context) { clean_context }
4
+
5
+ it "evaluates the inner expression" do
6
+ expression = EnclosedByParensExpression.new rojo
7
+
8
+ expect(expression.evaluate(context)).to eq(rojo)
9
+ end
10
+
11
+ end
@@ -0,0 +1,29 @@
1
+ describe FunctionCall do
2
+
3
+ it "evaluates an existing function and returns its result when calling it" do
4
+ return_statement = ReturnFromFunction.new [42.to_gbs_num]
5
+ my_function = Function.new 'myFunction', no_arguments, empty_body, return_statement
6
+ program = Program.new [my_function], no_return_statement
7
+ context = program_context_for program
8
+ call = FunctionCall.new 'myFunction', []
9
+
10
+ result = call.evaluate context
11
+
12
+ expect(result).to eq(42.to_gbs_num)
13
+ end
14
+
15
+ it "evaluates an existing function with some arguments" do
16
+ number_a, number_b, number_c = 'a'.to_var_name, 'b'.to_var_name, 'c'.to_var_name
17
+ return_statement = ReturnFromFunction.new [Add.new(Add.new(number_a, number_b), number_c)]
18
+ args = VarTuple.new [number_a, number_b, number_c]
19
+ my_function = Function.new 'myFunction', args, empty_body, return_statement
20
+ program = Program.new [my_function], no_return_statement
21
+ context = program_context_for program
22
+ call = FunctionCall.new 'myFunction', [1.to_gbs_num, 2.to_gbs_num, 3.to_gbs_num]
23
+
24
+ result = call.evaluate context
25
+
26
+ expect(result).to eq(6.to_gbs_num)
27
+ end
28
+
29
+ end
@@ -1,126 +1,124 @@
1
1
  describe "primitive functions" do
2
2
 
3
- let(:context) { ProgramExecutionContext.for double('GobstonesProgram') }
4
- let(:black) { Negro.new }
5
- let(:west) { Oeste.new }
3
+ let(:context) { clean_context }
6
4
 
7
5
  describe "nroBolitas() function" do
8
6
 
9
- it "should evaluates correctly in a clean context" do
10
- expect(NroBolitas.new(black).evaluate(context)).to eq(0.to_gbs_num)
7
+ it "evaluates correctly in a clean context" do
8
+ expect(NroBolitas.new(negro).evaluate(context)).to eq(0.to_gbs_num)
11
9
  end
12
10
 
13
- it "should evaluate correctly in a context with some data" do
14
- 5.times { context.head.put black }
15
- expect(NroBolitas.new(black).evaluate(context)).to eq(5.to_gbs_num)
11
+ it "evaluates correctly in a context with some data" do
12
+ 5.times { context.head.put negro }
13
+ expect(NroBolitas.new(negro).evaluate(context)).to eq(5.to_gbs_num)
16
14
  end
17
15
 
18
16
  end
19
17
 
20
18
  describe "hayBolitas() function" do
21
19
 
22
- it "should evaluate correctly in a clean context" do
23
- expect(HayBolitas.new(black).evaluate(context)).to eq(false.to_gbs_bool)
20
+ it "evaluates correctly in a clean context" do
21
+ expect(HayBolitas.new(negro).evaluate(context)).to eq(false_value)
24
22
  end
25
23
 
26
- it "should evaluate correctly in a context with some data" do
27
- context.head.put black
28
- expect(HayBolitas.new(black).evaluate(context)).to eq(true.to_gbs_bool)
24
+ it "evaluates correctly in a context with some data" do
25
+ context.head.put negro
26
+ expect(HayBolitas.new(negro).evaluate(context)).to eq(true_value)
29
27
  end
30
28
 
31
29
  end
32
30
 
33
31
  describe "puedeMover() function" do
34
32
 
35
- it "should evaluate correctly in a clean context" do
36
- expect(PuedeMover.new(west).evaluate(context)).to eq(false.to_gbs_bool)
33
+ it "evaluates correctly in a clean context" do
34
+ expect(PuedeMover.new(oeste).evaluate(context)).to eq(false_value)
37
35
  end
38
36
 
39
- it "should evaluate correctly in a modified context" do
40
- context.head.move(Este.new)
41
- expect(PuedeMover.new(west).evaluate(context)).to eq(true.to_gbs_bool)
37
+ it "evaluates correctly in a modified context" do
38
+ context.head.move(este)
39
+ expect(PuedeMover.new(oeste).evaluate(context)).to eq(true_value)
42
40
  end
43
41
 
44
42
  end
45
43
 
46
44
  describe "siguiente() function" do
47
45
 
48
- it "should evaluate correctly for numbers" do
49
- expect(Siguiente.new(15.to_gbs_num).evaluate).to eq(16.to_gbs_num)
46
+ it "evaluates correctly for numbers" do
47
+ expect(Siguiente.new(15.to_gbs_num).evaluate(context)).to eq(16.to_gbs_num)
50
48
  end
51
49
 
52
- it "should evaluate correctly for colors" do
53
- expect(Siguiente.new(Azul.new).evaluate).to eq(Negro.new)
54
- expect(Siguiente.new(Negro.new).evaluate).to eq(Rojo.new)
55
- expect(Siguiente.new(Rojo.new).evaluate).to eq(Verde.new)
56
- expect(Siguiente.new(Verde.new).evaluate).to eq(Azul.new)
50
+ it "evaluates correctly for colors" do
51
+ expect(Siguiente.new(azul).evaluate(context)).to eq(negro)
52
+ expect(Siguiente.new(negro).evaluate(context)).to eq(rojo)
53
+ expect(Siguiente.new(rojo).evaluate(context)).to eq(verde)
54
+ expect(Siguiente.new(verde).evaluate(context)).to eq(azul)
57
55
  end
58
56
 
59
- it "should evaluate correctly for directions" do
60
- expect(Siguiente.new(Norte.new).evaluate).to eq(Este.new)
61
- expect(Siguiente.new(Este.new).evaluate).to eq(Sur.new)
62
- expect(Siguiente.new(Sur.new).evaluate).to eq(Oeste.new)
63
- expect(Siguiente.new(Oeste.new).evaluate).to eq(Norte.new)
57
+ it "evaluates correctly for directions" do
58
+ expect(Siguiente.new(norte).evaluate(context)).to eq(este)
59
+ expect(Siguiente.new(este).evaluate(context)).to eq(sur)
60
+ expect(Siguiente.new(sur).evaluate(context)).to eq(oeste)
61
+ expect(Siguiente.new(oeste).evaluate(context)).to eq(norte)
64
62
  end
65
63
 
66
- it "should evaluate correctly for booleans" do
67
- expect(Siguiente.new(True.new).evaluate).to eq(False.new)
68
- expect(Siguiente.new(False.new).evaluate).to eq(True.new)
64
+ it "evaluates correctly for booleans" do
65
+ expect(Siguiente.new(true_value).evaluate(context)).to eq(false_value)
66
+ expect(Siguiente.new(false_value).evaluate(context)).to eq(true_value)
69
67
  end
70
68
 
71
69
  end
72
70
 
73
71
  describe "previo() function" do
74
72
 
75
- it "should evaluate correctly for numbers" do
76
- expect(Previo.new(43.to_gbs_num).evaluate).to eq(42.to_gbs_num)
73
+ it "evaluates correctly for numbers" do
74
+ expect(Previo.new(43.to_gbs_num).evaluate(context)).to eq(42.to_gbs_num)
77
75
  end
78
76
 
79
- it "should evaluate correctly for colors" do
80
- expect(Previo.new(Azul.new).evaluate).to eq(Verde.new)
81
- expect(Previo.new(Negro.new).evaluate).to eq(Azul.new)
82
- expect(Previo.new(Rojo.new).evaluate).to eq(Negro.new)
83
- expect(Previo.new(Verde.new).evaluate).to eq(Rojo.new)
77
+ it "evaluates correctly for colors" do
78
+ expect(Previo.new(azul).evaluate(context)).to eq(verde)
79
+ expect(Previo.new(negro).evaluate(context)).to eq(azul)
80
+ expect(Previo.new(rojo).evaluate(context)).to eq(negro)
81
+ expect(Previo.new(verde).evaluate(context)).to eq(rojo)
84
82
  end
85
83
 
86
- it "should evaluate correctly for directions" do
87
- expect(Previo.new(Norte.new).evaluate).to eq(Oeste.new)
88
- expect(Previo.new(Este.new).evaluate).to eq(Norte.new)
89
- expect(Previo.new(Sur.new).evaluate).to eq(Este.new)
90
- expect(Previo.new(Oeste.new).evaluate).to eq(Sur.new)
84
+ it "evaluates correctly for directions" do
85
+ expect(Previo.new(norte).evaluate(context)).to eq(oeste)
86
+ expect(Previo.new(este).evaluate(context)).to eq(norte)
87
+ expect(Previo.new(sur).evaluate(context)).to eq(este)
88
+ expect(Previo.new(oeste).evaluate(context)).to eq(sur)
91
89
  end
92
90
 
93
- it "should evaluate correctly for booleans" do
94
- expect(Previo.new(True.new).evaluate).to eq(False.new)
95
- expect(Previo.new(False.new).evaluate).to eq(True.new)
91
+ it "evaluates correctly for booleans" do
92
+ expect(Previo.new(true_value).evaluate(context)).to eq(false_value)
93
+ expect(Previo.new(false_value).evaluate(context)).to eq(true_value)
96
94
  end
97
95
 
98
96
  end
99
97
 
100
98
  describe "opuesto() function" do
101
99
 
102
- it "should evaluate correctly for numbers" do
103
- expect(Opuesto.new(23.to_gbs_num).evaluate).to eq(-23.to_gbs_num)
104
- expect(Opuesto.new(-42.to_gbs_num).evaluate).to eq(42.to_gbs_num)
100
+ it "evaluates correctly for numbers" do
101
+ expect(Opuesto.new(23.to_gbs_num).evaluate(context)).to eq(-23.to_gbs_num)
102
+ expect(Opuesto.new(-42.to_gbs_num).evaluate(context)).to eq(42.to_gbs_num)
105
103
  end
106
104
 
107
- it "should evaluate correctly for directions" do
108
- expect(Opuesto.new(Norte.new).evaluate).to eq(Sur.new)
109
- expect(Opuesto.new(Este.new).evaluate).to eq(Oeste.new)
110
- expect(Opuesto.new(Sur.new).evaluate).to eq(Norte.new)
111
- expect(Opuesto.new(Oeste.new).evaluate).to eq(Este.new)
105
+ it "evaluates correctly for directions" do
106
+ expect(Opuesto.new(norte).evaluate(context)).to eq(sur)
107
+ expect(Opuesto.new(este).evaluate(context)).to eq(oeste)
108
+ expect(Opuesto.new(sur).evaluate(context)).to eq(norte)
109
+ expect(Opuesto.new(oeste).evaluate(context)).to eq(este)
112
110
  end
113
111
 
114
- it "should evaluate correctly for booleans" do
115
- expect(Opuesto.new(True.new).evaluate).to eq(False.new)
116
- expect(Opuesto.new(False.new).evaluate).to eq(True.new)
112
+ it "evaluates correctly for booleans" do
113
+ expect(Opuesto.new(true_value).evaluate(context)).to eq(false_value)
114
+ expect(Opuesto.new(false_value).evaluate(context)).to eq(true_value)
117
115
  end
118
116
 
119
- it "should fail when evaluating for colors" do
120
- expect { Opuesto.new(Verde.new).evaluate }.
117
+ it "fails when evaluating for colors" do
118
+ expect { Opuesto.new(verde).evaluate(context) }.
121
119
  to raise_error(GobstonesTypeError, "colors don't have opposite")
122
120
  end
123
121
 
124
122
  end
125
123
 
126
- end
124
+ end
@@ -2,38 +2,38 @@ describe "type bound functions" do
2
2
 
3
3
  describe "boolean" do
4
4
 
5
- it "should evaluate minBool() to False" do
6
- expect(MinBool.new.evaluate).to eq(False.new)
5
+ it "evaluates minBool() to False" do
6
+ expect(MinBool.new.evaluate).to eq(false_value)
7
7
  end
8
8
 
9
- it "should evaluate maxBool() to True" do
10
- expect(MaxBool.new.evaluate).to eq(True.new)
9
+ it "evaluates maxBool() to True" do
10
+ expect(MaxBool.new.evaluate).to eq(true_value)
11
11
  end
12
12
 
13
13
  end
14
14
 
15
15
  describe "colors" do
16
16
 
17
- it "should evaluate minColor() to Azul" do
18
- expect(MinColor.new.evaluate).to eq(Azul.new)
17
+ it "evaluates minColor() to Azul" do
18
+ expect(MinColor.new.evaluate).to eq(azul)
19
19
  end
20
20
 
21
- it "should evaluate maxColor() to Verde" do
22
- expect(MaxColor.new.evaluate).to eq(Verde.new)
21
+ it "evaluates maxColor() to Verde" do
22
+ expect(MaxColor.new.evaluate).to eq(verde)
23
23
  end
24
24
 
25
25
  end
26
26
 
27
27
  describe "directions" do
28
28
 
29
- it "should evaluate minDir() to Norte" do
30
- expect(MinDir.new.evaluate).to eq(Norte.new)
29
+ it "evaluates minDir() to Norte" do
30
+ expect(MinDir.new.evaluate).to eq(norte)
31
31
  end
32
32
 
33
- it "should evaluate maxDir() to Oeste" do
34
- expect(MaxDir.new.evaluate).to eq(Oeste.new)
33
+ it "evaluates maxDir() to Oeste" do
34
+ expect(MaxDir.new.evaluate).to eq(oeste)
35
35
  end
36
36
 
37
37
  end
38
38
 
39
- end
39
+ end
@@ -1,16 +1,28 @@
1
1
  describe VarName do
2
2
 
3
- let(:context) { ExecutionContext.new }
4
- let(:var_name) { VarName.new 'var' }
3
+ let(:context) { clean_context }
4
+ let(:variable_name) { 'var'.to_var_name }
5
5
 
6
- it "should return the associated value if it was defined in the context" do
7
- context.set var_name, 42.to_gbs_num
8
- expect(var_name.evaluate(context)).to eq(42.to_gbs_num)
6
+ it "returns the associated value if it was defined in the context" do
7
+ context.set variable_name, 42.to_gbs_num
8
+ expect(variable_name.evaluate(context)).to eq(42.to_gbs_num)
9
9
  end
10
10
 
11
- it "should raise an error if there is no definition in context" do
12
- expect { var_name.evaluate context }
11
+ it "raises an error if there is no definition in context" do
12
+ expect { variable_name.evaluate context }
13
13
  .to raise_error(UndefinedVariableError)
14
14
  end
15
15
 
16
- end
16
+ describe "#named?" do
17
+
18
+ it "is named 'var'" do
19
+ expect(variable_name.named? 'var').to be true
20
+ end
21
+
22
+ it "is not named 'blah'" do
23
+ expect(variable_name.named? 'blah').to be false
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -1,13 +1,11 @@
1
1
  describe Boolean do
2
2
 
3
- it "should evaluate true to self" do
4
- bool = True.new
5
- expect(bool.evaluate).to eq(bool)
3
+ it "evaluates true to itself" do
4
+ expect(true_value.evaluate).to eq(true_value)
6
5
  end
7
6
 
8
- it "should evaluate false to self" do
9
- bool = False.new
10
- expect(bool.evaluate).to eq(bool)
7
+ it "evaluates false to itself" do
8
+ expect(false_value.evaluate).to eq(false_value)
11
9
  end
12
10
 
13
- end
11
+ end
@@ -1,13 +1,13 @@
1
1
  describe "colors" do
2
2
 
3
- let(:all) { [Azul.new, Negro.new, Rojo.new, Verde.new] }
3
+ let(:all) { [azul, negro, rojo, verde] }
4
4
 
5
- it "should evaluate any color to self" do
5
+ it "evaluates any color to itself" do
6
6
  all.each { |color| expect(color.evaluate).to eq(color) }
7
7
  end
8
8
 
9
- it "should give the string representation" do
9
+ it "returns the string representation" do
10
10
  expect(all.map(&:to_s)).to eq(['Azul', 'Negro', 'Rojo', 'Verde'])
11
11
  end
12
12
 
13
- end
13
+ end
@@ -1,45 +1,45 @@
1
1
  describe "directions" do
2
2
 
3
- let(:all) { [Norte.new, Sur.new, Este.new, Oeste.new] }
3
+ let(:all) { [norte, sur, este, oeste] }
4
4
 
5
- it "should evaluate any direction to self" do
5
+ it "evaluates any direction to itself" do
6
6
  all.each { |dir| expect(dir.evaluate).to eq(dir) }
7
7
  end
8
8
 
9
- it "should return the string representation" do
9
+ it "returns the string representation" do
10
10
  expect(all.map(&:to_s)).to eq(['Norte', 'Sur', 'Este', 'Oeste'])
11
11
  end
12
12
 
13
13
  describe Norte do
14
14
 
15
- it "should return Sur as opposite direction" do
16
- expect(Norte.new.opposite).to eq(Sur.new)
15
+ it "returns Sur as the opposite direction" do
16
+ expect(norte.opposite).to eq(sur)
17
17
  end
18
18
 
19
19
  end
20
20
 
21
21
  describe Este do
22
22
 
23
- it "should return Oeste as opposite direction" do
24
- expect(Este.new.opposite).to eq(Oeste.new)
23
+ it "returns Oeste as the opposite direction" do
24
+ expect(este.opposite).to eq(oeste)
25
25
  end
26
26
 
27
27
  end
28
28
 
29
29
  describe Sur do
30
30
 
31
- it "should return Norte as opposite direction" do
32
- expect(Sur.new.opposite).to eq(Norte.new)
31
+ it "returns Norte as the opposite direction" do
32
+ expect(sur.opposite).to eq(norte)
33
33
  end
34
34
 
35
35
  end
36
36
 
37
37
  describe Oeste do
38
38
 
39
- it "should return Este as opposite direction" do
40
- expect(Oeste.new.opposite).to eq(Este.new)
39
+ it "returns Este as the opposite direction" do
40
+ expect(oeste.opposite).to eq(este)
41
41
  end
42
42
 
43
43
  end
44
44
 
45
- end
45
+ end
@@ -1,8 +1,8 @@
1
1
  describe Number do
2
2
 
3
- it "should evaluate to self" do
3
+ it "evaluates to itself" do
4
4
  num = 42.to_gbs_num
5
5
  expect(num.evaluate).to eq(num)
6
6
  end
7
7
 
8
- end
8
+ end
@@ -5,8 +5,6 @@ PARSER = Gobstones::Parser::TreetopParser.new
5
5
 
6
6
  RSpec::Matchers.define :be_parsed_as do |grammar_elem|
7
7
 
8
- @valid_nodes = [:program, :definition, :main, :expression, :command, :var_tuple ]
9
-
10
8
  chain :and_fail do
11
9
  @expect_parser_results = false
12
10
  end
@@ -17,8 +15,9 @@ RSpec::Matchers.define :be_parsed_as do |grammar_elem|
17
15
  end
18
16
 
19
17
  match do |actual|
18
+ valid_nodes = [:program, :definition, :main, :expression, :command, :var_tuple]
20
19
  fail 'wrong expectation' if @expect_parser_results.nil?
21
- fail 'grammar elem not supported' if !@valid_nodes.include?(grammar_elem)
20
+ fail 'grammar elem not supported' unless valid_nodes.include?(grammar_elem)
22
21
 
23
22
  begin
24
23
  parse send("#{grammar_elem}_code_to_program", actual)
@@ -41,7 +40,7 @@ RSpec::Matchers.define :be_parsed_as do |grammar_elem|
41
40
  end
42
41
 
43
42
  def main_node_to_program(node)
44
- Program.new [], node
43
+ Program.new no_definitions, node
45
44
  end
46
45
 
47
46
  def definition_code_to_program(code)
@@ -49,7 +48,7 @@ RSpec::Matchers.define :be_parsed_as do |grammar_elem|
49
48
  end
50
49
 
51
50
  def definition_node_to_program(node)
52
- Program.new [node], Main.new(CmdBlock.new([]), NoReturnStatement.new)
51
+ Program.new [node], Main.new(empty_body, no_return_statement)
53
52
  end
54
53
 
55
54
  def expression_code_to_program(code)
@@ -57,8 +56,8 @@ RSpec::Matchers.define :be_parsed_as do |grammar_elem|
57
56
  end
58
57
 
59
58
  def expression_node_to_program(node)
60
- assign = SingleAssignment.new VarName.new('x'), node
61
- main_node_to_program Main.new(CmdBlock.new([assign]), NoReturnStatement.new)
59
+ assign = SingleAssignment.new 'x'.to_var_name, node
60
+ main_node_to_program Main.new(CommandBlock.new([assign]), no_return_statement)
62
61
  end
63
62
 
64
63
  def command_code_to_program(code)
@@ -66,7 +65,7 @@ RSpec::Matchers.define :be_parsed_as do |grammar_elem|
66
65
  end
67
66
 
68
67
  def command_node_to_program(node)
69
- main_node_to_program Main.new(CmdBlock.new([node]), NoReturnStatement.new)
68
+ main_node_to_program Main.new(CommandBlock.new([node]), no_return_statement)
70
69
  end
71
70
 
72
71
  def var_tuple_code_to_program(code)
@@ -74,11 +73,11 @@ RSpec::Matchers.define :be_parsed_as do |grammar_elem|
74
73
  end
75
74
 
76
75
  def var_tuple_node_to_program(node)
77
- Program.new [], Main.new(CmdBlock.new([]), ReturnFromMain.new(node))
76
+ Program.new no_definitions, Main.new(empty_body, ReturnFromMain.new(node))
78
77
  end
79
78
 
80
79
  def parse(code)
81
80
  @value = PARSER.parse code
82
81
  end
83
82
 
84
- end
83
+ end