cauldron 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +51 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +16 -3
- data/Rakefile +94 -92
- data/VERSION +1 -1
- data/bin/cauldron +2 -2
- data/cauldron.gemspec +15 -451
- data/features/cauldron_new_approach.feature +46 -0
- data/features/step_definitions/cauldron_steps.rb +11 -0
- data/features/step_definitions/terminal_steps.rb +0 -2
- data/features/support/env.rb +11 -1
- data/features/support/hooks.rb +5 -0
- data/lib/cauldron.rb +13 -7
- data/lib/cauldron/array_reverse_operator.rb +39 -0
- data/lib/cauldron/concat_operator.rb +34 -0
- data/lib/cauldron/if_relationship.rb +37 -0
- data/lib/cauldron/numeric_operator.rb +45 -0
- data/lib/cauldron/pot.rb +54 -162
- data/lib/cauldron/relationship.rb +5 -0
- data/lib/cauldron/terminal.rb +4 -60
- data/lib/cauldron/version.rb +3 -0
- data/lib/core/string.rb +21 -0
- data/sandbox.rb +27 -6
- data/spec/cauldron/array_reverse_operator_spec.rb +59 -0
- data/spec/cauldron/concat_operator_spec.rb +89 -0
- data/spec/cauldron/if_relationship_spec.rb +25 -0
- data/spec/cauldron/numeric_operator_spec.rb +70 -0
- data/spec/cauldron/pot_spec.rb +81 -151
- data/spec/cauldron/terminal_spec.rb +1 -39
- data/spec/examples/adding_if_statement.yml +13 -0
- data/spec/examples/simple_head_theory.txt +13 -0
- data/spec/spec_helper.rb +1 -14
- data/tasks/theory_tasks.rake +207 -207
- metadata +92 -532
- data/cauldron/.autotest +0 -23
- data/cauldron/History.txt +0 -6
- data/cauldron/Manifest.txt +0 -8
- data/cauldron/README.txt +0 -57
- data/cauldron/Rakefile +0 -27
- data/cauldron/bin/cauldron +0 -3
- data/cauldron/lib/cauldron.rb +0 -3
- data/cauldron/test/test_cauldron.rb +0 -8
- data/features/cauldron_example_cases.feature +0 -13
- data/features/cauldron_generates_runtime_method.feature +0 -16
- data/features/cauldron_generates_single_paramter_methods.feature +0 -25
- data/features/cauldron_interactive_start_terminal.feature +0 -17
- data/features/cauldron_quit_terminal.feature +0 -9
- data/features/cauldron_start_terminal.feature +0 -12
- data/features/support/method_1.example +0 -3
- data/features/support/method_2.example +0 -6
- data/lib/Chain.rb +0 -771
- data/lib/ChainMapping.rb +0 -172
- data/lib/CodeHandler.rb +0 -513
- data/lib/Mapping.rb +0 -27
- data/lib/MappingValues.rb +0 -24
- data/lib/PartialChain.rb +0 -253
- data/lib/Theory.rb +0 -295
- data/lib/UnifiedChain.rb +0 -351
- data/lib/cauldron/conversion.rb +0 -15
- data/lib/cauldron/demos.rb +0 -280
- data/lib/cauldron/env.rb +0 -1
- data/lib/cauldron/sexp2cauldron.rb +0 -139
- data/lib/cauldron/theory_factory.rb +0 -10
- data/lib/cauldron/util/home.rb +0 -21
- data/lib/cauldron/util/saver.rb +0 -45
- data/lib/core/ActsAsCode.rb +0 -25
- data/lib/core/BlockToken.rb +0 -33
- data/lib/core/CCall.rb +0 -7
- data/lib/core/CTestCase.rb +0 -27
- data/lib/core/ClassMethodCallContainer.rb +0 -58
- data/lib/core/Container.rb +0 -95
- data/lib/core/InstanceCallContainer.rb +0 -298
- data/lib/core/MethodUsage.rb +0 -65
- data/lib/core/PrintVariables.rb +0 -25
- data/lib/core/TheoryGenerator.rb +0 -753
- data/lib/core/Token.rb +0 -7
- data/lib/core/assignment/Assignment.rb +0 -18
- data/lib/core/assignment/Equal.rb +0 -39
- data/lib/core/assignment/Equivalent.rb +0 -20
- data/lib/core/assignment/NotEqual.rb +0 -14
- data/lib/core/call_container/CallContainer.rb +0 -72
- data/lib/core/class_method_call/New.rb +0 -15
- data/lib/core/class_method_call/RuntimeClassMethodCall.rb +0 -31
- data/lib/core/declaration/Declaration.rb +0 -16
- data/lib/core/declaration/LiteralDeclaration.rb +0 -47
- data/lib/core/declaration/VariableDeclaration.rb +0 -59
- data/lib/core/instance_call/ArrayEach.rb +0 -23
- data/lib/core/instance_call/ArrayLength.rb +0 -15
- data/lib/core/instance_call/Chop.rb +0 -19
- data/lib/core/instance_call/Copy.rb +0 -22
- data/lib/core/instance_call/DeclaredVariable.rb +0 -18
- data/lib/core/instance_call/InstanceCall.rb +0 -77
- data/lib/core/instance_call/Params.rb +0 -15
- data/lib/core/instance_call/Push.rb +0 -20
- data/lib/core/instance_call/StringLength.rb +0 -32
- data/lib/core/instance_call/Times.rb +0 -20
- data/lib/core/instance_call/instance_calls.rb +0 -176
- data/lib/core/instance_call/length_equal.rb +0 -15
- data/lib/core/kernal/EvalCall.rb +0 -15
- data/lib/core/kernal/LocalVariablesCall.rb +0 -15
- data/lib/core/literal/Literal.rb +0 -111
- data/lib/core/literal/Raw.rb +0 -23
- data/lib/core/literal/RuntimeMethodLiteral.rb +0 -21
- data/lib/core/literal/StatementLiteral.rb +0 -28
- data/lib/core/method_call/AvailableVariablesCall.rb +0 -25
- data/lib/core/method_call/ClassCall.rb +0 -33
- data/lib/core/method_call/DefCall.rb +0 -72
- data/lib/core/method_call/EvaluateClassCall.rb +0 -29
- data/lib/core/method_call/MethodNameCall.rb +0 -27
- data/lib/core/method_call/ToDeclarationCall.rb +0 -15
- data/lib/core/requirement/Requirement.rb +0 -292
- data/lib/core/runtime_class/ArrayClass.rb +0 -19
- data/lib/core/runtime_class/ClassCallClass.rb +0 -23
- data/lib/core/runtime_class/ClassEvaluationClass.rb +0 -19
- data/lib/core/runtime_class/ClassName.rb +0 -18
- data/lib/core/runtime_class/DefCallClass.rb +0 -21
- data/lib/core/runtime_class/EqualClass.rb +0 -19
- data/lib/core/runtime_class/FixnumClass.rb +0 -15
- data/lib/core/runtime_class/InstanceCallClass.rb +0 -19
- data/lib/core/runtime_class/InstanceCallContainerClass.rb +0 -16
- data/lib/core/runtime_class/InstanceClassCallClass.rb +0 -19
- data/lib/core/runtime_class/LiteralClass.rb +0 -19
- data/lib/core/runtime_class/MethodParameterClass.rb +0 -27
- data/lib/core/runtime_class/MethodUsageClass.rb +0 -27
- data/lib/core/runtime_class/RequirementClass.rb +0 -19
- data/lib/core/runtime_class/ReturnClass.rb +0 -21
- data/lib/core/runtime_class/RuntimeClass.rb +0 -30
- data/lib/core/runtime_class/RuntimeClassClass.rb +0 -19
- data/lib/core/runtime_class/RuntimeMethodClass.rb +0 -34
- data/lib/core/runtime_class/StatementClass.rb +0 -53
- data/lib/core/runtime_class/StringClass.rb +0 -23
- data/lib/core/runtime_class/StringLengthClass.rb +0 -19
- data/lib/core/runtime_class/StringVariableClass.rb +0 -19
- data/lib/core/runtime_class/ThisClass.rb +0 -15
- data/lib/core/runtime_class/UnknownClass.rb +0 -23
- data/lib/core/runtime_class/class_names.rb +0 -95
- data/lib/core/runtime_class/runtime_class.rb +0 -123
- data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +0 -293
- data/lib/core/runtime_method/ParametersContainer.rb +0 -29
- data/lib/core/runtime_method/RealisedRuntimeMethod.rb +0 -94
- data/lib/core/runtime_method/RuntimeMethod.rb +0 -814
- data/lib/core/runtime_method/WriteParameters.rb +0 -35
- data/lib/core/statement/ActsAsStatement.rb +0 -20
- data/lib/core/statement/ArrayAccess.rb +0 -122
- data/lib/core/statement/BlockStatement.rb +0 -348
- data/lib/core/statement/DeclarationStatement.rb +0 -19
- data/lib/core/statement/HackStatement.rb +0 -25
- data/lib/core/statement/HashAccess.rb +0 -18
- data/lib/core/statement/OpenStatement.rb +0 -178
- data/lib/core/statement/RealisedStatement.rb +0 -5
- data/lib/core/statement/SingleLineBlockStatement.rb +0 -39
- data/lib/core/statement/Statement.rb +0 -1091
- data/lib/core/statement/StatementGroup.rb +0 -157
- data/lib/core/statement/StatementStructure2.rb +0 -224
- data/lib/core/statement/TheoryStatement.rb +0 -68
- data/lib/core/statement/TopologicalStatements.rb +0 -34
- data/lib/core/syntax/Addition.rb +0 -26
- data/lib/core/syntax/BlockContainer.rb +0 -102
- data/lib/core/syntax/Boolean.rb +0 -15
- data/lib/core/syntax/Code.rb +0 -11
- data/lib/core/syntax/Do.rb +0 -20
- data/lib/core/syntax/False.rb +0 -12
- data/lib/core/syntax/If.rb +0 -36
- data/lib/core/syntax/Nil.rb +0 -15
- data/lib/core/syntax/Return.rb +0 -33
- data/lib/core/syntax/Subtract.rb +0 -19
- data/lib/core/syntax/This.rb +0 -40
- data/lib/core/syntax/True.rb +0 -20
- data/lib/core/syntax/syntax.rb +0 -24
- data/lib/core/tracking/ActsAsTrackable.rb +0 -65
- data/lib/core/tracking/History.rb +0 -167
- data/lib/core/tracking/RuntimeTrackingMethod.rb +0 -32
- data/lib/core/tracking/Step.rb +0 -52
- data/lib/core/variable/ArrayVariable.rb +0 -76
- data/lib/core/variable/BaseVariable.rb +0 -152
- data/lib/core/variable/BlockVariable.rb +0 -92
- data/lib/core/variable/FixnumVariable.rb +0 -35
- data/lib/core/variable/HistoryVariable.rb +0 -8
- data/lib/core/variable/MethodParameter.rb +0 -179
- data/lib/core/variable/MethodUsageVariable.rb +0 -60
- data/lib/core/variable/NilVariable.rb +0 -29
- data/lib/core/variable/RuntimeMethodParameter.rb +0 -67
- data/lib/core/variable/StatementVariable.rb +0 -72
- data/lib/core/variable/StepVariable.rb +0 -7
- data/lib/core/variable/StringVariable.rb +0 -46
- data/lib/core/variable/TypeVariable.rb +0 -72
- data/lib/core/variable/Unknown.rb +0 -102
- data/lib/core/variable/UnknownVariable.rb +0 -29
- data/lib/core/variable/Variable.rb +0 -70
- data/lib/core/variable/VariableContainer.rb +0 -28
- data/lib/core/variable/VariableIncluded.rb +0 -27
- data/lib/core/variable/VariableReference.rb +0 -85
- data/lib/error/FailedToFindStatementContainerError.rb +0 -7
- data/lib/error/FailedToFindStatementError.rb +0 -7
- data/lib/error/FailedToFindVariableError.rb +0 -7
- data/lib/error/FailedToLiteraliseError.rb +0 -7
- data/lib/error/FailedVariableMatch.rb +0 -7
- data/lib/error/ImproperStatementUsageError.rb +0 -7
- data/lib/error/IncompatiableRequirementsError.rb +0 -7
- data/lib/error/InvalidStatementError.rb +0 -7
- data/lib/error/MethodSizeError.rb +0 -7
- data/lib/error/RuntimeSyntaxError.rb +0 -7
- data/lib/error/UnexpectedStatementTypeError.rb +0 -7
- data/lib/error/UnknownStatementType.rb +0 -7
- data/lib/error/UnliteralisableError.rb +0 -7
- data/lib/implemented_chain.rb +0 -35
- data/lib/intrinsic/IntrinsicLastRuntimeMethod.rb +0 -20
- data/lib/intrinsic/IntrinsicLiteral.rb +0 -26
- data/lib/intrinsic/IntrinsicObject.rb +0 -22
- data/lib/intrinsic/IntrinsicRuntimeMethod.rb +0 -27
- data/lib/intrinsic/IntrinsicTestCases.rb +0 -17
- data/lib/logger/StandardLogger.rb +0 -62
- data/lib/required.rb +0 -222
- data/lib/ruby_code/Array.rb +0 -95
- data/lib/ruby_code/Fixnum.rb +0 -39
- data/lib/ruby_code/Hash.rb +0 -25
- data/lib/ruby_code/NilClass.rb +0 -19
- data/lib/ruby_code/Object.rb +0 -24
- data/lib/ruby_code/String.rb +0 -63
- data/lib/ruby_code/Symbol.rb +0 -7
- data/lib/standard_library/Tasks.rb +0 -12
- data/lib/theories.rb +0 -166
- data/lib/theory/ActionImplementation.rb +0 -17
- data/lib/theory/TheoryAction.rb +0 -100
- data/lib/theory/TheoryChainValidator.rb +0 -103
- data/lib/theory/TheoryComponent.rb +0 -59
- data/lib/theory/TheoryConnector.rb +0 -756
- data/lib/theory/TheoryDependent.rb +0 -135
- data/lib/theory/TheoryImplementation.rb +0 -75
- data/lib/theory/TheoryResult.rb +0 -131
- data/lib/theory/TheoryVariable.rb +0 -63
- data/lib/theory/theory_collection.rb +0 -62
- data/lib/util/ClassEvaluation.rb +0 -44
- data/lib/util/CodeEvaluation.rb +0 -39
- data/lib/util/DeclarationStatementEvaluation.rb +0 -32
- data/lib/util/MethodEvaluation.rb +0 -49
- data/lib/util/MethodTester.rb +0 -71
- data/lib/util/MethodValidation.rb +0 -149
- data/lib/util/MethodWriter.rb +0 -66
- data/lib/util/Parser.rb +0 -305
- data/lib/util/StatementCheck.rb +0 -44
- data/lib/util/StringToTheory.rb +0 -142
- data/lib/util/System.rb +0 -8
- data/spec/cauldron/chain_spec.rb +0 -24
- data/spec/cauldron/demos_spec.rb +0 -30
- data/spec/cauldron/runtime_method_spec.rb +0 -92
- data/spec/cauldron/saver_spec.rb +0 -45
- data/spec/cauldron/sexp_2_cauldron_spec.rb +0 -118
- data/spec/cauldron/theory_action_spec.rb +0 -25
- data/spec/cauldron/theory_connector_spec.rb +0 -52
- data/spec/cauldron/theory_spec.rb +0 -59
- data/spec/cauldron/unified_chain_spec.rb +0 -140
- data/test/fixtures/chains/1/declaration.txt +0 -26
- data/test/fixtures/chains/1/dump +0 -0
- data/test/fixtures/chains/2/declaration.txt +0 -26
- data/test/fixtures/chains/2/dump +0 -0
- data/test/fixtures/chains/3/declaration.txt +0 -26
- data/test/fixtures/chains/3/dump +0 -0
- data/test/fixtures/implementation_results/0/declaration.txt +0 -3
- data/test/fixtures/implementation_results/0/dump +0 -0
- data/test/fixtures/theories/0/declaration.txt +0 -9
- data/test/fixtures/theories/0/desc +0 -10
- data/test/fixtures/theories/0/dump +0 -0
- data/test/fixtures/theories/1/declaration.txt +0 -15
- data/test/fixtures/theories/1/desc +0 -11
- data/test/fixtures/theories/1/dump +0 -0
- data/test/fixtures/theories/10/declaration.txt +0 -23
- data/test/fixtures/theories/10/desc +0 -17
- data/test/fixtures/theories/10/dump +0 -0
- data/test/fixtures/theories/11/declaration.txt +0 -20
- data/test/fixtures/theories/11/desc +0 -14
- data/test/fixtures/theories/11/dump +0 -0
- data/test/fixtures/theories/12/declaration.txt +0 -18
- data/test/fixtures/theories/12/desc +0 -12
- data/test/fixtures/theories/12/dump +0 -0
- data/test/fixtures/theories/13/declaration.txt +0 -24
- data/test/fixtures/theories/13/desc +0 -20
- data/test/fixtures/theories/13/dump +0 -0
- data/test/fixtures/theories/14/declaration.txt +0 -26
- data/test/fixtures/theories/14/desc +0 -20
- data/test/fixtures/theories/14/dump +0 -0
- data/test/fixtures/theories/15/declaration.txt +0 -20
- data/test/fixtures/theories/15/desc +0 -14
- data/test/fixtures/theories/15/dump +0 -0
- data/test/fixtures/theories/16/declaration.txt +0 -30
- data/test/fixtures/theories/16/desc +0 -14
- data/test/fixtures/theories/16/dump +0 -0
- data/test/fixtures/theories/17/declaration.txt +0 -25
- data/test/fixtures/theories/17/desc +0 -11
- data/test/fixtures/theories/17/dump +0 -0
- data/test/fixtures/theories/18/declaration.txt +0 -23
- data/test/fixtures/theories/18/desc +0 -11
- data/test/fixtures/theories/18/dump +0 -0
- data/test/fixtures/theories/19/declaration.txt +0 -23
- data/test/fixtures/theories/19/desc +0 -11
- data/test/fixtures/theories/19/dump +0 -0
- data/test/fixtures/theories/2/declaration.txt +0 -12
- data/test/fixtures/theories/2/desc +0 -10
- data/test/fixtures/theories/2/dump +0 -0
- data/test/fixtures/theories/20/declaration.txt +0 -23
- data/test/fixtures/theories/20/desc +0 -17
- data/test/fixtures/theories/20/dump +0 -0
- data/test/fixtures/theories/3/declaration.txt +0 -19
- data/test/fixtures/theories/3/desc +0 -11
- data/test/fixtures/theories/3/dump +0 -0
- data/test/fixtures/theories/4/declaration.txt +0 -11
- data/test/fixtures/theories/4/desc +0 -11
- data/test/fixtures/theories/4/dump +0 -0
- data/test/fixtures/theories/5/declaration.txt +0 -6
- data/test/fixtures/theories/5/desc +0 -9
- data/test/fixtures/theories/5/dump +0 -0
- data/test/fixtures/theories/6/declaration.txt +0 -13
- data/test/fixtures/theories/6/desc +0 -11
- data/test/fixtures/theories/6/dump +0 -0
- data/test/fixtures/theories/7/declaration.txt +0 -19
- data/test/fixtures/theories/7/desc +0 -11
- data/test/fixtures/theories/7/dump +0 -0
- data/test/fixtures/theories/8/declaration.txt +0 -21
- data/test/fixtures/theories/8/desc +0 -11
- data/test/fixtures/theories/8/dump +0 -0
- data/test/fixtures/theories/9/declaration.txt +0 -24
- data/test/fixtures/theories/9/desc +0 -20
- data/test/fixtures/theories/9/dump +0 -0
- data/test/fixtures/theory_implementations/0/declaration.txt +0 -11
- data/test/fixtures/theory_implementations/0/desc.txt +0 -9
- data/test/fixtures/theory_implementations/0/dump +0 -0
- data/test/fixtures/theory_implementations/0/theory_id +0 -1
- data/test/fixtures/theory_implementations/1/declaration.txt +0 -11
- data/test/fixtures/theory_implementations/1/desc.txt +0 -9
- data/test/fixtures/theory_implementations/1/dump +0 -1
- data/test/fixtures/theory_implementations/1/theory_id +0 -1
- data/test/fixtures/theory_implementations/2/declaration.txt +0 -11
- data/test/fixtures/theory_implementations/2/desc.txt +0 -9
- data/test/fixtures/theory_implementations/2/dump +0 -0
- data/test/fixtures/theory_implementations/2/theory_id +0 -1
- data/test/output/simple_method.txt +0 -5
- data/test/output/test_method/first_possible_method.txt +0 -6
- data/test/output/test_simple_cases/simple_case_01.txt +0 -8
- data/test/output/test_simple_cases/simple_case_02.txt +0 -7
- data/test/output/test_simple_cases/simple_case_03.txt +0 -8
- data/test/output/test_simple_cases/simple_case_04.txt +0 -8
- data/test/output/test_simple_cases/simple_case_05.txt +0 -8
- data/test/output/test_simple_cases/simple_case_06.txt +0 -9
- data/test/output/test_simple_cases/simple_case_07.txt +0 -9
- data/test/output/test_simple_cases/simple_case_08.txt +0 -9
- data/test/tc_describe.rb +0 -46
- data/test/tc_method.rb +0 -130
- data/test/tc_requirement.rb +0 -30
- data/test/tc_suite_complete.rb +0 -26
- data/test/tc_variable.rb +0 -52
- data/test/ts_complete.rb +0 -74
- data/test/ts_stable.rb +0 -81
- data/test/unit/core/declaration/tc_literal_declaration.rb +0 -34
- data/test/unit/core/method_call/tc_class_call.rb +0 -20
- data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +0 -132
- data/test/unit/core/runtime_method/tc_runtime_method.rb +0 -546
- data/test/unit/core/statement/tc_array_access.rb +0 -63
- data/test/unit/core/statement/tc_block_statement.rb +0 -53
- data/test/unit/core/statement/tc_hack_statement.rb +0 -26
- data/test/unit/core/statement/tc_open_statement.rb +0 -79
- data/test/unit/core/statement/tc_statement.rb +0 -483
- data/test/unit/core/statement/tc_statement_group.rb +0 -35
- data/test/unit/core/statement/tc_statement_replace_variable.rb +0 -61
- data/test/unit/core/statement/tc_theory_statement.rb +0 -53
- data/test/unit/core/syntax/tc_block_container.rb +0 -32
- data/test/unit/core/syntax/tc_if_container.rb +0 -39
- data/test/unit/core/tc_class_method_call.rb +0 -34
- data/test/unit/core/tc_container.rb +0 -41
- data/test/unit/core/tc_ctest_case.rb +0 -25
- data/test/unit/core/tc_instance_call_container.rb +0 -93
- data/test/unit/core/tc_literal.rb +0 -30
- data/test/unit/core/tc_theory_generator.rb +0 -336
- data/test/unit/core/tc_theory_generator_heavy.rb +0 -42
- data/test/unit/core/tracking/tc_history.rb +0 -104
- data/test/unit/core/tracking/tc_step.rb +0 -65
- data/test/unit/core/variable/tc_array_variable.rb +0 -61
- data/test/unit/core/variable/tc_block_variable.rb +0 -17
- data/test/unit/core/variable/tc_fixnum_variable.rb +0 -54
- data/test/unit/core/variable/tc_method_parameter_variable.rb +0 -22
- data/test/unit/core/variable/tc_runtime_method_variable.rb +0 -32
- data/test/unit/core/variable/tc_string_variable.rb +0 -37
- data/test/unit/core/variable/tc_unknown.rb +0 -24
- data/test/unit/core/variable/tc_variable_reference.rb +0 -28
- data/test/unit/ruby_code/tc_array.rb +0 -64
- data/test/unit/ruby_code/tc_fixnum.rb +0 -18
- data/test/unit/ruby_code/tc_hash.rb +0 -41
- data/test/unit/ruby_code/tc_string.rb +0 -38
- data/test/unit/tc_chain.rb +0 -434
- data/test/unit/tc_chain_mapping.rb +0 -62
- data/test/unit/tc_chain_with_case_1.rb +0 -169
- data/test/unit/tc_instance_call.rb +0 -40
- data/test/unit/tc_method_usage.rb +0 -35
- data/test/unit/tc_pot.rb +0 -124
- data/test/unit/tc_runtime_tracking_method.rb +0 -40
- data/test/unit/tc_theory.rb +0 -531
- data/test/unit/tc_variable_declaration.rb +0 -32
- data/test/unit/theory/tc_theory_action.rb +0 -108
- data/test/unit/theory/tc_theory_action_implementation.rb +0 -23
- data/test/unit/theory/tc_theory_chain_validator.rb +0 -340
- data/test/unit/theory/tc_theory_connector.rb +0 -361
- data/test/unit/theory/tc_theory_dependent.rb +0 -153
- data/test/unit/theory/tc_theory_implementation.rb +0 -137
- data/test/unit/theory/tc_theory_result.rb +0 -112
- data/test/unit/theory/tc_theory_variable.rb +0 -45
- data/test/unit/util/tc_method_validation.rb +0 -101
- data/test/unit/util/tc_parser.rb +0 -110
- data/test/unit/util/tc_string_to_theory.rb +0 -300
- data/test/unit/variable/tc_method_usage_variable.rb +0 -25
- data/tmp/runtime_method_evaluation.rb +0 -16
@@ -1,546 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.expand_path('../../../../../lib',__FILE__)
|
2
|
-
|
3
|
-
require 'cauldron'
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
class TestRuntimeMethod < Test::Unit::TestCase
|
7
|
-
|
8
|
-
def setup
|
9
|
-
|
10
|
-
# Create the method usage
|
11
|
-
@method_var_a = MethodParameter.new
|
12
|
-
# Not used in the method
|
13
|
-
@method_var_b = MethodParameter.new
|
14
|
-
@single_parameter_usage = MethodUsage.new(@method_var_a,@method_var_b)
|
15
|
-
|
16
|
-
# Create the simple method used in the tests
|
17
|
-
@simple_method = RuntimeMethod.new(@single_parameter_usage)
|
18
|
-
|
19
|
-
# Add a few simple statements to the method
|
20
|
-
@var_b = Unknown.new
|
21
|
-
@statement_a = Statement.new(@var_b,Equal.new,Literal.new(9))
|
22
|
-
@var_c = Unknown.new
|
23
|
-
@statement_b = Statement.new(@var_c,Equal.new,InstanceCallContainer.new(@method_var_a,Chop.new))
|
24
|
-
@var_d = Unknown.new
|
25
|
-
@statement_c = Statement.new(@var_d,Equal.new,InstanceCallContainer.new(@var_c,StringLength.new))
|
26
|
-
@var_e = Unknown.new
|
27
|
-
@var_f = Unknown.new
|
28
|
-
@statement_d = Statement.new(@var_e,Equal.new,@var_b,Addition.new,@var_d)
|
29
|
-
@simple_method.push(@statement_a)
|
30
|
-
@simple_method.push(@statement_b)
|
31
|
-
@simple_method.push(@statement_c)
|
32
|
-
@simple_method.push(@statement_d)
|
33
|
-
@simple_method.push(Statement.new(@var_f,Equal.new,InstanceCallContainer.new(@var_c,StringLength.new)))
|
34
|
-
|
35
|
-
# Create a runtime method with no parameters
|
36
|
-
@method_b = RuntimeMethod.new(MethodUsage.new)
|
37
|
-
|
38
|
-
# Create a method that accepts one string parameter and some string parameters to use
|
39
|
-
@method_c = RuntimeMethod.new(MethodUsage.new(MethodParameter.new))
|
40
|
-
@var_g = 'Monkey'.to_var
|
41
|
-
@var_h = 'Island'.to_var
|
42
|
-
@var_i = '3'.to_var
|
43
|
-
|
44
|
-
# The methods all return string variables and have an increasing number of parameters
|
45
|
-
@method_usage_var_a = 'a string'.to_var
|
46
|
-
@method_respnse_a = 'Mass Effect'.to_var
|
47
|
-
@method_d = RuntimeMethod.new(MethodUsage.new(),@method_respnse_a)
|
48
|
-
|
49
|
-
# Create a method that excepts two string parameters
|
50
|
-
@method_usage_var_b = MethodParameter.new()
|
51
|
-
@method_usage_var_c = MethodParameter.new()
|
52
|
-
@method_e = RuntimeMethod.new(MethodUsage.new(@method_usage_var_b,@method_usage_var_c))
|
53
|
-
|
54
|
-
@method_usage_var_e = MethodParameter.new()
|
55
|
-
@method_usage_var_f = MethodParameter.new()
|
56
|
-
@method_respnse_b = 'Halo'.to_var
|
57
|
-
@method_f = RuntimeMethod.new(MethodUsage.new(@method_usage_var_e,@method_usage_var_f),@method_respnse_b)
|
58
|
-
|
59
|
-
# Create the methods to test the runtime methods history call
|
60
|
-
# Simple example
|
61
|
-
# def method_0
|
62
|
-
# var_0 = 'Civilisation'
|
63
|
-
# var_1 = var_0.length
|
64
|
-
# end
|
65
|
-
@method_history_a = RuntimeMethod.new(MethodUsage.new)
|
66
|
-
@var_j = Unknown.new
|
67
|
-
@method_history_a.push( Statement.new(@var_j,Equal.new,Literal.new('Civilisation')) )
|
68
|
-
@method_history_a.push( Statement.new(Unknown.new,Equal.new,InstanceCallContainer.new(@var_j,StringLength.new)) )
|
69
|
-
|
70
|
-
# Create a runtime method that use nested statements
|
71
|
-
# var_0 = ''
|
72
|
-
# var_1 = 'x'
|
73
|
-
# 3.times do |var_2|
|
74
|
-
# var_0 = var_0 + var_1
|
75
|
-
# end
|
76
|
-
#
|
77
|
-
@build_xxx_method = RuntimeMethod.new(MethodUsage.new)
|
78
|
-
@blank_variable = Unknown.new
|
79
|
-
@x_variable = Unknown.new
|
80
|
-
@build_xxx_method.push( Statement.new(@blank_variable,Equal.new,Literal.new('')) )
|
81
|
-
@build_xxx_method.push( Statement.new(@x_variable,Equal.new,Literal.new('x')) )
|
82
|
-
nested_xxx_statement = BlockStatement.new( Statement.new(InstanceCallContainer.new(Literal.new(3),Times.new)) )
|
83
|
-
nested_xxx_statement.push(Statement.new(@blank_variable,Equal.new,@blank_variable,Addition.new,@x_variable) )
|
84
|
-
@build_xxx_method.push( nested_xxx_statement )
|
85
|
-
|
86
|
-
# Create a method that calls a different method
|
87
|
-
@called_method = RuntimeMethod.new(MethodUsage.new)
|
88
|
-
@called_method << Statement.new(Return.new,' Jelly'.to_literal)
|
89
|
-
|
90
|
-
# Create an empty runtime method
|
91
|
-
@empty_rumtime_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new,MethodParameter.new))
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
def teardown
|
96
|
-
System.reset
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_copy
|
100
|
-
|
101
|
-
# Test some basic runtime method instances
|
102
|
-
assert_equal(@statement_d.write,@statement_d.copy.write)
|
103
|
-
assert_equal(@statement_d.write_with_uniq_id,@statement_d.copy.write_with_uniq_id)
|
104
|
-
assert_equal(@build_xxx_method.write,@build_xxx_method.copy.write)
|
105
|
-
assert_equal(@build_xxx_method.write_with_uniq_id,@build_xxx_method.copy.write_with_uniq_id)
|
106
|
-
|
107
|
-
# Check that dependies are found for modified statements
|
108
|
-
# var_a = 8
|
109
|
-
# var_b = []
|
110
|
-
# var_b.push(9)
|
111
|
-
# var_b.push(10)
|
112
|
-
statement_a_1 = Statement.new(Unknown.new,Equal.new,8.to_literal)
|
113
|
-
statement_a_2 = Statement.new(Unknown.new,Equal.new,[].to_literal)
|
114
|
-
statement_a_3 = Statement.new(InstanceCallContainer.new(statement_a_2.first.copy,Push.new,9.to_literal))
|
115
|
-
statement_a_4 = Statement.new(InstanceCallContainer.new(statement_a_3.first.subject.copy,Push.new,10.to_literal))
|
116
|
-
runtime_a = RuntimeMethod.new(MethodUsage.new)
|
117
|
-
runtime_a.push(statement_a_1)
|
118
|
-
runtime_a.push(statement_a_2)
|
119
|
-
runtime_a.push(statement_a_3)
|
120
|
-
runtime_a.push(statement_a_4)
|
121
|
-
assert_equal(runtime_a.write,runtime_a.copy.write)
|
122
|
-
assert_equal(runtime_a.write_with_uniq_id,runtime_a.copy.write_with_uniq_id)
|
123
|
-
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_statement_count
|
128
|
-
assert_equal(5,@simple_method.statement_count)
|
129
|
-
assert_equal(0,@method_b.statement_count)
|
130
|
-
assert_equal(5,@build_xxx_method.statement_count)
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_partial_method
|
134
|
-
|
135
|
-
# Retrieve a partial version of a runtime method and checks the length is correct
|
136
|
-
assert_nothing_raised(){@simple_method.partial_method(3)}
|
137
|
-
assert(@simple_method.partial_method(3).kind_of?(RuntimeMethod))
|
138
|
-
assert(4,@simple_method.partial_method(4).length)
|
139
|
-
|
140
|
-
# Attempt to retrieve a bigger method
|
141
|
-
assert_raises(MethodSizeError){@simple_method.partial_method(@simple_method.length+1)}
|
142
|
-
|
143
|
-
# Retrieve a partial for a method with nested statements
|
144
|
-
assert_nothing_raised(){@build_xxx_method.partial_method(3)}
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
# Tests the method that retrieves all the variables from a particular
|
149
|
-
# method. The variables aren't in the context of the method.
|
150
|
-
#
|
151
|
-
def test_available_variables
|
152
|
-
|
153
|
-
# Check the correct number of variables are returned
|
154
|
-
var_count = 7
|
155
|
-
assert_equal(var_count,@simple_method.available_variables(ParametersContainer.new(@method_var_a,@method_var_b)).length)
|
156
|
-
|
157
|
-
# Check its in the expected order
|
158
|
-
assert_equal(@var_f.variable_id,@simple_method.available_variables(ParametersContainer.new(@method_var_a,@method_var_b)).last.variable_id)
|
159
|
-
|
160
|
-
# Add a dupplicate statement to method and check there are the same number of variables
|
161
|
-
@simple_method.push(@statement_a)
|
162
|
-
assert_equal(var_count,@simple_method.available_variables(ParametersContainer.new(@method_var_a,@method_var_b)).length)
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
# Tests the RuntimeMethods abilitity to identify what comninations
|
167
|
-
# of variables can be used to call this method.
|
168
|
-
#
|
169
|
-
def test_callable_combinations
|
170
|
-
|
171
|
-
# Assert that a method with no parameters only has one call
|
172
|
-
assert_equal(1,@method_b.callable_combinations([]).length)
|
173
|
-
assert(@method_b.callable_combinations([]).last.kind_of?(DefCall))
|
174
|
-
|
175
|
-
# Check the number of methods calls available when only using variables
|
176
|
-
assert_equal(3,@method_c.callable_combinations([@var_g,@var_h,@var_i]).length)
|
177
|
-
assert(@method_c.callable_combinations([@var_g,@var_h,@var_i]).last.kind_of?(DefCall))
|
178
|
-
|
179
|
-
# Check a combination of method calls and runtime methods
|
180
|
-
assert_equal(3,@method_c.callable_combinations([@var_g,@var_h,@var_i]).length)
|
181
|
-
|
182
|
-
# Check using a method that allows muliple parameters
|
183
|
-
assert_equal(9,@method_e.callable_combinations([@var_g,@var_h,@var_i]).length)
|
184
|
-
|
185
|
-
end
|
186
|
-
|
187
|
-
# TODO Need to test with methods that require parameters (var_a) etc
|
188
|
-
def test_history
|
189
|
-
assert_equal(2,@method_history_a.history(ParametersContainer.new)[2]['variables'].length)
|
190
|
-
assert_equal("'Civilisation'",@method_history_a.history(ParametersContainer.new)[1]['variables'].first['value'].write)
|
191
|
-
assert_equal("12",@method_history_a.history(ParametersContainer.new)[2]['variables'].first['value'].write)
|
192
|
-
assert_equal("'Civilisation'",@method_history_a.history(ParametersContainer.new)[2]['variables'].last['value'].write)
|
193
|
-
|
194
|
-
# Check that history retains the correct variable ids
|
195
|
-
manny = 'Manny'.to_var
|
196
|
-
string_runtime_method = RuntimeMethod.new(MethodUsage.new(),nil)
|
197
|
-
|
198
|
-
# Add a statement to the runtime method
|
199
|
-
manny_length_var = Unknown.new
|
200
|
-
|
201
|
-
a_equals_manny_length = Statement.new(manny_length_var,Equal.new,InstanceCallContainer.new(manny,StringLength.new))
|
202
|
-
string_runtime_method.push(a_equals_manny_length)
|
203
|
-
|
204
|
-
# Check that the unknown variable "manny_length_var" retains the correct id
|
205
|
-
assert_nothing_raised() {string_runtime_method.find_variable(manny_length_var.variable_id)}
|
206
|
-
|
207
|
-
# Check that history captures all the expected values.
|
208
|
-
@method_history_a.history(ParametersContainer.new)[1]['variables'].each do |x|
|
209
|
-
assert_not_nil(x['id'])
|
210
|
-
assert_not_nil(x['uniq_id'])
|
211
|
-
end
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
# def method_0(var1)
|
216
|
-
# if(var1=='something')
|
217
|
-
# return 'exists'
|
218
|
-
# end
|
219
|
-
# return 'does not exist'
|
220
|
-
# end
|
221
|
-
#
|
222
|
-
def test_history_case_1
|
223
|
-
|
224
|
-
# Create the runtime that's history will be checked
|
225
|
-
param1 = MethodParameter.new
|
226
|
-
rm = RuntimeMethod.new(MethodUsage.new(param1))
|
227
|
-
statement1 = Parser.run("if(#{param1.write}=='something')\nend")
|
228
|
-
statement1 << Parser.run("return 'exists'")
|
229
|
-
rm << statement1
|
230
|
-
rm << Parser.run("return 'does not exists'")
|
231
|
-
|
232
|
-
assert_nothing_raised(){rm.history2(['akfjlkasd'])}
|
233
|
-
assert_equal(2,rm.history2(['akfjlkasd']).length)
|
234
|
-
assert_equal(2,rm.history2(['something']).length)
|
235
|
-
# TODO Should check what I think statement_id values are are correct
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_trackify
|
240
|
-
|
241
|
-
# Create a simple method to be trackified
|
242
|
-
manny = MethodParameter.new()
|
243
|
-
string_runtime_method = RuntimeMethod.new(MethodUsage.new(manny),nil)
|
244
|
-
|
245
|
-
# Add a statement to the runtime method
|
246
|
-
manny_length_var = Unknown.new
|
247
|
-
a_equals_manny_length = Statement.new(manny_length_var,Equal.new,InstanceCallContainer.new(manny,StringLength.new))
|
248
|
-
string_runtime_method.push(a_equals_manny_length)
|
249
|
-
|
250
|
-
# Save the original written method
|
251
|
-
original_written = string_runtime_method.write
|
252
|
-
|
253
|
-
# Create the method that changes are logged to
|
254
|
-
instance_tracking_variable = ArrayVariable.new
|
255
|
-
instance_tracking_variable.instance_variable = true
|
256
|
-
tracking_method = RuntimeTrackingMethod.new(instance_tracking_variable)
|
257
|
-
|
258
|
-
# Trackify it and check nothing is raised
|
259
|
-
assert_nothing_raised(){
|
260
|
-
string_runtime_method.trackify(ParametersContainer.new('Manny'.to_var),tracking_method)
|
261
|
-
}
|
262
|
-
|
263
|
-
# Check that the method is unchanged after trackify
|
264
|
-
assert_equal(original_written,string_runtime_method.write)
|
265
|
-
|
266
|
-
end
|
267
|
-
|
268
|
-
def test_realise_with_an_empty_runtime_method
|
269
|
-
|
270
|
-
# Check that parameters have the same variable id
|
271
|
-
assert_not_nil(@empty_rumtime_method.usage[0].variable_id)
|
272
|
-
assert_not_nil(@empty_rumtime_method.realise2(['Mia','Elle']).params[0].variable_id)
|
273
|
-
assert_equal(
|
274
|
-
@empty_rumtime_method.usage[0].variable_id,
|
275
|
-
@empty_rumtime_method.realise2(['Mia','Elle']).params[0].variable_id
|
276
|
-
)
|
277
|
-
|
278
|
-
end
|
279
|
-
|
280
|
-
# Checks that a relised method only contrains literal values
|
281
|
-
# and type variables. Each of the type variables should contain
|
282
|
-
# there own literal value.
|
283
|
-
#
|
284
|
-
# TODO Test this nested statements and with variable overwritting.
|
285
|
-
#
|
286
|
-
# TODO When I start to use variable overwriting I need to come up with
|
287
|
-
# a way of identifying equivalence.
|
288
|
-
#
|
289
|
-
# e.g.
|
290
|
-
# var_a = 'test'
|
291
|
-
# var_b = var_a.length
|
292
|
-
#
|
293
|
-
# and
|
294
|
-
#
|
295
|
-
# var_a = 'test'
|
296
|
-
# var_a = var_a.length
|
297
|
-
#
|
298
|
-
# In this situation var_a is the same as var_b. Asides from removing the
|
299
|
-
# availablility of 'var_a'test'.
|
300
|
-
#
|
301
|
-
# Actually it really boils down to creating new variables. So as long as
|
302
|
-
# var_a isn't used the overwrite doesn't matter. I do need keep track of
|
303
|
-
# variations of a variable e.g. var_a(0) var_a(1). The variations are
|
304
|
-
# essential variables in their own right.
|
305
|
-
#
|
306
|
-
def test_realise
|
307
|
-
|
308
|
-
# Create a simple runtime method and check that the paramaters are valid
|
309
|
-
var_a = MethodParameter.new
|
310
|
-
var_b = MethodParameter.new
|
311
|
-
var_g = MethodParameter.new
|
312
|
-
simple_method = RuntimeMethod.new(MethodUsage.new(var_a,var_b,var_g))
|
313
|
-
|
314
|
-
# Check that realise returns an identical runtime method
|
315
|
-
var_a_value = StringVariable.new('Grim')
|
316
|
-
var_b_value = 'fandango'.to_var
|
317
|
-
var_g_value = 'Threepwood'.to_var
|
318
|
-
assert_nothing_raised(){
|
319
|
-
simple_method.realise2(['Grim','fandango','Threepwood'])
|
320
|
-
}
|
321
|
-
realised_instance_1 = simple_method.realise2(['Grim','fandango','Threepwood'])
|
322
|
-
assert_equal(
|
323
|
-
"\n#\n# @param [StringVariable] 'Grim'\n# @param [StringVariable] 'fandango'\n" \
|
324
|
-
"# @param [StringVariable] 'Threepwood'\n#\n#\n" \
|
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",
|
326
|
-
realised_instance_1.write
|
327
|
-
)
|
328
|
-
|
329
|
-
# Check that all the variables are type variables and have a literal value
|
330
|
-
realised_instance_1.available_variables(ParametersContainer.new(var_a_value,var_b_value,var_g_value)).each do |x|
|
331
|
-
assert(x.kind_of?(TypeVariable))
|
332
|
-
end
|
333
|
-
assert(realised_instance_1.available_variables(ParametersContainer.new(var_a_value,var_b_value,var_g_value)).any? {|x| x.value == 'Grim' })
|
334
|
-
assert(realised_instance_1.available_variables(ParametersContainer.new(var_a_value,var_b_value,var_g_value)).any? {|x| x.value == 'fandango' })
|
335
|
-
assert_not_equal(true,realised_instance_1.available_variables(ParametersContainer.new(var_a_value,var_b_value,var_g_value)).any? {|x| x.value == 'WARREN' })
|
336
|
-
|
337
|
-
# Check that invalid paramters and undeclared parameters are caught
|
338
|
-
temp_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new))
|
339
|
-
assert_raises(StandardError) {temp_method.realise2([])}
|
340
|
-
|
341
|
-
# Now let's add a few statements to the method
|
342
|
-
# var_c = var_a.length
|
343
|
-
var_c = Unknown.new
|
344
|
-
simple_method.push(Statement.new(var_c,Equal.new,InstanceCallContainer.new(var_a,StringLength.new)))
|
345
|
-
realised_instance_2 = simple_method.realise2(['Grim','fandango','Threepwood'])
|
346
|
-
assert_equal(
|
347
|
-
"\n#\n# @param [StringVariable] 'Grim'\n# @param [StringVariable] 'fandango'\n# @param [StringVariable] 'Threepwood'\n#\n#\n"\
|
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})"\
|
349
|
-
"\n var_64 = var_35.length\nend\n",
|
350
|
-
realised_instance_2.write
|
351
|
-
)
|
352
|
-
|
353
|
-
# Now lets have a chop instance call as well
|
354
|
-
# var_d = var_a.chop
|
355
|
-
simple_method.push(Statement.new(Unknown.new,Equal.new,InstanceCallContainer.new(var_a,Chop.new)))
|
356
|
-
simple_method_written_3 = simple_method.write
|
357
|
-
realised_simple_method_3 = simple_method.realise2(['Grim','fandango','Threepwood'])
|
358
|
-
assert_equal(
|
359
|
-
"\n#\n# @param [StringVariable] 'Grim'\n"\
|
360
|
-
"# @param [StringVariable] 'fandango'\n"\
|
361
|
-
"# @param [StringVariable] 'Threepwood'\n"\
|
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"\
|
363
|
-
" var_64 = var_#{simple_method.usage[0].variable_id}.length\n var_76 = var_#{simple_method.usage[0].variable_id}.chop\nend\n",
|
364
|
-
realised_simple_method_3.write
|
365
|
-
)
|
366
|
-
|
367
|
-
# Go through each statement and check that there are no unrealised values
|
368
|
-
realised_simple_method_3.each do |x|
|
369
|
-
assert_equal(0,x.unrealised_variables.length)
|
370
|
-
end
|
371
|
-
|
372
|
-
# Try adding a variable that gets defined in a previous statement
|
373
|
-
# var_e = var_b.length
|
374
|
-
# var_f = var_e+var_c
|
375
|
-
var_e = Unknown.new
|
376
|
-
var_f = Unknown.new()
|
377
|
-
simple_method.push(Statement.new(var_e,Equal.new,InstanceCallContainer.new(var_b,StringLength.new)))
|
378
|
-
simple_method.push(Statement.new(var_f,Equal.new,var_e,Addition.new,var_c))
|
379
|
-
simple_method_written_4 = simple_method.write
|
380
|
-
realised_simple_method_4 = simple_method.realise2(['Grim','fandango','Threepwood'])
|
381
|
-
assert_equal(
|
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",
|
383
|
-
realised_simple_method_4.write
|
384
|
-
)
|
385
|
-
|
386
|
-
# Go through and check that there are no unrealised_variables
|
387
|
-
realised_simple_method_4.each do |x|
|
388
|
-
assert_equal(0,x.unrealised_variables.length)
|
389
|
-
end
|
390
|
-
|
391
|
-
# Check that a array variable can be realised
|
392
|
-
var_h = Unknown.new
|
393
|
-
simple_method.push(Statement.new(var_h,Equal.new,InstanceCallContainer.new(var_g,ArrayLength.new)))
|
394
|
-
|
395
|
-
# Check that a block statement can be used
|
396
|
-
nested_statement = BlockStatement.new(Statement.new(InstanceCallContainer.new(var_h,Times.new)))
|
397
|
-
nested_statement.push Statement.new(var_e,Equal.new,var_e,Addition.new,var_f)
|
398
|
-
simple_method.push(nested_statement)
|
399
|
-
|
400
|
-
# 2# Try relising a method that declares a value via another method call
|
401
|
-
# e.g. a method with the statement 'var = method_45'
|
402
|
-
|
403
|
-
# a. Create the method that returns a statement variable
|
404
|
-
return_statement_method = RuntimeMethod.new(MethodUsage.new(),Statement.new.to_var)
|
405
|
-
return_statement_method.push(Parser.run('return Statement.new(Return.new,"sparky")'))
|
406
|
-
|
407
|
-
# b. Create the method
|
408
|
-
runtime_method_2 = RuntimeMethod.new(MethodUsage.new)
|
409
|
-
declared_variable = Unknown.new
|
410
|
-
runtime_method_2.push( Statement.new(declared_variable,Equal.new,DefCall.new(Statement.new.to_var,return_statement_method)))
|
411
|
-
|
412
|
-
# c. Check that the method can't be relised with the called runtime method
|
413
|
-
assert_raises(StandardError) {runtime_method_2.realise2(ParametersContainer.new)}
|
414
|
-
|
415
|
-
# d. Check that the unknow variable has been converted into a StatementVariable
|
416
|
-
assert_nothing_raised() {runtime_method_2.realise2(ParametersContainer.new,[return_statement_method])}
|
417
|
-
assert(runtime_method_2.realise2(ParametersContainer.new,[return_statement_method]).kind_of?(RealisedRuntimeMethod))
|
418
|
-
realised_runtime_method_2 = runtime_method_2.realise2(ParametersContainer.new,[return_statement_method])
|
419
|
-
assert_equal(false,realised_runtime_method_2.find_variable(declared_variable.variable_id).kind_of?(Unknown))
|
420
|
-
|
421
|
-
# Check that value of last variable after it has been realised
|
422
|
-
|
423
|
-
# NEXT Use method calls
|
424
|
-
|
425
|
-
end
|
426
|
-
|
427
|
-
# Test that the runtime methods are written properly.
|
428
|
-
#
|
429
|
-
def test_write
|
430
|
-
|
431
|
-
# Create a simple method with no paramaters
|
432
|
-
method_example_a = RuntimeMethod.new(MethodUsage.new)
|
433
|
-
assert_equal("\n#\n#\ndef method_#{method_example_a.method_id.to_s}\nend\n",method_example_a.write(nil))
|
434
|
-
|
435
|
-
# Test a simple method with one paramter
|
436
|
-
#param_1 = StringVariable.new('Girm')
|
437
|
-
param_1 = MethodParameter.new
|
438
|
-
method_example_b = RuntimeMethod.new(MethodUsage.new(param_1))
|
439
|
-
assert_not_equal("#\n#\ndef method_"+method_example_b.method_id.to_s+"\n\nend\n",method_example_b.write)
|
440
|
-
|
441
|
-
# Test that neested methods are writen properly
|
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)
|
443
|
-
|
444
|
-
# Test how the method is written with tabs
|
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))
|
446
|
-
|
447
|
-
end
|
448
|
-
|
449
|
-
def test_push
|
450
|
-
|
451
|
-
# Create a method that is passed a string
|
452
|
-
#manny = 'Manny'.to_var
|
453
|
-
manny = MethodParameter.new
|
454
|
-
string_runtime_method = RuntimeMethod.new(MethodUsage.new(manny),nil)
|
455
|
-
|
456
|
-
manny_length_var = Unknown.new
|
457
|
-
a_equals_manny_length = Statement.new(manny_length_var,Equal.new,InstanceCallContainer.new(manny_length_var,StringLength.new))
|
458
|
-
string_runtime_method.push(a_equals_manny_length)
|
459
|
-
|
460
|
-
# Check that the variable ids are equal
|
461
|
-
assert_nothing_raised(){string_runtime_method.find_variable(manny_length_var.variable_id)}
|
462
|
-
|
463
|
-
end
|
464
|
-
|
465
|
-
def test_identify_overriding_statements
|
466
|
-
|
467
|
-
# Create a method that is passed a string
|
468
|
-
manny = 'Manny'.to_var
|
469
|
-
# def method_0(var_a)
|
470
|
-
# var_b = var_a.length
|
471
|
-
# var_b.times do |var_c|
|
472
|
-
# var_a = 'Glotis'
|
473
|
-
# end
|
474
|
-
# end
|
475
|
-
string_runtime_method = RuntimeMethod.new(
|
476
|
-
MethodUsage.new(MethodParameter.new),nil
|
477
|
-
)
|
478
|
-
|
479
|
-
manny_length_var = Unknown.new
|
480
|
-
a_equals_manny_length = Statement.new(manny_length_var,Equal.new,InstanceCallContainer.new(manny,StringLength.new))
|
481
|
-
string_runtime_method.push(a_equals_manny_length)
|
482
|
-
|
483
|
-
# Add the first nested statement to the method.
|
484
|
-
manny_length_times = Statement.new(InstanceCallContainer.new(manny_length_var,Times.new))
|
485
|
-
manny_length_times_do = BlockStatement.new(manny_length_times)
|
486
|
-
|
487
|
-
# Override manny with a new string
|
488
|
-
overriding_statement = Statement.new(manny,Equal.new,Literal.new('Glotis'))
|
489
|
-
manny_length_times_do.push( overriding_statement )
|
490
|
-
string_runtime_method.push(manny_length_times_do)
|
491
|
-
|
492
|
-
# Identify all the overridden statements
|
493
|
-
assert_nothing_raised() {string_runtime_method.identify_overriding_statements(ParametersContainer.new(manny))}
|
494
|
-
assert_equal(false,string_runtime_method.find_statement(a_equals_manny_length.statement_id).overrides?)
|
495
|
-
assert_equal(true,string_runtime_method.find_statement(overriding_statement.statement_id).overrides?)
|
496
|
-
|
497
|
-
end
|
498
|
-
|
499
|
-
def test_to_var
|
500
|
-
assert(@simple_method.to_var.kind_of?(RuntimeMethodParameter))
|
501
|
-
|
502
|
-
# Declare the runtime method variable and check it retains the properties of
|
503
|
-
# the original runtime method.
|
504
|
-
simple_method_var = @simple_method.to_var
|
505
|
-
|
506
|
-
# Check the statements are retained
|
507
|
-
assert_equal(@simple_method.length,simple_method_var.value.length)
|
508
|
-
assert_equal(@simple_method.method_id,simple_method_var.value.method_id)
|
509
|
-
|
510
|
-
# Check that variable ids can be set
|
511
|
-
assert_equal(8,@simple_method.to_var(8,9).variable_id)
|
512
|
-
assert_equal(9,@simple_method.to_var(8,9).uniq_id)
|
513
|
-
|
514
|
-
end
|
515
|
-
|
516
|
-
def test_abstract_variables_for_tracking_with_some_simple_statement
|
517
|
-
#assert_equal(1,@simple_method.abstract_variables_for_tracking(Parser.run('var4 = "test"')).length)
|
518
|
-
# TODO The parser doesn't generate a variable with an id of 7 here - is that a problem?
|
519
|
-
assert_equal(2,@simple_method.abstract_variables_for_tracking(Parser.run('var7 = var70.length')).length)
|
520
|
-
end
|
521
|
-
|
522
|
-
def test_all_pass_with_basic_method
|
523
|
-
basic_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new()))
|
524
|
-
basic_method.push(Parser.run('return var'+basic_method.usage.first.variable_id.to_s))
|
525
|
-
test_cases = [
|
526
|
-
{:params=>['sparky'], :output=>'sparky'},
|
527
|
-
{:params=>['pip'], :output=>'pip'},
|
528
|
-
]
|
529
|
-
assert_equal(true,basic_method.all_pass?(test_cases))
|
530
|
-
end
|
531
|
-
|
532
|
-
def test_pass_with_basic_method
|
533
|
-
basic_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new()))
|
534
|
-
basic_method.push(Parser.run('return var'+basic_method.usage.first.variable_id.to_s))
|
535
|
-
assert_equal(true,basic_method.pass?({:params=>['sparky'], :output=>'sparky'}))
|
536
|
-
end
|
537
|
-
|
538
|
-
def test_pass_with_a_method_that_returns_an_integer
|
539
|
-
basic_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new()))
|
540
|
-
basic_method.push(
|
541
|
-
Parser.run("return var#{basic_method.usage.first.variable_id.to_s}.length")
|
542
|
-
)
|
543
|
-
assert_equal(true,basic_method.pass?({:params=>['sparky'], :output=>'sparky'.length}))
|
544
|
-
end
|
545
|
-
|
546
|
-
end
|