cauldron 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -0
- data/Gemfile.lock +63 -0
- data/History.md +5 -0
- data/Rakefile +62 -16
- data/VERSION +1 -1
- data/cauldron.gemspec +463 -0
- data/cauldron/lib/cauldron.rb +1 -1
- data/features/cauldron_generates_runtime_method.feature +7 -4
- data/features/cauldron_generates_single_paramter_methods.feature +25 -0
- data/features/cauldron_interactive_start_terminal.feature +17 -0
- data/features/cauldron_quit_terminal.feature +9 -0
- data/features/cauldron_start_terminal.feature +0 -1
- data/features/step_definitions/cauldron_steps.rb +10 -5
- data/features/step_definitions/terminal_steps.rb +27 -0
- data/features/support/env.rb +2 -0
- data/features/support/hooks.rb +15 -0
- data/lib/Chain.rb +3 -3
- data/lib/Mapping.rb +1 -0
- data/lib/PartialChain.rb +253 -0
- data/lib/Theory.rb +28 -4
- data/lib/UnifiedChain.rb +94 -125
- data/lib/cauldron.rb +3 -0
- data/lib/cauldron/demos.rb +4 -4
- data/lib/cauldron/env.rb +1 -0
- data/lib/cauldron/pot.rb +42 -38
- data/lib/cauldron/terminal.rb +19 -3
- data/lib/cauldron/util/home.rb +21 -0
- data/lib/cauldron/util/saver.rb +45 -0
- data/lib/core/Container.rb +1 -1
- data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +28 -28
- data/lib/core/runtime_method/RuntimeMethod.rb +6 -23
- data/lib/core/statement/ActsAsStatement.rb +0 -96
- data/lib/core/statement/BlockStatement.rb +1 -1
- data/lib/core/statement/OpenStatement.rb +1 -1
- data/lib/core/statement/Statement.rb +39 -94
- data/lib/core/statement/TheoryStatement.rb +1 -1
- data/lib/core/syntax/BlockContainer.rb +0 -28
- data/lib/core/variable/MethodParameter.rb +1 -1
- data/lib/required.rb +2 -14
- data/lib/theories.rb +0 -1
- data/lib/theory/ActionImplementation.rb +1 -1
- data/lib/theory/TheoryAction.rb +2 -2
- data/lib/theory/TheoryConnector.rb +11 -14
- data/lib/theory/TheoryImplementation.rb +10 -9
- data/lib/util/MethodWriter.rb +10 -10
- data/sandbox.rb +23 -0
- data/spec/cauldron/pot_spec.rb +62 -10
- data/spec/cauldron/runtime_method_spec.rb +31 -17
- data/spec/cauldron/saver_spec.rb +45 -0
- data/spec/cauldron/terminal_spec.rb +10 -1
- data/spec/cauldron/theory_spec.rb +4 -4
- data/spec/cauldron/unified_chain_spec.rb +38 -0
- data/spec/spec_helper.rb +3 -1
- data/tasks/development_tasks.rake +4 -0
- data/tasks/theory_tasks.rake +16 -20
- data/test/fixtures/theories/0/desc +6 -6
- data/test/fixtures/theories/0/dump +0 -0
- data/test/fixtures/theories/1/desc +7 -7
- data/test/fixtures/theories/1/dump +0 -0
- data/test/fixtures/theories/10/desc +13 -13
- data/test/fixtures/theories/10/dump +0 -0
- data/test/fixtures/theories/11/desc +10 -10
- data/test/fixtures/theories/11/dump +0 -0
- data/test/fixtures/theories/12/desc +9 -9
- data/test/fixtures/theories/12/dump +0 -0
- data/test/fixtures/theories/13/desc +16 -16
- data/test/fixtures/theories/13/dump +0 -0
- data/test/fixtures/theories/14/desc +16 -16
- data/test/fixtures/theories/14/dump +0 -0
- data/test/fixtures/theories/15/desc +10 -10
- data/test/fixtures/theories/15/dump +0 -0
- data/test/fixtures/theories/16/desc +10 -10
- data/test/fixtures/theories/16/dump +0 -0
- data/test/fixtures/theories/17/desc +7 -7
- data/test/fixtures/theories/17/dump +0 -0
- data/test/fixtures/theories/18/desc +7 -7
- data/test/fixtures/theories/18/dump +0 -0
- data/test/fixtures/theories/19/desc +7 -7
- data/test/fixtures/theories/19/dump +0 -0
- data/test/fixtures/theories/2/desc +6 -6
- data/test/fixtures/theories/2/dump +0 -0
- data/test/fixtures/theories/20/desc +13 -13
- data/test/fixtures/theories/20/dump +0 -0
- data/test/fixtures/theories/3/desc +7 -7
- data/test/fixtures/theories/3/dump +0 -0
- data/test/fixtures/theories/4/desc +7 -7
- data/test/fixtures/theories/4/dump +0 -0
- data/test/fixtures/theories/5/desc +6 -6
- data/test/fixtures/theories/5/dump +0 -0
- data/test/fixtures/theories/6/desc +7 -7
- data/test/fixtures/theories/6/dump +0 -0
- data/test/fixtures/theories/7/desc +7 -7
- data/test/fixtures/theories/7/dump +0 -0
- data/test/fixtures/theories/8/desc +7 -7
- data/test/fixtures/theories/8/dump +0 -0
- data/test/fixtures/theories/9/desc +16 -16
- data/test/fixtures/theories/9/dump +0 -0
- data/test/fixtures/theory_implementations/0/dump +0 -0
- data/test/fixtures/theory_implementations/2/dump +0 -0
- data/test/ts_complete.rb +1 -10
- data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +1 -0
- data/test/unit/core/runtime_method/tc_runtime_method.rb +16 -39
- data/test/unit/core/statement/tc_block_statement.rb +3 -3
- data/test/unit/core/statement/tc_open_statement.rb +4 -4
- data/test/unit/core/statement/tc_statement.rb +2 -147
- data/test/unit/core/statement/tc_theory_statement.rb +1 -1
- data/test/unit/theory/tc_theory_dependent.rb +3 -3
- data/test/unit/theory/tc_theory_result.rb +5 -5
- data/test/unit/util/tc_method_validation.rb +45 -45
- data/test/unit/util/tc_parser.rb +1 -1
- data/test/unit/util/tc_string_to_theory.rb +2 -2
- metadata +74 -48
- data/lib/ScopeDependencies.rb +0 -8
- data/lib/core/statement/StatementDependencies.rb +0 -271
- data/lib/core/structure/DeclareNewInstanceStructure.rb +0 -49
- data/lib/core/structure/DeclareRuntimeMethodStructure.rb +0 -34
- data/lib/core/structure/DeclareVariableAsLiteralStructure.rb +0 -31
- data/lib/core/structure/DeclareVariableAsVariableStructure.rb +0 -52
- data/lib/core/structure/FixnumAdditionStructure.rb +0 -56
- data/lib/core/structure/InstanceCallContainerStructure.rb +0 -50
- data/lib/core/structure/InstanceCallStructure.rb +0 -53
- data/lib/core/structure/InstanceMethodCallStructure.rb +0 -21
- data/lib/core/structure/ReturnStructure.rb +0 -20
- data/lib/core/structure/StatementStructure.rb +0 -11
- data/test/unit/core/statement/tc_statement_dependencies.rb +0 -147
- data/test/unit/core/structure/tc_declare_new_instance_structure.rb +0 -41
- data/test/unit/core/structure/tc_declare_variable_as_literal_structure.rb +0 -41
- data/test/unit/core/structure/tc_declare_variable_as_variable_structure.rb +0 -66
- data/test/unit/core/structure/tc_instance_call_container_structure.rb +0 -41
- data/test/unit/core/structure/tc_return_structure.rb +0 -32
- data/test/unit/tc_instance_call_structure.rb +0 -35
- data/test/unit/tc_statement_structure_2.rb +0 -43
Binary file
|
@@ -1,11 +1,11 @@
|
|
1
1
|
if:
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
if(var1.realise2(var2[var3][:params]).params[var4].value.length == var2[var3][:output])
|
3
|
+
return true
|
4
|
+
end
|
5
5
|
|
6
6
|
action:
|
7
|
-
|
7
|
+
<runtime_method>.add_statement_at(Statement.new(Return.new, InstanceCallContainer.new(var1.params[var4], StringLength.new)),var1.statement_id)
|
8
8
|
result:
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
if(var1.pass?(var2[var3]))
|
10
|
+
return true
|
11
|
+
end
|
Binary file
|
@@ -1,11 +1,11 @@
|
|
1
1
|
if:
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
if(var1[var2][:params][var2] + var1[var2][:params][var3] == var1[var2][:output])
|
3
|
+
return true
|
4
|
+
end
|
5
5
|
|
6
6
|
action:
|
7
|
-
|
7
|
+
<runtime_method>.add_statement_at(Statement.new(Unknown.new, Equal.new, var4.params[var2], Addition.new, var4.params[var3]),var4.statement_id)
|
8
8
|
result:
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
if(var4.all_pass?(var1))
|
10
|
+
return true
|
11
|
+
end
|
Binary file
|
@@ -1,20 +1,20 @@
|
|
1
1
|
if:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
if(var2[var3].kind_of?(CTestCase))
|
3
|
+
return true
|
4
|
+
end
|
5
|
+
if(var6.kind_of?(Fixnum))
|
6
|
+
return true
|
7
|
+
end
|
8
|
+
if((var2[var3][:params][var6] == var2[var4][:params][var6]) == false)
|
9
|
+
return true
|
10
|
+
end
|
11
11
|
|
12
12
|
action:
|
13
|
-
|
13
|
+
<runtime_method>.add_statement_at(Statement.new(If.new, Container.new(var2[var3][:params][var6], Equivalent.new, var2[var3][:output])),var1.statement_id)
|
14
14
|
result:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
if(var1.history(var2[var3][:params]).any?{ |x| x.statement_id == var1.last.statement_id} )
|
16
|
+
return true
|
17
|
+
end
|
18
|
+
if((var1.history(var2[var4][:params]).any?{ |x| x.statement_id == var1.last.statement_id} ) == false)
|
19
|
+
return true
|
20
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
data/test/ts_complete.rb
CHANGED
@@ -12,7 +12,7 @@ require 'test/unit/core/tc_instance_call_container'
|
|
12
12
|
# require 'test/unit/core/syntax/tc_block_container'
|
13
13
|
# require 'test/unit/core/syntax/tc_if_container'
|
14
14
|
# require 'test/unit/core/declaration/tc_literal_declaration'
|
15
|
-
|
15
|
+
|
16
16
|
require 'test/unit/ruby_code/tc_string'
|
17
17
|
require 'test/unit/ruby_code/tc_fixnum'
|
18
18
|
require 'test/unit/ruby_code/tc_hash'
|
@@ -33,12 +33,6 @@ require 'test/unit/core/statement/tc_statement_group'
|
|
33
33
|
require 'test/unit/core/statement/tc_array_access'
|
34
34
|
require 'test/unit/core/statement/tc_theory_statement'
|
35
35
|
|
36
|
-
require 'test/unit/core/structure/tc_return_structure'
|
37
|
-
require 'test/unit/core/structure/tc_instance_call_container_structure'
|
38
|
-
require 'test/unit/core/structure/tc_declare_new_instance_structure'
|
39
|
-
require 'test/unit/core/structure/tc_declare_variable_as_literal_structure'
|
40
|
-
require 'test/unit/core/structure/tc_declare_variable_as_variable_structure'
|
41
|
-
|
42
36
|
require 'test/unit/core/tracking/tc_history'
|
43
37
|
require 'test/unit/core/tracking/tc_step'
|
44
38
|
|
@@ -66,12 +60,9 @@ require 'test/unit/theory/tc_theory_implementation'
|
|
66
60
|
# require 'test/unit/theory/tc_theory_chain_validator'
|
67
61
|
require 'test/unit/theory/tc_theory_action_implementation'
|
68
62
|
|
69
|
-
require 'test/unit/tc_instance_call_structure'
|
70
63
|
require 'test/unit/tc_instance_call'
|
71
64
|
require 'test/unit/tc_method_usage'
|
72
65
|
require 'test/unit/tc_runtime_tracking_method'
|
73
|
-
require 'test/unit/core/statement/tc_statement_dependencies'
|
74
|
-
require 'test/unit/tc_statement_structure_2'
|
75
66
|
require 'test/unit/tc_variable_declaration'
|
76
67
|
|
77
68
|
require 'test/tc_describe'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
$LOAD_PATH << File.expand_path('../../../../../lib',__FILE__)
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'cauldron'
|
4
4
|
require 'test/unit'
|
5
5
|
|
6
6
|
class TestRuntimeMethod < Test::Unit::TestCase
|
@@ -256,7 +256,9 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
256
256
|
tracking_method = RuntimeTrackingMethod.new(instance_tracking_variable)
|
257
257
|
|
258
258
|
# Trackify it and check nothing is raised
|
259
|
-
assert_nothing_raised(){
|
259
|
+
assert_nothing_raised(){
|
260
|
+
string_runtime_method.trackify(ParametersContainer.new('Manny'.to_var),tracking_method)
|
261
|
+
}
|
260
262
|
|
261
263
|
# Check that the method is unchanged after trackify
|
262
264
|
assert_equal(original_written,string_runtime_method.write)
|
@@ -318,8 +320,8 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
318
320
|
}
|
319
321
|
realised_instance_1 = simple_method.realise2(['Grim','fandango','Threepwood'])
|
320
322
|
assert_equal(
|
321
|
-
"\n#\n
|
322
|
-
"
|
323
|
+
"\n#\n# @param [StringVariable] 'Grim'\n# @param [StringVariable] 'fandango'\n" \
|
324
|
+
"# @param [StringVariable] 'Threepwood'\n#\n#\n" \
|
323
325
|
"def method_0(var_#{simple_method.usage[0].variable_id}, var_#{simple_method.usage[1].variable_id}, var_#{simple_method.usage[2].variable_id})\n\nend\n",
|
324
326
|
realised_instance_1.write
|
325
327
|
)
|
@@ -342,9 +344,9 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
342
344
|
simple_method.push(Statement.new(var_c,Equal.new,InstanceCallContainer.new(var_a,StringLength.new)))
|
343
345
|
realised_instance_2 = simple_method.realise2(['Grim','fandango','Threepwood'])
|
344
346
|
assert_equal(
|
345
|
-
"\n#\n
|
347
|
+
"\n#\n# @param [StringVariable] 'Grim'\n# @param [StringVariable] 'fandango'\n# @param [StringVariable] 'Threepwood'\n#\n#\n"\
|
346
348
|
"def method_0(var_#{simple_method.usage[0].variable_id}, var_#{simple_method.usage[1].variable_id}, var_#{simple_method.usage[2].variable_id})"\
|
347
|
-
"\n
|
349
|
+
"\n var_64 = var_35.length\nend\n",
|
348
350
|
realised_instance_2.write
|
349
351
|
)
|
350
352
|
|
@@ -354,11 +356,11 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
354
356
|
simple_method_written_3 = simple_method.write
|
355
357
|
realised_simple_method_3 = simple_method.realise2(['Grim','fandango','Threepwood'])
|
356
358
|
assert_equal(
|
357
|
-
"\n#\n
|
358
|
-
"
|
359
|
-
"
|
359
|
+
"\n#\n# @param [StringVariable] 'Grim'\n"\
|
360
|
+
"# @param [StringVariable] 'fandango'\n"\
|
361
|
+
"# @param [StringVariable] 'Threepwood'\n"\
|
360
362
|
"#\n#\ndef method_0(var_#{simple_method.usage[0].variable_id}, var_#{simple_method.usage[1].variable_id}, var_#{simple_method.usage[2].variable_id})\n"\
|
361
|
-
"
|
363
|
+
" var_64 = var_#{simple_method.usage[0].variable_id}.length\n var_76 = var_#{simple_method.usage[0].variable_id}.chop\nend\n",
|
362
364
|
realised_simple_method_3.write
|
363
365
|
)
|
364
366
|
|
@@ -377,7 +379,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
377
379
|
simple_method_written_4 = simple_method.write
|
378
380
|
realised_simple_method_4 = simple_method.realise2(['Grim','fandango','Threepwood'])
|
379
381
|
assert_equal(
|
380
|
-
"\n#\n
|
382
|
+
"\n#\n# @param [StringVariable] 'Grim'\n# @param [StringVariable] 'fandango'\n# @param [StringVariable] 'Threepwood'\n#\n#\ndef method_0(var_35, var_36, var_37)\n var_64 = var_35.length\n var_76 = var_35.chop\n var_89 = var_36.length\n var_90 = var_89 + var_64\nend\n",
|
381
383
|
realised_simple_method_4.write
|
382
384
|
)
|
383
385
|
|
@@ -400,7 +402,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
400
402
|
|
401
403
|
# a. Create the method that returns a statement variable
|
402
404
|
return_statement_method = RuntimeMethod.new(MethodUsage.new(),Statement.new.to_var)
|
403
|
-
return_statement_method.push(
|
405
|
+
return_statement_method.push(Parser.run('return Statement.new(Return.new,"sparky")'))
|
404
406
|
|
405
407
|
# b. Create the method
|
406
408
|
runtime_method_2 = RuntimeMethod.new(MethodUsage.new)
|
@@ -437,10 +439,10 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
437
439
|
assert_not_equal("#\n#\ndef method_"+method_example_b.method_id.to_s+"\n\nend\n",method_example_b.write)
|
438
440
|
|
439
441
|
# Test that neested methods are writen properly
|
440
|
-
assert_equal("\n#\n#\ndef method_6\n
|
442
|
+
assert_equal("\n#\n#\ndef method_6\n var_28 = ''\n var_29 = 'x'\n 3.times do |var_30|\n var_28 = var_28 + var_29\n end\n\nend\n",@build_xxx_method.write)
|
441
443
|
|
442
444
|
# Test how the method is written with tabs
|
443
|
-
assert_equal("\n
|
445
|
+
assert_equal("\n #\n #\n def method_6\n var_28 = ''\n var_29 = 'x'\n 3.times do |var_30|\n var_28 = var_28 + var_29\n end\n\n end\n",@build_xxx_method.write(nil,1))
|
444
446
|
|
445
447
|
end
|
446
448
|
|
@@ -510,31 +512,6 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
510
512
|
assert_equal(9,@simple_method.to_var(8,9).uniq_id)
|
511
513
|
|
512
514
|
end
|
513
|
-
|
514
|
-
def test_to_declaration
|
515
|
-
|
516
|
-
# Test the simplest possible runtime method - accepts nothing and returns nothing
|
517
|
-
simple_runtime_method = RuntimeMethod.new(MethodUsage.new,nil.to_var)
|
518
|
-
assert_nothing_raised() {simple_runtime_method.to_declaration}
|
519
|
-
|
520
|
-
# Test a simple runtime method expected to return a literal
|
521
|
-
literal_return_runtime_method = RuntimeMethod.new(MethodUsage.new,56)
|
522
|
-
assert_nothing_raised() {literal_return_runtime_method.to_declaration}
|
523
|
-
|
524
|
-
# Test a simple runtime method that accepts a parameter
|
525
|
-
single_parameter_runtime_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new()),nil)
|
526
|
-
assert_nothing_raised() {single_parameter_runtime_method.to_declaration}
|
527
|
-
|
528
|
-
# Test that a runtime method that contains one statement is duplicated correctly
|
529
|
-
test_3_runtime_method = RuntimeMethod.new(MethodUsage.new)
|
530
|
-
test_3_runtime_method.push Statement.new(Return.new,'Tony')
|
531
|
-
assert_equal('Tony',MethodValidation.new.use_runtime_method(test_3_runtime_method))
|
532
|
-
|
533
|
-
# Create a duplicate of the simple runtime method
|
534
|
-
duplicate_test_3_runtime_method = test_3_runtime_method.to_declaration.evaluate
|
535
|
-
assert_equal('Tony',MethodValidation.new.use_runtime_method(duplicate_test_3_runtime_method))
|
536
|
-
|
537
|
-
end
|
538
515
|
|
539
516
|
def test_abstract_variables_for_tracking_with_some_simple_statement
|
540
517
|
#assert_equal(1,@simple_method.abstract_variables_for_tracking(Parser.run('var4 = "test"')).length)
|
@@ -35,13 +35,13 @@ class TestBlockStatement < Test::Unit::TestCase
|
|
35
35
|
|
36
36
|
def test_write
|
37
37
|
assert_equal("var_0.each do |var_"+@block_variable.variable_id.to_s+"|\nend\n",@each_game.write(0))
|
38
|
-
assert_equal("
|
38
|
+
assert_equal(" var_0.each do |var_1|\n end\n",@each_game.write(1))
|
39
39
|
assert_equal(
|
40
|
-
"var_0.each do |var_"+@populated_loop_block_var.variable_id.to_s+"|\n
|
40
|
+
"var_0.each do |var_"+@populated_loop_block_var.variable_id.to_s+"|\n var_"+@declared_unknown.variable_id.to_s+" = 6\nend\n",
|
41
41
|
@populated_loop.write(0)
|
42
42
|
)
|
43
43
|
assert_equal(
|
44
|
-
"
|
44
|
+
" var_0.each do |var_"+@populated_loop_block_var.variable_id.to_s+"|\n var_"+@declare_six.declared_variable_id.to_s+" = 6\n end\n",
|
45
45
|
@populated_loop.write(1)
|
46
46
|
)
|
47
47
|
end
|
@@ -37,7 +37,7 @@ class TestOpenStatement < Test::Unit::TestCase
|
|
37
37
|
|
38
38
|
# Test that internal statements are properly tabs
|
39
39
|
@simple_open_if_statement << Statement.new(Return.new,True.new)
|
40
|
-
assert_equal("if(#{@simple_if_statement_var.write} == 'Stobart')\n
|
40
|
+
assert_equal("if(#{@simple_if_statement_var.write} == 'Stobart')\n return true\nend" ,@simple_open_if_statement.write)
|
41
41
|
|
42
42
|
end
|
43
43
|
|
@@ -71,9 +71,9 @@ class TestOpenStatement < Test::Unit::TestCase
|
|
71
71
|
|
72
72
|
def test_write_structure_with_simple_examples
|
73
73
|
assert_equal("if(a == b)\nend",Parser.run("if(var1 == var2)\nend").write_structure)
|
74
|
-
assert_equal("if(a == b)\n
|
75
|
-
assert_equal("if(a.chop == b)\n
|
76
|
-
assert_equal("if(a.chop == b)\n
|
74
|
+
assert_equal("if(a == b)\n return c\nend",Parser.run("if(var1 == var2)\nreturn 8\nend").write_structure)
|
75
|
+
assert_equal("if(a.chop == b)\n return c\nend",Parser.run("if(var1.chop == var2)\nreturn 8\nend").write_structure)
|
76
|
+
assert_equal("if(a.chop == b)\n return a.chop\nend", Parser.run("if(var1.chop == var2)\nreturn var1.chop\nend").write_structure)
|
77
77
|
end
|
78
78
|
|
79
79
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
$LOAD_PATH << File.expand_path('../../../../../lib',__FILE__)
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'cauldron'
|
4
4
|
require 'test/unit'
|
5
5
|
|
6
6
|
class TestStatement < Test::Unit::TestCase
|
@@ -212,21 +212,6 @@ class TestStatement < Test::Unit::TestCase
|
|
212
212
|
assert_not_equal(statement.object_id,copied_statement[i].object_id)
|
213
213
|
end
|
214
214
|
|
215
|
-
# Check that the statement_type is maintained for copied statements.
|
216
|
-
statement_1 = Statement.new(@var_a,Equal.new,Literal.new('Daggerfall'))
|
217
|
-
#statement_1.statement_type = StatementStructure::DECLARATION_STATEMENT
|
218
|
-
assert_equal(statement_1.copy.statement_type,statement_1.statement_type)
|
219
|
-
|
220
|
-
end
|
221
|
-
|
222
|
-
# Tests it can identifiy the structure of the statement.
|
223
|
-
#
|
224
|
-
def test_statement_type
|
225
|
-
assert_equal(StatementStructure::DECLARATION_STATEMENT,@statement_b.statement_type)
|
226
|
-
assert_equal(StatementStructure::RETURN_STATEMENT,@return_statement_a.statement_type)
|
227
|
-
|
228
|
-
# Test some poorly structured statements
|
229
|
-
assert_raises(UnknownStatementType){Statement.new(RequirementsVariable.new,RequirementsVariable.new).statement_type}
|
230
215
|
end
|
231
216
|
|
232
217
|
def test_required_variable_ids
|
@@ -314,42 +299,6 @@ class TestStatement < Test::Unit::TestCase
|
|
314
299
|
def test_write
|
315
300
|
|
316
301
|
end
|
317
|
-
|
318
|
-
def test_to_declaration
|
319
|
-
|
320
|
-
# Check that statement returns a declaration statement
|
321
|
-
assert_equal(true,@simple_statement.to_declaration.kind_of?(VariableDeclaration))
|
322
|
-
|
323
|
-
# Check to_declaration command when excluding a variable
|
324
|
-
assert_equal(
|
325
|
-
"Statement.new(var_#{@var_c.variable_id}, Equal.new(), InstanceCallContainer.new(StringVariable.new('Arena'), Chop.new()))",
|
326
|
-
@statement_b.to_declaration([@var_c.variable_id]).write
|
327
|
-
)
|
328
|
-
|
329
|
-
end
|
330
|
-
|
331
|
-
def test_find_all_required_runtime_methods
|
332
|
-
|
333
|
-
# Check that any empty array is returned if there are no runtime methods used
|
334
|
-
assert_equal(0,@simple_statement.find_all_required_runtime_methods.length)
|
335
|
-
|
336
|
-
# 1. Create a statement that calls a runtime method
|
337
|
-
static_statement = Statement.new
|
338
|
-
#static_statement.statement_type = StatementStructure::MISC_STATEMENT
|
339
|
-
return_statement_method = RuntimeMethod.new(MethodUsage.new(),static_statement.to_var)
|
340
|
-
return_statement = Statement.new(Return.new,'sparky')
|
341
|
-
#return_statement.statement_type = StatementStructure::RETURN_STATEMENT
|
342
|
-
return_declaration_statement = Statement.new(Return.new,return_statement.to_declaration )
|
343
|
-
#return_declaration_statement.statement_type = StatementStructure::RETURN_STATEMENT
|
344
|
-
return_statement_method.push(return_declaration_statement)
|
345
|
-
|
346
|
-
# 1a. Create the statement that contains the method call
|
347
|
-
statement_with_method_call = Statement.new(Unknown.new,Equal.new,DefCall.new(static_statement.to_var,return_statement_method))
|
348
|
-
#statement_with_method_call.statement_type = StatementStructure::DECLARATION_STATEMENT
|
349
|
-
assert_equal(1,statement_with_method_call.find_all_required_runtime_methods.length)
|
350
|
-
assert(statement_with_method_call.find_all_required_runtime_methods.kind_of?(Array))
|
351
|
-
|
352
|
-
end
|
353
302
|
|
354
303
|
def test_realise2
|
355
304
|
|
@@ -399,12 +348,8 @@ class TestStatement < Test::Unit::TestCase
|
|
399
348
|
called_runtime_method_3 = RuntimeMethod.new(MethodUsage.new,blank_statement.to_var)
|
400
349
|
|
401
350
|
# b. Create the statement that is returned as a variable.
|
402
|
-
returned_statement_variable = Statement.new(Return.new,'sparky')
|
403
351
|
declared_return_statement_var = Unknown.new
|
404
|
-
|
405
|
-
return_return_statement = Statement.new(Return.new,returned_statement_variable.to_declaration)
|
406
|
-
#return_return_statement.statement_type = StatementStructure::RETURN_STATEMENT
|
407
|
-
#declare_return_statement = StatementStructure::DECLARATION_STATEMENT
|
352
|
+
return_return_statement = Statement.new(Return.new,Parser.run("Statement.new(Return.new,'sparky')"))
|
408
353
|
called_runtime_method_3.push(return_return_statement)
|
409
354
|
|
410
355
|
# c. Create the method that includes a call to "called_runtime_method_3"
|
@@ -430,73 +375,6 @@ class TestStatement < Test::Unit::TestCase
|
|
430
375
|
|
431
376
|
end
|
432
377
|
|
433
|
-
def test_statement_type
|
434
|
-
|
435
|
-
# Test that statement type is saved correctly - even after copying
|
436
|
-
return_statement = Statement.new(Return.new,6.to_literal)
|
437
|
-
#return_statement.statement_type = StatementStructure::RETURN_STATEMENT
|
438
|
-
assert_equal(return_statement.statement_type,StatementStructure::RETURN_STATEMENT)
|
439
|
-
assert_equal(return_statement.copy.statement_type,StatementStructure::RETURN_STATEMENT)
|
440
|
-
|
441
|
-
# Test that return statements can be dynamically identified
|
442
|
-
return_statement_without_statement_type = Statement.new(Return.new,8.to_literal)
|
443
|
-
assert_nothing_raised(){return_statement_without_statement_type.statement_type}
|
444
|
-
assert_equal(return_statement_without_statement_type.statement_type,StatementStructure::RETURN_STATEMENT)
|
445
|
-
|
446
|
-
end
|
447
|
-
|
448
|
-
def test_replace_variable_if
|
449
|
-
|
450
|
-
# Create a simple statement will have it's variable replaced
|
451
|
-
# unknown = 7
|
452
|
-
statement_a_unknown = Unknown.new
|
453
|
-
statement_a = Statement.new(statement_a_unknown,Equal.new,7.to_literal)
|
454
|
-
assert(statement_a.first.kind_of?(Unknown))
|
455
|
-
modified_statement_a = statement_a.replace_variable_if(FixnumVariable.new(7)) {|x| x.uniq_id == statement_a_unknown.uniq_id }
|
456
|
-
assert(modified_statement_a.first.kind_of?(FixnumVariable))
|
457
|
-
|
458
|
-
# Create a statement with an instance call container
|
459
|
-
# unknown = 'test'.chop
|
460
|
-
statement_b_unknown = Unknown.new
|
461
|
-
statement_b = Statement.new(Unknown.new,Equal.new,InstanceCallContainer.new(statement_b_unknown,Chop.new))
|
462
|
-
modified_statement_b = statement_b.replace_variable_if('test'.to_var) do |x|
|
463
|
-
x.uniq_id == statement_b_unknown.uniq_id
|
464
|
-
end
|
465
|
-
assert(modified_statement_b.kind_of?(Statement))
|
466
|
-
assert_equal(3,modified_statement_b.length)
|
467
|
-
assert_not_equal(modified_statement_b[2].subject.variable_id,statement_b_unknown.variable_id)
|
468
|
-
|
469
|
-
# Create a statement with parameters in the statement
|
470
|
-
# ['goo'].push('jon')
|
471
|
-
statement_c_unknown = Unknown.new
|
472
|
-
statement_c = Statement.new(InstanceCallContainer.new(['goo'].to_var,Push.new,statement_c_unknown))
|
473
|
-
modified_statement_c = statement_c.replace_variable_if('jon'.to_var) do |x|
|
474
|
-
x.uniq_id == statement_c_unknown.uniq_id
|
475
|
-
end
|
476
|
-
assert(modified_statement_c.kind_of?(Statement))
|
477
|
-
assert_not_equal(modified_statement_c[0][0].uniq_id,statement_c_unknown.uniq_id)
|
478
|
-
|
479
|
-
# Create a statement with no matches
|
480
|
-
# unknown = 5 + 6
|
481
|
-
statement_d = Statement.new(Unknown.new,Equal.new,5.to_var,Addition.new,6.to_var)
|
482
|
-
modified_statement_d = statement_d.replace_variable_if('jon'.to_var) do |x|
|
483
|
-
x.uniq_id == 21312
|
484
|
-
end
|
485
|
-
assert_equal(statement_d.write,modified_statement_d.write)
|
486
|
-
|
487
|
-
# Create an instance call statement with no matches
|
488
|
-
# unknown = var_a.length
|
489
|
-
statement_e = Statement.new(Unknown.new,Equal.new,InstanceCallContainer.new('richardson'.to_var,StringLength.new))
|
490
|
-
modified_statement_e = statement_e.replace_variable_if('jon'.to_var) do |x|
|
491
|
-
if x.uniq_id == 3242
|
492
|
-
next true
|
493
|
-
end
|
494
|
-
false
|
495
|
-
end
|
496
|
-
assert_equal(statement_e.write,modified_statement_e.write)
|
497
|
-
|
498
|
-
end
|
499
|
-
|
500
378
|
def test_find_actual_variable
|
501
379
|
|
502
380
|
# 1. Check that the actual variable is returned from a statement
|
@@ -535,29 +413,6 @@ class TestStatement < Test::Unit::TestCase
|
|
535
413
|
|
536
414
|
end
|
537
415
|
|
538
|
-
def test_exchange_variables
|
539
|
-
|
540
|
-
# Create a statement that includes a method variable and is replaced by a different variable
|
541
|
-
method_variable_1 = MethodParameter.new
|
542
|
-
unknown_variable_1 = Unknown.new
|
543
|
-
statement_1 = Statement.new(unknown_variable_1,Equal.new,InstanceCallContainer.new(method_variable_1,Chop.new))
|
544
|
-
pip = 'pip'.to_var
|
545
|
-
conversions = Hash.new()
|
546
|
-
conversions[method_variable_1.variable_id.to_s.to_sym] = pip.copy
|
547
|
-
assert(statement_1.exchange_variables(conversions).kind_of?(Statement))
|
548
|
-
assert_nothing_raised(){statement_1.exchange_variables(conversions).to_literal_string}
|
549
|
-
assert_equal(
|
550
|
-
'var_'+unknown_variable_1.variable_id.to_s+' = var_'+pip.variable_id.to_s+'.chop',
|
551
|
-
statement_1.exchange_variables(conversions).write
|
552
|
-
)
|
553
|
-
|
554
|
-
# Create a statement that modifies an existing variable.
|
555
|
-
|
556
|
-
|
557
|
-
# TODO Test with the same variable used twice in a statement e.g. var_a = var_b+var_b
|
558
|
-
|
559
|
-
end
|
560
|
-
|
561
416
|
def test_creates_variable?
|
562
417
|
|
563
418
|
# Check that a declaration statement creates a variable
|