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.
- checksums.yaml +4 -4
- data/.gitignore +1 -3
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG +22 -2
- data/Gemfile +3 -3
- data/Gemfile.lock +32 -27
- data/bin/gobstones +1 -1
- data/examples/.gitkeep +0 -0
- data/gobstones.gemspec +2 -2
- data/lib/gobstones/cli/board_template +1 -1
- data/lib/gobstones/cli/printer.rb +1 -1
- data/lib/gobstones/cli/runner.rb +8 -2
- data/lib/gobstones/extensions/all.rb +2 -1
- data/lib/gobstones/extensions/boolean.rb +1 -1
- data/lib/gobstones/extensions/fixnum.rb +1 -1
- data/lib/gobstones/extensions/string.rb +9 -0
- data/lib/gobstones/lang/all.rb +1 -1
- data/lib/gobstones/lang/commands/all.rb +3 -2
- data/lib/gobstones/lang/commands/boom_cmd.rb +6 -3
- data/lib/gobstones/lang/commands/command_block.rb +1 -1
- data/lib/gobstones/lang/commands/conditional_cmd.rb +5 -1
- data/lib/gobstones/lang/commands/ir_al_origen_cmd.rb +1 -1
- data/lib/gobstones/lang/commands/mover_cmd.rb +4 -2
- data/lib/gobstones/lang/commands/multiple_assignment.rb +35 -0
- data/lib/gobstones/lang/commands/poner_cmd.rb +8 -4
- data/lib/gobstones/lang/commands/procedure_call.rb +1 -9
- data/lib/gobstones/lang/commands/repeat_with_cmd.rb +10 -6
- data/lib/gobstones/lang/commands/sacar_cmd.rb +9 -7
- data/lib/gobstones/lang/commands/{assignments.rb → single_assignment.rb} +5 -3
- data/lib/gobstones/lang/commands/skip_cmd.rb +2 -2
- data/lib/gobstones/lang/commands/vaciar_tablero_cmd.rb +1 -1
- data/lib/gobstones/lang/commands/while_cmd.rb +1 -1
- data/lib/gobstones/lang/definitions/all.rb +1 -1
- data/lib/gobstones/lang/definitions/definition.rb +47 -5
- data/lib/gobstones/lang/definitions/definition_call.rb +17 -5
- data/lib/gobstones/lang/definitions/function.rb +9 -0
- data/lib/gobstones/lang/definitions/main.rb +1 -1
- data/lib/gobstones/lang/definitions/no_return_statement.rb +7 -3
- data/lib/gobstones/lang/definitions/procedure.rb +5 -20
- data/lib/gobstones/lang/definitions/return_from_function.rb +12 -2
- data/lib/gobstones/lang/definitions/return_from_main.rb +5 -1
- data/lib/gobstones/lang/definitions/var_tuple.rb +13 -1
- data/lib/gobstones/lang/expressions/all.rb +1 -1
- data/lib/gobstones/lang/expressions/arithmetic_expressions.rb +1 -1
- data/lib/gobstones/lang/expressions/boolean_expressions.rb +3 -2
- data/lib/gobstones/lang/expressions/enclosed_by_parens_expression.rb +17 -0
- data/lib/gobstones/lang/expressions/function_call.rb +1 -1
- data/lib/gobstones/lang/expressions/one_arg_expression.rb +16 -4
- data/lib/gobstones/lang/expressions/primitive_functions.rb +18 -12
- data/lib/gobstones/lang/expressions/two_arg_expression.rb +7 -3
- data/lib/gobstones/lang/expressions/type_bound_functions.rb +1 -1
- data/lib/gobstones/lang/expressions/var_name.rb +9 -3
- data/lib/gobstones/lang/literals/all.rb +1 -1
- data/lib/gobstones/lang/literals/colors.rb +1 -1
- data/lib/gobstones/lang/literals/literal.rb +31 -21
- data/lib/gobstones/lang/literals/number.rb +1 -1
- data/lib/gobstones/lang/program.rb +13 -4
- data/lib/gobstones/modules/equal_by_class.rb +1 -1
- data/lib/gobstones/parser/ast/ast.rb +12 -8
- data/lib/gobstones/parser/grammar/gobstones.treetop +4 -4
- data/lib/gobstones/parser/parse_error.rb +1 -1
- data/lib/gobstones/runner/all.rb +1 -2
- data/lib/gobstones/runner/board.rb +13 -4
- data/lib/gobstones/runner/cell.rb +10 -0
- data/lib/gobstones/runner/errors/all.rb +1 -1
- data/lib/gobstones/runner/errors/definition_not_found_error.rb +1 -1
- data/lib/gobstones/runner/execution_context.rb +66 -16
- data/lib/gobstones/runner/head.rb +17 -3
- data/spec/gobstones_lang_test_objects.rb +75 -0
- data/spec/lang/commands/boom_cmd_spec.rb +3 -3
- data/spec/lang/commands/cmd_block_spec.rb +14 -14
- data/spec/lang/commands/if_cmd_spec.rb +21 -20
- data/spec/lang/commands/ir_al_origen_cmd_spec.rb +3 -3
- data/spec/lang/commands/mover_cmd_spec.rb +12 -14
- data/spec/lang/commands/multiple_assignment_spec.rb +37 -0
- data/spec/lang/commands/poner_cmd_spec.rb +13 -14
- data/spec/lang/commands/procedure_call_spec.rb +19 -24
- data/spec/lang/commands/procedure_spec.rb +32 -36
- data/spec/lang/commands/repeat_with_cmd_spec.rb +39 -20
- data/spec/lang/commands/sacar_cmd_spec.rb +17 -16
- data/spec/lang/commands/single_assignment_spec.rb +13 -0
- data/spec/lang/commands/skip_cmd_spec.rb +2 -2
- data/spec/lang/commands/vaciar_tablero_cmd_spec.rb +7 -6
- data/spec/lang/commands/while_cmd_spec.rb +21 -15
- data/spec/lang/definitions/no_return_statement_spec.rb +10 -0
- data/spec/lang/definitions/var_tuple_spec.rb +16 -0
- data/spec/lang/expressions/arithmetic_expressions_spec.rb +15 -15
- data/spec/lang/expressions/boolean_expressions_spec.rb +35 -25
- data/spec/lang/expressions/comparison_expressions_spec.rb +25 -28
- data/spec/lang/expressions/enclosed_by_parens_expression_spec.rb +11 -0
- data/spec/lang/expressions/function_call_spec.rb +29 -0
- data/spec/lang/expressions/primitive_functions_spec.rb +60 -62
- data/spec/lang/expressions/type_bound_functions_spec.rb +13 -13
- data/spec/lang/expressions/var_name_spec.rb +20 -8
- data/spec/lang/literals/booleans_spec.rb +5 -7
- data/spec/lang/literals/colors_spec.rb +4 -4
- data/spec/lang/literals/directions_spec.rb +12 -12
- data/spec/lang/literals/numbers_spec.rb +2 -2
- data/spec/matchers/parse_matcher.rb +9 -10
- data/spec/parser/arithmetic_expressions_spec.rb +19 -19
- data/spec/parser/assignments_spec.rb +24 -10
- data/spec/parser/boolean_expressions_spec.rb +18 -18
- data/spec/parser/command_block_spec.rb +17 -19
- data/spec/parser/data_types_spec.rb +23 -23
- data/spec/parser/function_calls_spec.rb +13 -12
- data/spec/parser/function_definitions_spec.rb +13 -18
- data/spec/parser/gobstones_program_spec.rb +15 -15
- data/spec/parser/if_command_spec.rb +13 -12
- data/spec/parser/main_definition_spec.rb +12 -12
- data/spec/parser/nested_expressions_spec.rb +16 -20
- data/spec/parser/primitive_expressions_spec.rb +27 -33
- data/spec/parser/procedure_calls_spec.rb +12 -12
- data/spec/parser/procedure_definitions_spec.rb +10 -16
- data/spec/parser/repeat_with_command_spec.rb +7 -10
- data/spec/parser/simple_commands_spec.rb +10 -10
- data/spec/parser/treetop_parser_spec.rb +11 -10
- data/spec/parser/var_tuple_spec.rb +7 -11
- data/spec/parser/while_command_spec.rb +9 -9
- data/spec/runner/board_spec.rb +23 -27
- data/spec/runner/cell_spec.rb +34 -38
- data/spec/runner/execution_context_spec.rb +38 -24
- data/spec/runner/head_spec.rb +54 -63
- data/spec/spec_helper.rb +4 -1
- data/spec/type_checker_spec.rb +13 -13
- metadata +33 -18
- data/lib/gobstones/lang/expressions/parentheses_expression.rb +0 -13
- data/spec/lang/commands/assignments_spec.rb +0 -13
@@ -1,36 +1,36 @@
|
|
1
1
|
describe Gobstones::Parser, "procedure calls" do
|
2
2
|
|
3
|
-
it "
|
3
|
+
it "parses a procedure call without args" do
|
4
4
|
expect('P1()').to be_parsed_as(:command).and_return(ProcedureCall.new('P1'))
|
5
5
|
end
|
6
6
|
|
7
|
-
it "
|
7
|
+
it "does not parse a procedure call without a valid identifier" do
|
8
8
|
expect('p1()').to be_parsed_as(:command).and_fail
|
9
9
|
end
|
10
10
|
|
11
|
-
it "
|
12
|
-
expected = ProcedureCall.new 'Proc1', [
|
11
|
+
it "parses a procedure call with one arg" do
|
12
|
+
expected = ProcedureCall.new 'Proc1', [verde]
|
13
13
|
expect('Proc1(Verde)').to be_parsed_as(:command).and_return(expected)
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
16
|
+
it "parses a procedure with many args" do
|
17
17
|
first_arg = 42.to_gbs_num
|
18
|
-
second_arg = NroBolitas.new
|
19
|
-
third_arg =
|
18
|
+
second_arg = NroBolitas.new verde
|
19
|
+
third_arg = norte
|
20
20
|
expected = ProcedureCall.new 'Proc1', [first_arg, second_arg, third_arg]
|
21
21
|
|
22
22
|
expect('Proc1(42, nroBolitas(Verde), Norte)').
|
23
23
|
to be_parsed_as(:command).and_return(expected)
|
24
24
|
end
|
25
25
|
|
26
|
-
it "
|
27
|
-
or_expr = Or.new
|
28
|
-
paren_expr =
|
26
|
+
it "parses a complex procedure call" do
|
27
|
+
or_expr = Or.new 'a'.to_var_name, 'b'.to_var_name
|
28
|
+
paren_expr = EnclosedByParensExpression.new Div.new(10.to_gbs_num, 'c'.to_var_name)
|
29
29
|
num_expr = Mul.new 5.to_gbs_num, paren_expr
|
30
|
-
func_call = FunctionCall.new 'func', [
|
30
|
+
func_call = FunctionCall.new 'func', [verde, Opuesto.new(norte)]
|
31
31
|
proc_call = ProcedureCall.new 'Proc1', [or_expr, num_expr, func_call]
|
32
32
|
expect('Proc1(a || b, 5*(10 div c), func(Verde, opuesto(Norte)))').
|
33
33
|
to be_parsed_as(:command).and_return(proc_call)
|
34
34
|
end
|
35
35
|
|
36
|
-
end
|
36
|
+
end
|
@@ -1,29 +1,23 @@
|
|
1
1
|
describe Gobstones::Parser, "procedure definitions" do
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it "should parse an empty procedure def without args" do
|
6
|
-
args = VarTuple.new []
|
7
|
-
proc_def = Procedure.new 'MyProc', args, body
|
3
|
+
it "parses an empty procedure def without args" do
|
4
|
+
proc_def = Procedure.new 'MyProc', no_arguments, empty_body
|
8
5
|
|
9
6
|
expect('procedure MyProc() {}').
|
10
7
|
to be_parsed_as(:definition).and_return(proc_def)
|
11
8
|
end
|
12
9
|
|
13
|
-
it "
|
14
|
-
|
15
|
-
|
16
|
-
third_arg = VarName.new 'thirdArg'
|
17
|
-
args = VarTuple.new [first_arg, second_arg, third_arg]
|
18
|
-
proc_def = Procedure.new 'MyProc', args, body
|
10
|
+
it "parses an empty procedure with some args" do
|
11
|
+
args = VarTuple.new ['firstArg'.to_var_name, 'secondArg'.to_var_name, 'thirdArg'.to_var_name]
|
12
|
+
proc_def = Procedure.new 'MyProc', args, empty_body
|
19
13
|
|
20
14
|
expect('procedure MyProc (firstArg, secondArg, thirdArg) {}').
|
21
15
|
to be_parsed_as(:definition).and_return(proc_def)
|
22
16
|
end
|
23
17
|
|
24
|
-
it "
|
25
|
-
args = VarTuple.new [
|
26
|
-
body =
|
18
|
+
it "parses a procedure with some statements" do
|
19
|
+
args = VarTuple.new ['arg'.to_var_name]
|
20
|
+
body = CommandBlock.new [Poner.new(verde)]
|
27
21
|
proc_def = Procedure.new 'MyProc', args, body
|
28
22
|
|
29
23
|
expect('procedure MyProc(arg)
|
@@ -32,8 +26,8 @@ describe Gobstones::Parser, "procedure definitions" do
|
|
32
26
|
}').to be_parsed_as(:definition).and_return(proc_def)
|
33
27
|
end
|
34
28
|
|
35
|
-
it "
|
29
|
+
it "does not parse a procedure without a valid identifier" do
|
36
30
|
expect('procedure myWrongProc() {}').to be_parsed_as(:definition).and_fail
|
37
31
|
end
|
38
32
|
|
39
|
-
end
|
33
|
+
end
|
@@ -1,23 +1,20 @@
|
|
1
1
|
describe Gobstones::Parser, "repeatWith statements" do
|
2
2
|
|
3
|
-
it "
|
4
|
-
var_name = VarName.new 'i'
|
3
|
+
it "parses an empty statement" do
|
5
4
|
min_range, max_range = 1.to_gbs_num, 10.to_gbs_num
|
6
|
-
|
7
|
-
rw_cmd = RepeatWithCmd.new var_name, min_range, max_range, cmd_block
|
5
|
+
rw_cmd = RepeatWithCmd.new 'i'.to_var_name, min_range, max_range, empty_body
|
8
6
|
|
9
7
|
expect('repeatWith i in 1..10 {}').to be_parsed_as(:command).and_return(rw_cmd)
|
10
8
|
end
|
11
9
|
|
12
|
-
it "
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
rw_cmd = RepeatWithCmd.new var_name, min_range, max_range, cmd_block
|
10
|
+
it "parses an statement with any expressions in the range" do
|
11
|
+
min_range, max_range = MinDir.new, Siguiente.new(rojo)
|
12
|
+
cmd_block = CommandBlock.new [Poner.new(verde)]
|
13
|
+
rw_cmd = RepeatWithCmd.new 'myDir'.to_var_name, min_range, max_range, cmd_block
|
17
14
|
|
18
15
|
expect('repeatWith myDir in minDir() .. siguiente(Rojo) {
|
19
16
|
Poner(Verde)
|
20
17
|
}').to be_parsed_as(:command).and_return(rw_cmd)
|
21
18
|
end
|
22
19
|
|
23
|
-
end
|
20
|
+
end
|
@@ -5,12 +5,12 @@ describe Gobstones::Parser, "simple commands" do
|
|
5
5
|
|
6
6
|
describe "primitives" do
|
7
7
|
|
8
|
-
it "
|
8
|
+
it "parses a Skip cmd" do
|
9
9
|
skip_cmd = Skip.new
|
10
10
|
expect('Skip').to be_parsed_as(:command).and_return(skip_cmd)
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
13
|
+
it "parses a BOOM cmd" do
|
14
14
|
boom_cmd = Boom.new 'the message'
|
15
15
|
expect('BOOM("the message")').to be_parsed_as(:command).and_return(boom_cmd)
|
16
16
|
expect('BOOM ("the message")').to be_parsed_as(:command).and_return(boom_cmd)
|
@@ -21,21 +21,21 @@ describe Gobstones::Parser, "simple commands" do
|
|
21
21
|
|
22
22
|
describe "#{command}() cmd" do
|
23
23
|
|
24
|
-
it "
|
25
|
-
cmd = Kernel.const_get(command).new
|
24
|
+
it "is parsed ok with a primitive as argument" do
|
25
|
+
cmd = Kernel.const_get(command).new verde
|
26
26
|
expect("#{command}(Verde)").to be_parsed_as(:command).and_return(cmd)
|
27
27
|
expect("#{command} (Verde)").to be_parsed_as(:command).and_return(cmd)
|
28
28
|
expect("#{command}( Verde )").to be_parsed_as(:command).and_return(cmd)
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
31
|
+
it "is parsed ok with a simple expression as argument" do
|
32
32
|
cmd = Kernel.const_get(command).new MinColor.new
|
33
33
|
expect("#{command}(minColor())").
|
34
34
|
to be_parsed_as(:command).and_return(cmd)
|
35
35
|
end
|
36
36
|
|
37
|
-
it "
|
38
|
-
func_call = FunctionCall.new 'funcCall', [
|
37
|
+
it "is parsed ok with a complex expression as argument" do
|
38
|
+
func_call = FunctionCall.new 'funcCall', [norte, 42.to_gbs_num]
|
39
39
|
cmd = Kernel.const_get(command).new Opuesto.new(func_call)
|
40
40
|
expect("#{command}(opuesto(funcCall(Norte, 42)))").
|
41
41
|
to be_parsed_as(:command).and_return(cmd)
|
@@ -45,13 +45,13 @@ describe Gobstones::Parser, "simple commands" do
|
|
45
45
|
|
46
46
|
end
|
47
47
|
|
48
|
-
it "
|
48
|
+
it "parses a IrAlOrigen cmd" do
|
49
49
|
ir_al_origen_cmd = IrAlOrigen.new
|
50
50
|
expect('IrAlOrigen()').to be_parsed_as(:command).
|
51
51
|
and_return(ir_al_origen_cmd)
|
52
52
|
end
|
53
53
|
|
54
|
-
it "
|
54
|
+
it "parses a VaciarTablero cmd" do
|
55
55
|
vaciar_tablero_cmd = VaciarTablero.new
|
56
56
|
expect('VaciarTablero()').to be_parsed_as(:command).
|
57
57
|
and_return(vaciar_tablero_cmd)
|
@@ -59,4 +59,4 @@ describe Gobstones::Parser, "simple commands" do
|
|
59
59
|
|
60
60
|
end
|
61
61
|
|
62
|
-
end
|
62
|
+
end
|
@@ -4,13 +4,13 @@ describe Gobstones::Parser do
|
|
4
4
|
|
5
5
|
describe "removing comments of a gobstones piece of code" do
|
6
6
|
|
7
|
-
it "
|
7
|
+
it "removes a one-line comment with // characters for a single line" do
|
8
8
|
code_with_comments = 'Poner(Verde) // put a green ball on the board'
|
9
9
|
code_without_comments = @parser.remove_comments_from code_with_comments
|
10
10
|
expect(code_without_comments).to eq('Poner(Verde) ')
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
13
|
+
it "removes many one-line comments with //" do
|
14
14
|
code_with_comments = <<CODE
|
15
15
|
Poner(Verde) // put a green ball on the board
|
16
16
|
Poner(Azul) // and a blue one
|
@@ -24,13 +24,13 @@ Poner(Azul)
|
|
24
24
|
CODE
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
27
|
+
it "removes a one-line comment with -- for a single line" do
|
28
28
|
code_with_comments = 'Poner(Verde) -- put a green ball on the board'
|
29
29
|
code_without_comments = @parser.remove_comments_from code_with_comments
|
30
30
|
expect(code_without_comments).to eq('Poner(Verde) ')
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
33
|
+
it "removes many one-line comments with --" do
|
34
34
|
code_with_comments = <<CODE
|
35
35
|
Poner(Verde) -- put a green ball on the board
|
36
36
|
Poner(Azul) -- and a blue one
|
@@ -44,7 +44,7 @@ Poner(Azul)
|
|
44
44
|
CODE
|
45
45
|
end
|
46
46
|
|
47
|
-
it "
|
47
|
+
it "removes many one-line comments with // and --" do
|
48
48
|
code_with_comments = <<CODE
|
49
49
|
Poner(Verde) // put a green ball on the board
|
50
50
|
Poner(Azul) -- and a blue one
|
@@ -60,13 +60,14 @@ if (puedeMover(Norte)) { Mover(Norte) }
|
|
60
60
|
CODE
|
61
61
|
end
|
62
62
|
|
63
|
-
it "
|
63
|
+
it "removes a multiline comment with {- -}" do
|
64
64
|
code_with_comments = 'Poner(Verde) {- this is a comment -}'
|
65
65
|
code_without_comments = @parser.remove_comments_from code_with_comments
|
66
66
|
expect(code_without_comments).to eq('Poner(Verde) ')
|
67
67
|
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
|
+
it "removes many multiline comments with {- -}, in same and different lines" do
|
70
71
|
code_with_comments = <<CODE
|
71
72
|
Poner(Verde) {- comment 1 -}
|
72
73
|
Poner(Azul) {- start comment 2
|
@@ -82,13 +83,13 @@ Poner(Rojo)
|
|
82
83
|
CODE
|
83
84
|
end
|
84
85
|
|
85
|
-
it "
|
86
|
+
it "removes a multiline comment with /* */" do
|
86
87
|
code_with_comments = 'Poner(Verde) /* this is a comment */'
|
87
88
|
code_without_comments = @parser.remove_comments_from code_with_comments
|
88
89
|
expect(code_without_comments).to eq('Poner(Verde) ')
|
89
90
|
|
90
91
|
end
|
91
|
-
it "
|
92
|
+
it "removes many multiline comments with /* */, in same and different lines" do
|
92
93
|
code_with_comments = <<CODE
|
93
94
|
Poner(Verde) /* comment 1 */
|
94
95
|
Poner(Azul) /* start comment 2
|
@@ -106,4 +107,4 @@ CODE
|
|
106
107
|
|
107
108
|
end
|
108
109
|
|
109
|
-
end
|
110
|
+
end
|
@@ -1,25 +1,21 @@
|
|
1
1
|
describe Gobstones::Parser, "var tuples" do
|
2
2
|
|
3
|
-
it "
|
4
|
-
var_tuple = VarTuple.
|
3
|
+
it "parses an empty var tuple" do
|
4
|
+
var_tuple = VarTuple.empty
|
5
5
|
|
6
6
|
expect('()').to be_parsed_as(:var_tuple).and_return(var_tuple)
|
7
7
|
expect('( )').to be_parsed_as(:var_tuple).and_return(var_tuple)
|
8
8
|
end
|
9
9
|
|
10
|
-
it "
|
11
|
-
|
12
|
-
var_tuple = VarTuple.new [var]
|
10
|
+
it "parses a var tuple with one arg" do
|
11
|
+
var_tuple = VarTuple.new ['myVar'.to_var_name]
|
13
12
|
|
14
13
|
expect('(myVar)').to be_parsed_as(:var_tuple).and_return(var_tuple)
|
15
14
|
expect('( myVar )').to be_parsed_as(:var_tuple).and_return(var_tuple)
|
16
15
|
end
|
17
16
|
|
18
|
-
it "
|
19
|
-
|
20
|
-
second = VarName.new 'secondVar'
|
21
|
-
third = VarName.new 'thirdVar'
|
22
|
-
var_tuple = VarTuple.new [first, second, third]
|
17
|
+
it "parses a var tuple with many args" do
|
18
|
+
var_tuple = VarTuple.new ['firstVar'.to_var_name, 'secondVar'.to_var_name, 'thirdVar'.to_var_name]
|
23
19
|
|
24
20
|
expect('(firstVar, secondVar, thirdVar)').
|
25
21
|
to be_parsed_as(:var_tuple).and_return(var_tuple)
|
@@ -27,4 +23,4 @@ describe Gobstones::Parser, "var tuples" do
|
|
27
23
|
to be_parsed_as(:var_tuple).and_return(var_tuple)
|
28
24
|
end
|
29
25
|
|
30
|
-
end
|
26
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe Gobstones::Parser, "while statements" do
|
2
2
|
|
3
|
-
it "
|
4
|
-
while_cmd = WhileCmd.new
|
3
|
+
it "parses a statement with a simple boolean and an empty block" do
|
4
|
+
while_cmd = WhileCmd.new true_value, empty_body
|
5
5
|
|
6
6
|
expect('while (True) {}').to be_parsed_as(:command).and_return(while_cmd)
|
7
7
|
expect('while (True) {
|
@@ -10,18 +10,18 @@ describe Gobstones::Parser, "while statements" do
|
|
10
10
|
{}').to be_parsed_as(:command).and_return(while_cmd)
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
14
|
-
cmd_block =
|
15
|
-
while_cmd = WhileCmd.new
|
13
|
+
it "parses a statement with a simple boolean and a block with commands" do
|
14
|
+
cmd_block = CommandBlock.new [Poner.new(verde), Skip.new]
|
15
|
+
while_cmd = WhileCmd.new false_value, cmd_block
|
16
16
|
|
17
17
|
expect('while(False){Poner(Verde); Skip}').
|
18
18
|
to be_parsed_as(:command).and_return(while_cmd)
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
22
|
-
and_expr = And.new
|
23
|
-
exp = Or.new PuedeMover.new(
|
24
|
-
while_cmd = WhileCmd.new exp,
|
21
|
+
it "parses a statement with a complex boolean expression" do
|
22
|
+
and_expr = And.new 'a'.to_var_name, false_value
|
23
|
+
exp = Or.new PuedeMover.new(norte), EnclosedByParensExpression.new(and_expr)
|
24
|
+
while_cmd = WhileCmd.new exp, empty_body
|
25
25
|
|
26
26
|
expect('while (puedeMover(Norte) || (a && False)) {}').
|
27
27
|
to be_parsed_as(:command).and_return(while_cmd)
|
data/spec/runner/board_spec.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
describe Board do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:blue) { Azul.new }
|
5
|
-
let(:green) { Verde.new }
|
6
|
-
let(:red) { Rojo.new }
|
7
|
-
let(:colors) { [blue, black, red, green] }
|
3
|
+
let(:colors) { [azul, negro, rojo, verde] }
|
8
4
|
|
9
5
|
it "can be created with a number of rows and columns" do
|
10
6
|
board = Board.new 8, 5
|
@@ -12,13 +8,13 @@ describe Board do
|
|
12
8
|
expect(board.columns).to eq(5)
|
13
9
|
end
|
14
10
|
|
15
|
-
it "
|
11
|
+
it "has cells in every position" do
|
16
12
|
board = Board.new 3, 3
|
17
13
|
|
18
14
|
board.each_cell { |cell| expect(cell).to be_a(Cell) }
|
19
15
|
end
|
20
16
|
|
21
|
-
it "
|
17
|
+
it "accesses cells in a x&y dimension" do
|
22
18
|
board = Board.new 3, 5
|
23
19
|
|
24
20
|
3.times do |x|
|
@@ -28,7 +24,7 @@ describe Board do
|
|
28
24
|
end
|
29
25
|
end
|
30
26
|
|
31
|
-
it "
|
27
|
+
it "raises errors if it is accessed out of the bounds" do
|
32
28
|
board = Board.new 9, 6
|
33
29
|
|
34
30
|
expect { board.cell_at(9, 4) }.to raise_error(OutOfBoardError)
|
@@ -37,28 +33,28 @@ describe Board do
|
|
37
33
|
expect { board.cell_at(8, -1) }.to raise_error(OutOfBoardError)
|
38
34
|
end
|
39
35
|
|
40
|
-
it "
|
36
|
+
it "puts balls in a given position" do
|
41
37
|
board = Board.new 5, 5
|
42
38
|
|
43
|
-
2.times { board.put 0, 0,
|
44
|
-
10.times { board.put 2, 3,
|
39
|
+
2.times { board.put 0, 0, azul }
|
40
|
+
10.times { board.put 2, 3, rojo }
|
45
41
|
|
46
|
-
expect(board.are_there_balls?(0, 0,
|
47
|
-
expect(board.number_of_balls(0, 0,
|
48
|
-
expect(board.are_there_balls?(2, 3,
|
49
|
-
expect(board.number_of_balls(2, 3,
|
42
|
+
expect(board.are_there_balls?(0, 0, azul)).to be true
|
43
|
+
expect(board.number_of_balls(0, 0, azul)).to eq(2)
|
44
|
+
expect(board.are_there_balls?(2, 3, rojo)).to be true
|
45
|
+
expect(board.number_of_balls(2, 3, rojo)).to eq(10)
|
50
46
|
end
|
51
47
|
|
52
|
-
it "
|
48
|
+
it "puts and takes out balls in a given position" do
|
53
49
|
board = Board.new 2, 2
|
54
50
|
|
55
|
-
3.times { board.put 1, 1,
|
56
|
-
3.times { board.take_out 1, 1,
|
51
|
+
3.times { board.put 1, 1, verde }
|
52
|
+
3.times { board.take_out 1, 1, verde }
|
57
53
|
|
58
|
-
expect(board.are_there_balls?(1, 1,
|
54
|
+
expect(board.are_there_balls?(1, 1, verde)).to be false
|
59
55
|
end
|
60
56
|
|
61
|
-
it "
|
57
|
+
it "clears the entire board" do
|
62
58
|
board = Board.new 3, 4
|
63
59
|
board.each_cell { |cell| cell.put colors.sample }
|
64
60
|
|
@@ -66,20 +62,20 @@ describe Board do
|
|
66
62
|
|
67
63
|
board.each_cell do |cell|
|
68
64
|
colors.each do |color|
|
69
|
-
expect(cell.are_there_balls?(color)).to
|
65
|
+
expect(cell.are_there_balls?(color)).to be false
|
70
66
|
end
|
71
67
|
end
|
72
68
|
end
|
73
69
|
|
74
|
-
it "
|
70
|
+
it "is empty if there are no balls" do
|
75
71
|
board = Board.new 3, 4
|
76
|
-
expect(board.empty?).to
|
72
|
+
expect(board.empty?).to be true
|
77
73
|
end
|
78
74
|
|
79
|
-
it "
|
75
|
+
it "is not empty if there are balls" do
|
80
76
|
board = Board.new 3, 4
|
81
|
-
board.put 0, 0,
|
82
|
-
expect(board.empty?).to
|
77
|
+
board.put 0, 0, negro
|
78
|
+
expect(board.empty?).to be false
|
83
79
|
end
|
84
80
|
|
85
|
-
end
|
81
|
+
end
|