cauldron 0.1.0
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.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README +1 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/cauldron +10 -0
- data/cauldron/.autotest +23 -0
- data/cauldron/History.txt +6 -0
- data/cauldron/Manifest.txt +8 -0
- data/cauldron/README.txt +57 -0
- data/cauldron/Rakefile +27 -0
- data/cauldron/bin/cauldron +3 -0
- data/cauldron/lib/cauldron.rb +3 -0
- data/cauldron/test/test_cauldron.rb +8 -0
- data/features/cauldron_example_cases.feature +13 -0
- data/features/cauldron_generates_runtime_method.feature +12 -0
- data/features/cauldron_start_terminal.feature +13 -0
- data/features/step_definitions/cauldron_steps.rb +16 -0
- data/features/step_definitions/terminal_steps.rb +34 -0
- data/features/support/env.rb +19 -0
- data/lib/Chain.rb +879 -0
- data/lib/ChainMapping.rb +172 -0
- data/lib/CodeHandler.rb +517 -0
- data/lib/Mapping.rb +26 -0
- data/lib/MappingValues.rb +24 -0
- data/lib/ScopeDependencies.rb +7 -0
- data/lib/Theory.rb +274 -0
- data/lib/UnifiedChain.rb +110 -0
- data/lib/cauldron.rb +6 -0
- data/lib/cauldron/conversion.rb +15 -0
- data/lib/cauldron/pot.rb +134 -0
- data/lib/cauldron/sexp2cauldron.rb +156 -0
- data/lib/cauldron/terminal.rb +120 -0
- data/lib/cauldron/theory_factory.rb +10 -0
- data/lib/core/ActsAsCode.rb +25 -0
- data/lib/core/BlockToken.rb +33 -0
- data/lib/core/CCall.rb +7 -0
- data/lib/core/CTestCase.rb +27 -0
- data/lib/core/ClassMethodCallContainer.rb +45 -0
- data/lib/core/Container.rb +85 -0
- data/lib/core/InstanceCallContainer.rb +272 -0
- data/lib/core/MethodUsage.rb +66 -0
- data/lib/core/PrintVariables.rb +25 -0
- data/lib/core/TheoryGenerator.rb +764 -0
- data/lib/core/Token.rb +7 -0
- data/lib/core/assignment/Assignment.rb +18 -0
- data/lib/core/assignment/Equal.rb +39 -0
- data/lib/core/assignment/Equivalent.rb +20 -0
- data/lib/core/assignment/NotEqual.rb +14 -0
- data/lib/core/call_container/CallContainer.rb +66 -0
- data/lib/core/class_method_call/New.rb +15 -0
- data/lib/core/class_method_call/RuntimeClassMethodCall.rb +31 -0
- data/lib/core/declaration/Declaration.rb +16 -0
- data/lib/core/declaration/LiteralDeclaration.rb +47 -0
- data/lib/core/declaration/VariableDeclaration.rb +59 -0
- data/lib/core/instance_call/ArrayEach.rb +23 -0
- data/lib/core/instance_call/ArrayLength.rb +15 -0
- data/lib/core/instance_call/Chop.rb +28 -0
- data/lib/core/instance_call/Copy.rb +22 -0
- data/lib/core/instance_call/DeclaredVariable.rb +18 -0
- data/lib/core/instance_call/InstanceCall.rb +77 -0
- data/lib/core/instance_call/Params.rb +15 -0
- data/lib/core/instance_call/Push.rb +20 -0
- data/lib/core/instance_call/StringLength.rb +32 -0
- data/lib/core/instance_call/Times.rb +20 -0
- data/lib/core/instance_call/instance_calls.rb +168 -0
- data/lib/core/instance_call/length_equal.rb +15 -0
- data/lib/core/kernal/EvalCall.rb +15 -0
- data/lib/core/kernal/LocalVariablesCall.rb +15 -0
- data/lib/core/literal/Literal.rb +111 -0
- data/lib/core/literal/Raw.rb +23 -0
- data/lib/core/literal/RuntimeMethodLiteral.rb +21 -0
- data/lib/core/literal/StatementLiteral.rb +28 -0
- data/lib/core/method_call/AvailableVariablesCall.rb +25 -0
- data/lib/core/method_call/ClassCall.rb +33 -0
- data/lib/core/method_call/DefCall.rb +72 -0
- data/lib/core/method_call/EvaluateClassCall.rb +29 -0
- data/lib/core/method_call/MethodNameCall.rb +27 -0
- data/lib/core/method_call/ToDeclarationCall.rb +15 -0
- data/lib/core/requirement/Requirement.rb +291 -0
- data/lib/core/runtime_class/ArrayClass.rb +19 -0
- data/lib/core/runtime_class/ClassCallClass.rb +23 -0
- data/lib/core/runtime_class/ClassEvaluationClass.rb +19 -0
- data/lib/core/runtime_class/ClassName.rb +18 -0
- data/lib/core/runtime_class/DefCallClass.rb +21 -0
- data/lib/core/runtime_class/EqualClass.rb +19 -0
- data/lib/core/runtime_class/FixnumClass.rb +15 -0
- data/lib/core/runtime_class/IfStatementClass.rb +12 -0
- data/lib/core/runtime_class/InstanceCallClass.rb +19 -0
- data/lib/core/runtime_class/InstanceCallContainerClass.rb +16 -0
- data/lib/core/runtime_class/InstanceClassCallClass.rb +19 -0
- data/lib/core/runtime_class/LiteralClass.rb +19 -0
- data/lib/core/runtime_class/MethodParameterClass.rb +27 -0
- data/lib/core/runtime_class/MethodUsageClass.rb +27 -0
- data/lib/core/runtime_class/RequirementClass.rb +19 -0
- data/lib/core/runtime_class/ReturnClass.rb +21 -0
- data/lib/core/runtime_class/RuntimeClass.rb +30 -0
- data/lib/core/runtime_class/RuntimeClassClass.rb +19 -0
- data/lib/core/runtime_class/RuntimeMethodClass.rb +34 -0
- data/lib/core/runtime_class/StatementClass.rb +53 -0
- data/lib/core/runtime_class/StringClass.rb +23 -0
- data/lib/core/runtime_class/StringLengthClass.rb +19 -0
- data/lib/core/runtime_class/StringVariableClass.rb +19 -0
- data/lib/core/runtime_class/ThisClass.rb +15 -0
- data/lib/core/runtime_class/UnknownClass.rb +23 -0
- data/lib/core/runtime_class/class_names.rb +95 -0
- data/lib/core/runtime_class/runtime_class.rb +123 -0
- data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +300 -0
- data/lib/core/runtime_method/ParametersContainer.rb +29 -0
- data/lib/core/runtime_method/RealisedRuntimeMethod.rb +94 -0
- data/lib/core/runtime_method/RuntimeMethod.rb +817 -0
- data/lib/core/runtime_method/WriteParameters.rb +35 -0
- data/lib/core/statement/ActsAsStatement.rb +116 -0
- data/lib/core/statement/ArrayAccess.rb +96 -0
- data/lib/core/statement/BlockStatement.rb +348 -0
- data/lib/core/statement/DeclarationStatement.rb +19 -0
- data/lib/core/statement/HackStatement.rb +25 -0
- data/lib/core/statement/HashAccess.rb +18 -0
- data/lib/core/statement/OpenStatement.rb +171 -0
- data/lib/core/statement/RealisedStatement.rb +5 -0
- data/lib/core/statement/SingleLineBlockStatement.rb +39 -0
- data/lib/core/statement/Statement.rb +1223 -0
- data/lib/core/statement/StatementDependencies.rb +271 -0
- data/lib/core/statement/StatementGroup.rb +157 -0
- data/lib/core/statement/StatementStructure2.rb +224 -0
- data/lib/core/statement/TheoryStatement.rb +60 -0
- data/lib/core/statement/TopologicalStatements.rb +34 -0
- data/lib/core/structure/DeclareNewInstanceStructure.rb +49 -0
- data/lib/core/structure/DeclareRuntimeMethodStructure.rb +34 -0
- data/lib/core/structure/DeclareVariableAsLiteralStructure.rb +31 -0
- data/lib/core/structure/DeclareVariableAsVariableStructure.rb +52 -0
- data/lib/core/structure/FixnumAdditionStructure.rb +56 -0
- data/lib/core/structure/InstanceCallContainerStructure.rb +50 -0
- data/lib/core/structure/InstanceCallStructure.rb +53 -0
- data/lib/core/structure/InstanceMethodCallStructure.rb +21 -0
- data/lib/core/structure/ReturnStructure.rb +20 -0
- data/lib/core/structure/StatementStructure.rb +11 -0
- data/lib/core/syntax/Addition.rb +25 -0
- data/lib/core/syntax/BlockContainer.rb +130 -0
- data/lib/core/syntax/Boolean.rb +15 -0
- data/lib/core/syntax/Code.rb +11 -0
- data/lib/core/syntax/Do.rb +20 -0
- data/lib/core/syntax/False.rb +12 -0
- data/lib/core/syntax/If.rb +28 -0
- data/lib/core/syntax/IfContainer.rb +100 -0
- data/lib/core/syntax/Nil.rb +15 -0
- data/lib/core/syntax/Return.rb +33 -0
- data/lib/core/syntax/Subtract.rb +19 -0
- data/lib/core/syntax/This.rb +40 -0
- data/lib/core/syntax/True.rb +20 -0
- data/lib/core/syntax/syntax.rb +24 -0
- data/lib/core/tracking/ActsAsTrackable.rb +65 -0
- data/lib/core/tracking/History.rb +167 -0
- data/lib/core/tracking/RuntimeTrackingMethod.rb +32 -0
- data/lib/core/tracking/Step.rb +52 -0
- data/lib/core/variable/ArrayVariable.rb +76 -0
- data/lib/core/variable/BaseVariable.rb +154 -0
- data/lib/core/variable/BlockVariable.rb +92 -0
- data/lib/core/variable/FixnumVariable.rb +36 -0
- data/lib/core/variable/HistoryVariable.rb +8 -0
- data/lib/core/variable/MethodParameter.rb +206 -0
- data/lib/core/variable/MethodUsageVariable.rb +60 -0
- data/lib/core/variable/NilVariable.rb +29 -0
- data/lib/core/variable/RuntimeMethodParameter.rb +67 -0
- data/lib/core/variable/StatementVariable.rb +72 -0
- data/lib/core/variable/StepVariable.rb +7 -0
- data/lib/core/variable/StringVariable.rb +46 -0
- data/lib/core/variable/TypeVariable.rb +72 -0
- data/lib/core/variable/Unknown.rb +116 -0
- data/lib/core/variable/UnknownVariable.rb +29 -0
- data/lib/core/variable/Variable.rb +70 -0
- data/lib/core/variable/VariableContainer.rb +28 -0
- data/lib/core/variable/VariableIncluded.rb +27 -0
- data/lib/core/variable/VariableReference.rb +85 -0
- data/lib/error/FailedToFindStatementContainerError.rb +7 -0
- data/lib/error/FailedToFindStatementError.rb +7 -0
- data/lib/error/FailedToFindVariableError.rb +7 -0
- data/lib/error/FailedToLiteraliseError.rb +7 -0
- data/lib/error/FailedVariableMatch.rb +7 -0
- data/lib/error/ImproperStatementUsageError.rb +7 -0
- data/lib/error/IncompatiableRequirementsError.rb +7 -0
- data/lib/error/InvalidStatementError.rb +7 -0
- data/lib/error/MethodSizeError.rb +7 -0
- data/lib/error/RuntimeSyntaxError.rb +7 -0
- data/lib/error/UnexpectedStatementTypeError.rb +7 -0
- data/lib/error/UnknownStatementType.rb +7 -0
- data/lib/error/UnliteralisableError.rb +7 -0
- data/lib/implemented_chain.rb +34 -0
- data/lib/intrinsic/IntrinsicLastRuntimeMethod.rb +20 -0
- data/lib/intrinsic/IntrinsicLiteral.rb +26 -0
- data/lib/intrinsic/IntrinsicObject.rb +22 -0
- data/lib/intrinsic/IntrinsicRuntimeMethod.rb +27 -0
- data/lib/intrinsic/IntrinsicTestCases.rb +17 -0
- data/lib/logger/StandardLogger.rb +62 -0
- data/lib/required.rb +236 -0
- data/lib/ruby_code/Array.rb +95 -0
- data/lib/ruby_code/Fixnum.rb +39 -0
- data/lib/ruby_code/Hash.rb +25 -0
- data/lib/ruby_code/NilClass.rb +19 -0
- data/lib/ruby_code/Object.rb +24 -0
- data/lib/ruby_code/String.rb +86 -0
- data/lib/ruby_code/Symbol.rb +7 -0
- data/lib/standard_library/Tasks.rb +12 -0
- data/lib/theories.rb +143 -0
- data/lib/theory/ActionImplementation.rb +17 -0
- data/lib/theory/TheoryAction.rb +70 -0
- data/lib/theory/TheoryChainValidator.rb +101 -0
- data/lib/theory/TheoryComponent.rb +42 -0
- data/lib/theory/TheoryConnector.rb +755 -0
- data/lib/theory/TheoryDependent.rb +135 -0
- data/lib/theory/TheoryImplementation.rb +74 -0
- data/lib/theory/TheoryResult.rb +131 -0
- data/lib/theory/TheoryVariable.rb +63 -0
- data/lib/theory/theory_collection.rb +62 -0
- data/lib/util/ClassEvaluation.rb +68 -0
- data/lib/util/CodeEvaluation.rb +35 -0
- data/lib/util/DeclarationStatementEvaluation.rb +31 -0
- data/lib/util/MethodEvaluation.rb +49 -0
- data/lib/util/MethodTester.rb +71 -0
- data/lib/util/MethodValidation.rb +145 -0
- data/lib/util/MethodWriter.rb +66 -0
- data/lib/util/Parser.rb +299 -0
- data/lib/util/StatementCheck.rb +42 -0
- data/lib/util/StringToTheory.rb +119 -0
- data/lib/util/System.rb +8 -0
- data/spec/cauldron/pot_spec.rb +6 -0
- data/spec/cauldron/runtime_method_spec.rb +36 -0
- data/spec/cauldron/sexp_2_cauldron_spec.rb +26 -0
- data/spec/cauldron/terminal_spec.rb +38 -0
- data/spec/cauldron/theory_action_spec.rb +5 -0
- data/spec/spec_helper.rb +4 -0
- data/test/fixtures/chains/1/declaration.txt +26 -0
- data/test/fixtures/chains/1/dump +0 -0
- data/test/fixtures/chains/2/declaration.txt +26 -0
- data/test/fixtures/chains/2/dump +0 -0
- data/test/fixtures/chains/3/declaration.txt +26 -0
- data/test/fixtures/chains/3/dump +0 -0
- data/test/fixtures/implementation_results/0/declaration.txt +3 -0
- data/test/fixtures/implementation_results/0/dump +0 -0
- data/test/fixtures/theories/0/declaration.txt +9 -0
- data/test/fixtures/theories/0/desc +10 -0
- data/test/fixtures/theories/0/dump +0 -0
- data/test/fixtures/theories/1/declaration.txt +15 -0
- data/test/fixtures/theories/1/desc +11 -0
- data/test/fixtures/theories/1/dump +0 -0
- data/test/fixtures/theories/10/declaration.txt +23 -0
- data/test/fixtures/theories/10/desc +17 -0
- data/test/fixtures/theories/10/dump +0 -0
- data/test/fixtures/theories/11/declaration.txt +20 -0
- data/test/fixtures/theories/11/desc +14 -0
- data/test/fixtures/theories/11/dump +0 -0
- data/test/fixtures/theories/12/declaration.txt +18 -0
- data/test/fixtures/theories/12/desc +12 -0
- data/test/fixtures/theories/12/dump +0 -0
- data/test/fixtures/theories/13/declaration.txt +24 -0
- data/test/fixtures/theories/13/desc +20 -0
- data/test/fixtures/theories/13/dump +0 -0
- data/test/fixtures/theories/14/declaration.txt +26 -0
- data/test/fixtures/theories/14/desc +20 -0
- data/test/fixtures/theories/14/dump +0 -0
- data/test/fixtures/theories/15/declaration.txt +20 -0
- data/test/fixtures/theories/15/desc +14 -0
- data/test/fixtures/theories/15/dump +0 -0
- data/test/fixtures/theories/16/declaration.txt +30 -0
- data/test/fixtures/theories/16/desc +14 -0
- data/test/fixtures/theories/16/dump +0 -0
- data/test/fixtures/theories/17/declaration.txt +25 -0
- data/test/fixtures/theories/17/desc +11 -0
- data/test/fixtures/theories/17/dump +0 -0
- data/test/fixtures/theories/18/declaration.txt +23 -0
- data/test/fixtures/theories/18/desc +11 -0
- data/test/fixtures/theories/18/dump +0 -0
- data/test/fixtures/theories/19/declaration.txt +23 -0
- data/test/fixtures/theories/19/desc +11 -0
- data/test/fixtures/theories/19/dump +0 -0
- data/test/fixtures/theories/2/declaration.txt +12 -0
- data/test/fixtures/theories/2/desc +10 -0
- data/test/fixtures/theories/2/dump +0 -0
- data/test/fixtures/theories/20/declaration.txt +23 -0
- data/test/fixtures/theories/20/desc +17 -0
- data/test/fixtures/theories/20/dump +0 -0
- data/test/fixtures/theories/3/declaration.txt +19 -0
- data/test/fixtures/theories/3/desc +11 -0
- data/test/fixtures/theories/3/dump +0 -0
- data/test/fixtures/theories/4/declaration.txt +11 -0
- data/test/fixtures/theories/4/desc +11 -0
- data/test/fixtures/theories/4/dump +0 -0
- data/test/fixtures/theories/5/declaration.txt +6 -0
- data/test/fixtures/theories/5/desc +9 -0
- data/test/fixtures/theories/5/dump +0 -0
- data/test/fixtures/theories/6/declaration.txt +13 -0
- data/test/fixtures/theories/6/desc +11 -0
- data/test/fixtures/theories/6/dump +0 -0
- data/test/fixtures/theories/7/declaration.txt +19 -0
- data/test/fixtures/theories/7/desc +11 -0
- data/test/fixtures/theories/7/dump +0 -0
- data/test/fixtures/theories/8/declaration.txt +21 -0
- data/test/fixtures/theories/8/desc +11 -0
- data/test/fixtures/theories/8/dump +0 -0
- data/test/fixtures/theories/9/declaration.txt +24 -0
- data/test/fixtures/theories/9/desc +20 -0
- data/test/fixtures/theories/9/dump +0 -0
- data/test/fixtures/theory_implementations/0/declaration.txt +11 -0
- data/test/fixtures/theory_implementations/0/desc.txt +9 -0
- data/test/fixtures/theory_implementations/0/dump +0 -0
- data/test/fixtures/theory_implementations/0/theory_id +1 -0
- data/test/fixtures/theory_implementations/1/desc.txt +9 -0
- data/test/fixtures/theory_implementations/1/dump +0 -0
- data/test/fixtures/theory_implementations/1/theory_id +1 -0
- data/test/fixtures/theory_implementations/2/desc.txt +9 -0
- data/test/fixtures/theory_implementations/2/dump +0 -0
- data/test/fixtures/theory_implementations/2/theory_id +1 -0
- data/test/output/simple_method.txt +6 -0
- data/test/output/test_method/first_possible_method.txt +6 -0
- data/test/output/test_simple_cases/simple_case_01.txt +8 -0
- data/test/output/test_simple_cases/simple_case_02.txt +7 -0
- data/test/output/test_simple_cases/simple_case_03.txt +8 -0
- data/test/output/test_simple_cases/simple_case_04.txt +8 -0
- data/test/output/test_simple_cases/simple_case_05.txt +8 -0
- data/test/output/test_simple_cases/simple_case_06.txt +9 -0
- data/test/output/test_simple_cases/simple_case_07.txt +9 -0
- data/test/output/test_simple_cases/simple_case_08.txt +9 -0
- data/test/tc_contextual_variables.rb +87 -0
- data/test/tc_describe.rb +47 -0
- data/test/tc_method.rb +133 -0
- data/test/tc_requirement.rb +30 -0
- data/test/tc_suite_complete.rb +26 -0
- data/test/tc_variable.rb +52 -0
- data/test/ts_complete.rb +84 -0
- data/test/ts_stable.rb +81 -0
- data/test/unit/core/declaration/tc_literal_declaration.rb +34 -0
- data/test/unit/core/method_call/tc_class_call.rb +20 -0
- data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +129 -0
- data/test/unit/core/runtime_method/tc_runtime_method.rb +616 -0
- data/test/unit/core/statement/tc_array_access.rb +63 -0
- data/test/unit/core/statement/tc_block_statement.rb +51 -0
- data/test/unit/core/statement/tc_hack_statement.rb +26 -0
- data/test/unit/core/statement/tc_open_statement.rb +70 -0
- data/test/unit/core/statement/tc_statement.rb +681 -0
- data/test/unit/core/statement/tc_statement_dependencies.rb +146 -0
- data/test/unit/core/statement/tc_statement_group.rb +35 -0
- data/test/unit/core/statement/tc_statement_replace_variable.rb +61 -0
- data/test/unit/core/statement/tc_theory_statement.rb +51 -0
- data/test/unit/core/structure/tc_declare_new_instance_structure.rb +41 -0
- data/test/unit/core/structure/tc_declare_variable_as_literal_structure.rb +41 -0
- data/test/unit/core/structure/tc_declare_variable_as_variable_structure.rb +66 -0
- data/test/unit/core/structure/tc_instance_call_container_structure.rb +41 -0
- data/test/unit/core/structure/tc_return_structure.rb +32 -0
- data/test/unit/core/syntax/tc_block_container.rb +32 -0
- data/test/unit/core/syntax/tc_if_container.rb +39 -0
- data/test/unit/core/tc_class_method_call.rb +34 -0
- data/test/unit/core/tc_container.rb +41 -0
- data/test/unit/core/tc_ctest_case.rb +25 -0
- data/test/unit/core/tc_instance_call_container.rb +93 -0
- data/test/unit/core/tc_literal.rb +30 -0
- data/test/unit/core/tc_theory_generator.rb +336 -0
- data/test/unit/core/tc_theory_generator_heavy.rb +42 -0
- data/test/unit/core/tracking/tc_history.rb +102 -0
- data/test/unit/core/tracking/tc_step.rb +65 -0
- data/test/unit/core/variable/tc_array_variable.rb +61 -0
- data/test/unit/core/variable/tc_block_variable.rb +17 -0
- data/test/unit/core/variable/tc_fixnum_variable.rb +54 -0
- data/test/unit/core/variable/tc_method_parameter_variable.rb +22 -0
- data/test/unit/core/variable/tc_runtime_method_variable.rb +32 -0
- data/test/unit/core/variable/tc_string_variable.rb +37 -0
- data/test/unit/core/variable/tc_unknown.rb +24 -0
- data/test/unit/core/variable/tc_variable_reference.rb +28 -0
- data/test/unit/ruby_code/tc_array.rb +64 -0
- data/test/unit/ruby_code/tc_fixnum.rb +18 -0
- data/test/unit/ruby_code/tc_hash.rb +41 -0
- data/test/unit/ruby_code/tc_string.rb +38 -0
- data/test/unit/tc_chain.rb +434 -0
- data/test/unit/tc_chain_mapping.rb +62 -0
- data/test/unit/tc_chain_with_case_1.rb +169 -0
- data/test/unit/tc_instance_call.rb +40 -0
- data/test/unit/tc_instance_call_structure.rb +35 -0
- data/test/unit/tc_method_usage.rb +35 -0
- data/test/unit/tc_pot.rb +124 -0
- data/test/unit/tc_runtime_tracking_method.rb +40 -0
- data/test/unit/tc_statement_structure_2.rb +43 -0
- data/test/unit/tc_theory.rb +533 -0
- data/test/unit/tc_variable_declaration.rb +32 -0
- data/test/unit/theory/tc_theory_action.rb +80 -0
- data/test/unit/theory/tc_theory_action_implementation.rb +23 -0
- data/test/unit/theory/tc_theory_chain_validator.rb +340 -0
- data/test/unit/theory/tc_theory_connector.rb +396 -0
- data/test/unit/theory/tc_theory_dependent.rb +151 -0
- data/test/unit/theory/tc_theory_implementation.rb +133 -0
- data/test/unit/theory/tc_theory_result.rb +111 -0
- data/test/unit/theory/tc_theory_variable.rb +45 -0
- data/test/unit/util/tc_method_validation.rb +98 -0
- data/test/unit/util/tc_parser.rb +108 -0
- data/test/unit/util/tc_string_to_theory.rb +299 -0
- data/test/unit/variable/tc_method_usage_variable.rb +25 -0
- data/tmp/runtime_method_evaluation.rb +10 -0
- metadata +522 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'required'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestArrayAccess < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
animals = ['spider','bear','rat'].to_var
|
8
|
+
@index_0 = ArrayAccess.new(animals,Literal.new(0))
|
9
|
+
@index_1 = ArrayAccess.new(animals,Literal.new(1))
|
10
|
+
@index_2 = ArrayAccess.new(animals,Literal.new(2))
|
11
|
+
@index_3 = ArrayAccess.new(animals,Literal.new(3))
|
12
|
+
|
13
|
+
@spider_index_variable = FixnumVariable.new(0)
|
14
|
+
@spider_access = ArrayAccess.new(animals,@spider_index_variable)
|
15
|
+
|
16
|
+
@characters = ['Manny','Guybrush','Elaine',9].to_var
|
17
|
+
@manny_access = ArrayAccess.new(@characters,Literal.new(0))
|
18
|
+
@access_9 = ArrayAccess.new(@characters,Literal.new(3))
|
19
|
+
@nil_access = ArrayAccess.new(@characters,Literal.new(4))
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
System.reset
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_write
|
28
|
+
assert_equal('var_0[0]',@index_0.write)
|
29
|
+
assert_equal('var_0[1]',@index_1.write)
|
30
|
+
assert_equal('var_0[2]',@index_2.write)
|
31
|
+
assert_equal('var_0[3]',@index_3.write)
|
32
|
+
assert_equal('var_0[3]',@index_3.write)
|
33
|
+
|
34
|
+
# Create methods to access
|
35
|
+
assert_equal('var_0[var_'+@spider_index_variable.variable_id.to_s+']',@spider_access.write)
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_response
|
40
|
+
assert(@manny_access.response.kind_of?(StringVariable))
|
41
|
+
assert_equal('Manny',@manny_access.response.value)
|
42
|
+
assert_equal(9,@access_9.response.value)
|
43
|
+
assert_equal(nil,@nil_access.response.value)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_equivalent?
|
47
|
+
assert(@manny_access.equivalent?(@manny_access))
|
48
|
+
assert_equal(false,@spider_access.equivalent?(@manny_access))
|
49
|
+
|
50
|
+
# Test accessing using the same varaible
|
51
|
+
array_access_1 = ArrayAccess.new(@characters,1.to_literal)
|
52
|
+
array_access_2 = ArrayAccess.new(@characters,2.to_literal)
|
53
|
+
assert_equal(false,array_access_1.equivalent?(array_access_2))
|
54
|
+
|
55
|
+
# Check a duplicate declaration are equivalent
|
56
|
+
assert(array_access_1.equivalent?(ArrayAccess.new(@characters,1.to_literal)))
|
57
|
+
|
58
|
+
# Check that duplcate arrays and keys are caught
|
59
|
+
assert(ArrayAccess.new(['warren'].to_literal,0.to_literal).equivalent?(ArrayAccess.new(['warren'].to_literal,0.to_literal)))
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'required'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestBlockStatement < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
|
8
|
+
@games = ['Grim Fandango','Monkey Island', 'Full Throttle','Simon the Soreceror'].to_var
|
9
|
+
@block_variable = BlockVariable.new
|
10
|
+
@block_container = BlockContainer.new(@block_variable)
|
11
|
+
@each_game = BlockStatement.new(
|
12
|
+
Statement.new(InstanceCallContainer.new(@games,ArrayEach.new)),
|
13
|
+
@block_container
|
14
|
+
)
|
15
|
+
@declared_unknown = Unknown.new
|
16
|
+
@declare_six = Statement.new(@declared_unknown,Equal.new,Literal.new(6))
|
17
|
+
@populated_loop_block_var = BlockVariable.new
|
18
|
+
@populated_loop = BlockStatement.new(
|
19
|
+
Statement.new(InstanceCallContainer.new(@games,ArrayEach.new)),
|
20
|
+
BlockContainer.new(@populated_loop_block_var),
|
21
|
+
@declare_six
|
22
|
+
)
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
System.reset
|
28
|
+
RuntimeMethod.reset_global_id
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_initialize
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_write
|
35
|
+
assert_equal("var_0.each do |var_"+@block_variable.variable_id.to_s+"|\nend\n",@each_game.write(0))
|
36
|
+
assert_equal("\tvar_0.each do |var_1|\n\tend\n",@each_game.write(1))
|
37
|
+
assert_equal(
|
38
|
+
"var_0.each do |var_"+@populated_loop_block_var.variable_id.to_s+"|\n\tvar_"+@declared_unknown.variable_id.to_s+" = 6\nend\n",
|
39
|
+
@populated_loop.write(0)
|
40
|
+
)
|
41
|
+
assert_equal(
|
42
|
+
"\tvar_0.each do |var_"+@populated_loop_block_var.variable_id.to_s+"|\n\t\tvar_"+@declare_six.declared_variable_id.to_s+" = 6\n\tend\n",
|
43
|
+
@populated_loop.write(1)
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_copy
|
48
|
+
assert_equal(@each_game.write,@each_game.copy.write)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'required'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestHackStatement < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
|
8
|
+
@example_hack_statement = HackStatement.new("@var.push({'test':'sadasd','somethingelse':8}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
System.reset
|
13
|
+
RuntimeMethod.reset_global_id
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_write
|
17
|
+
assert_equal("@var.push({'test':'sadasd','somethingelse':8}",@example_hack_statement.write)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_copy
|
21
|
+
assert_nothing_raised(){@example_hack_statement.copy}
|
22
|
+
assert_not_nil(@example_hack_statement.copy)
|
23
|
+
assert_equal(@example_hack_statement.write,@example_hack_statement.copy.write)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'required'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestOpenStatement < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
|
8
|
+
# Create a simple open if statement
|
9
|
+
@simple_if_statement_var = Unknown.new
|
10
|
+
simple_if_statement = Statement.new(If.new,@simple_if_statement_var,Equivalent.new,'Stobart'.to_literal)
|
11
|
+
@simple_open_if_statement = OpenStatement.new(simple_if_statement)
|
12
|
+
|
13
|
+
# Create a simple open statement with variables
|
14
|
+
@simple_open_statement_with_theory_variables = StringToTheory.run("if(var1 == 8)\nend")
|
15
|
+
@simple_open_statement_with_theory_variables.push StringToTheory.run("var2 = var1.length")
|
16
|
+
|
17
|
+
# More complex open statement with theory variables
|
18
|
+
@open_theory_statement_two = StringToTheory.run("if(var1.realise2(var3).params[0].value.length == var2.length)\nend")
|
19
|
+
@open_theory_statement_two.push StringToTheory.run("var4 = var2.length")
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
System.reset
|
25
|
+
RuntimeMethod.reset_global_id
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_initialize
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_write
|
32
|
+
|
33
|
+
# Test the simple statement is written out properly
|
34
|
+
assert_equal("if #{@simple_if_statement_var.write} == 'Stobart'\nend" ,@simple_open_if_statement.write)
|
35
|
+
|
36
|
+
# Test that internal statements are properly tabs
|
37
|
+
@simple_open_if_statement << Statement.new(Return.new,True.new)
|
38
|
+
assert_equal("if #{@simple_if_statement_var.write} == 'Stobart'\n\treturn true\nend" ,@simple_open_if_statement.write)
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_select_all_with_theory_variables
|
43
|
+
assert_equal(3,@simple_open_statement_with_theory_variables.select_all {|x| x.kind_of?(TheoryVariable)}.length)
|
44
|
+
@simple_open_statement_with_theory_variables.select_all {|x| x.kind_of?(TheoryVariable)}.each do |x|
|
45
|
+
assert(x.kind_of?(TheoryVariable))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_select_all_with_open_theory_statement_two
|
50
|
+
assert_equal(5,@open_theory_statement_two.select_all {|x| x.kind_of?(TheoryVariable)}.length)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_copy
|
54
|
+
|
55
|
+
# Test copy with an open theory statement
|
56
|
+
# TODO This is quite a good way to test copy - I should use it across the other main classes
|
57
|
+
initial_theory = StringToTheory.run("if(var1.length = var2.length)\nend")
|
58
|
+
original_element_ids = initial_theory.select_all{true}.collect {|x| x.object_id}
|
59
|
+
copied_elements_ids = initial_theory.copy.select_all{true}.collect {|x| x.object_id}
|
60
|
+
assert_equal(initial_theory.select_all{true}.length*2,(copied_elements_ids + original_element_ids).uniq.length)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_write_structure_with_simple_examples
|
64
|
+
assert_equal("if(a == b)\nend",Parser.run("if(var1 == var2)\nend").write_structure)
|
65
|
+
assert_equal("if(a == b)\n\treturn c\nend",Parser.run("if(var1 == var2)\nreturn 8\nend").write_structure)
|
66
|
+
assert_equal("if(a.chop == b)\n\treturn c\nend",Parser.run("if(var1.chop == var2)\nreturn 8\nend").write_structure)
|
67
|
+
assert_equal("if(a.chop == b)\n\treturn a.chop\nend", Parser.run("if(var1.chop == var2)\nreturn var1.chop\nend").write_structure)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,681 @@
|
|
1
|
+
require 'required'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestStatement < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
|
8
|
+
# Create a simple literal declaration statement
|
9
|
+
@var_a = Unknown.new
|
10
|
+
@simple_statement = Statement.new(@var_a,Equal.new,Literal.new('Daggerfall'))
|
11
|
+
|
12
|
+
# Create a statement with a variable in it
|
13
|
+
@var_b = 'Arena'.to_var
|
14
|
+
@var_c = Unknown.new
|
15
|
+
@statement_b = Statement.new(@var_c,Equal.new,InstanceCallContainer.new(@var_b,Chop.new))
|
16
|
+
|
17
|
+
# Create a return statement
|
18
|
+
@return_statement_a = Statement.new(Return.new,@var_b)
|
19
|
+
|
20
|
+
# Create a statement with mulitiple variables
|
21
|
+
@var_e = 3.to_var
|
22
|
+
@var_f = 6.to_var
|
23
|
+
@var_g = Unknown.new
|
24
|
+
@statement_c = Statement.new(@var_g,Equal.new,@var_e,Addition.new,@var_f)
|
25
|
+
|
26
|
+
# Create some statements that's unknown variable is determined
|
27
|
+
@wally = StringVariable.new('Wally')
|
28
|
+
@chopped_wally = Unknown.new
|
29
|
+
@chop_wally = Statement.new(@chopped_wally,Equal.new,InstanceCallContainer.new(@wally,Chop.new))
|
30
|
+
@number_9 = FixnumVariable.new(9)
|
31
|
+
@declared_number = Unknown.new
|
32
|
+
@statement_d = Statement.new(@declared_number,Equal.new,@number_9)
|
33
|
+
|
34
|
+
# Create some statements that's unknown variable can't be determined
|
35
|
+
@var_h = Unknown.new
|
36
|
+
@var_i = Unknown.new
|
37
|
+
@statemnet_e = Statement.new(@var_h,Equal.new,@chopped_wally)
|
38
|
+
@statemnet_f = Statement.new(@var_i,Equal.new,InstanceCallContainer.new(@chopped_wally,Chop.new))
|
39
|
+
|
40
|
+
# Create a statement that accesses an array variable
|
41
|
+
animals = ['bear','badger','bison','beever','bird'].to_var
|
42
|
+
|
43
|
+
# 3.times
|
44
|
+
@three_times = Statement.new(InstanceCallContainer.new(3.to_literal,Times.new))
|
45
|
+
|
46
|
+
# Return 'sparky' method
|
47
|
+
# def return_sparky
|
48
|
+
# return 'sparky'
|
49
|
+
# end
|
50
|
+
@return_sparky_method = RuntimeMethod.new(MethodUsage.new)
|
51
|
+
return_sparky = Statement.new(Return.new,'sparky'.to_literal)
|
52
|
+
@return_sparky_method.push(return_sparky)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def teardown
|
57
|
+
System.reset
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_simple_valid_syntax
|
61
|
+
|
62
|
+
# Statement: var0 = var1.chop
|
63
|
+
declaration_statement = DeclarationStatement.new(Unknown.new,Equal.new,InstanceCallContainer.new(Unknown.new,Chop.new))
|
64
|
+
assert_equal(false,declaration_statement.valid_syntax?)
|
65
|
+
|
66
|
+
# Statement: var0 = 'test'.chop
|
67
|
+
chop_string_statement = DeclarationStatement.new(Unknown.new,Equal.new,InstanceCallContainer.new(Literal.new('test'),Chop.new))
|
68
|
+
assert_equal(true,chop_string_statement.valid_syntax?)
|
69
|
+
|
70
|
+
# Statement: return false
|
71
|
+
return_statement = Statement.new(Return.new,False.new)
|
72
|
+
assert_equal(true,return_statement.valid_syntax?)
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_not_declared_variables
|
77
|
+
|
78
|
+
# Create a simple declaration statement var1 = var0
|
79
|
+
simple_declaration_statement = DeclarationStatement.new(Unknown.new,Equal.new,Unknown.new)
|
80
|
+
assert_equal(false,simple_declaration_statement.valid_syntax?)
|
81
|
+
|
82
|
+
# Check the number of unknown variables returned
|
83
|
+
assert_equal(1,simple_declaration_statement.not_declared_variables.length)
|
84
|
+
|
85
|
+
# Create the statement with undeclared variables in an instance call
|
86
|
+
declaration_statement = DeclarationStatement.new(Unknown.new,Equal.new,InstanceCallContainer.new(Unknown.new,Chop.new))
|
87
|
+
assert_equal(false,declaration_statement.valid_syntax?)
|
88
|
+
|
89
|
+
# Check the number of undeclared variables
|
90
|
+
assert_equal(1,declaration_statement.not_declared_variables.length)
|
91
|
+
|
92
|
+
# Create a declared variable that references itself var0 = var0 (this is valid ruby, var0 is just nil)
|
93
|
+
unknown_var = Unknown.new()
|
94
|
+
referencing_statement = DeclarationStatement.new(unknown_var,Equal.new,unknown_var)
|
95
|
+
assert_equal(0,referencing_statement.not_declared_variables.length)
|
96
|
+
|
97
|
+
# Check that undeclared variable is found in array access
|
98
|
+
# e.g var_c = var_b[var_a]
|
99
|
+
# 1.
|
100
|
+
var_1_a = 0.to_var
|
101
|
+
var_1_b = ['dogs','cats','mass hysteria'].to_var
|
102
|
+
var_1_c = Unknown.new
|
103
|
+
statement_1 = Statement.new(var_1_c,Equal.new,ArrayAccess.new(var_1_b,var_1_a))
|
104
|
+
assert_equal(2,statement_1.not_declared_variables.length)
|
105
|
+
|
106
|
+
# Check that push statements are properly handled
|
107
|
+
vault_101 = Unknown.new() # e.g ArrayVariable
|
108
|
+
butch = Unknown.new # e.g. StringVariable
|
109
|
+
example_1 = Statement.new(InstanceCallContainer.new(vault_101,Push.new,butch))
|
110
|
+
assert_equal(2,example_1.not_declared_variables.length)
|
111
|
+
|
112
|
+
# 2.
|
113
|
+
# Check that arguments are picked up as "not_declared_variables"
|
114
|
+
# e.g. var_b = RuntimeMethod.new(var_a) -> should return "var_a"
|
115
|
+
var_a = Unknown.new
|
116
|
+
var_b = Unknown.new
|
117
|
+
var_b_statement = Statement.new(var_b,Equal.new,ClassMethodCallContainer.new(RuntimeMethodClass.new,New.new,var_a))
|
118
|
+
assert_equal(1,var_b_statement.not_declared_variables.length)
|
119
|
+
|
120
|
+
# Create a declared variable that references itself var0 += var0
|
121
|
+
# TODO Currently only uses equal
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
# Check that I am able to substitute one variable for another
|
126
|
+
# within a statement.
|
127
|
+
#
|
128
|
+
def test_variable_subst
|
129
|
+
|
130
|
+
# Create the substitute variable (the one to replace the current one) self.class = String
|
131
|
+
class_req = Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equal.new,StringClass.new)
|
132
|
+
# TODO If this is 8 it still works - it should raise an exception since it is a conflict
|
133
|
+
string_value_req = Requirement.new(This.new,Equal.new,Literal.new('tests'))
|
134
|
+
subst_variable = MethodParameter.new(class_req)
|
135
|
+
|
136
|
+
# Create the variable to be replaced self.class = String
|
137
|
+
replacable_variable = Unknown.new
|
138
|
+
|
139
|
+
# Create the statement 'tests' = var.chop
|
140
|
+
tests = 'test'.to_var
|
141
|
+
# TODO This contains duplicate statements - when you describe it self.class = String twice
|
142
|
+
# e.g 'tests' = var.chop
|
143
|
+
statement = Statement.new(tests,Equal.new,InstanceCallContainer.new(replacable_variable,Chop.new))
|
144
|
+
|
145
|
+
# Confirm that the statement isn't valid sytax becuase replacable_variable has no actual value
|
146
|
+
assert_equal(false,statement.valid_syntax?)
|
147
|
+
|
148
|
+
# Replaced the replacable variable e.g. var1 in var0 = var1.chop
|
149
|
+
assert_nothing_raised(){ statement.subst(replacable_variable.variable_id,subst_variable) }
|
150
|
+
|
151
|
+
# Check the printed statement
|
152
|
+
assert_equal('var_'+tests.variable_id.to_s+' = var_'+replacable_variable.variable_id.to_s+'.chop',statement.write)
|
153
|
+
|
154
|
+
# Check that a statement is returned
|
155
|
+
assert_equal( true,statement.subst(subst_variable.variable_id,replacable_variable).kind_of?(Statement) )
|
156
|
+
|
157
|
+
# Check the resulting statement is properly updated
|
158
|
+
updated_statement = statement.subst(replacable_variable.variable_id,subst_variable)
|
159
|
+
|
160
|
+
# Check the original statement is printed out in the same way - after the substiution
|
161
|
+
assert_equal('var_'+tests.variable_id.to_s+' = var_'+replacable_variable.variable_id.to_s+'.chop',statement.write)
|
162
|
+
|
163
|
+
# Check the print out for the updated statement
|
164
|
+
assert_equal('var_'+tests.variable_id.to_s+' = var_'+subst_variable.variable_id.to_s+'.chop',updated_statement.write)
|
165
|
+
|
166
|
+
# Check that the variable_ids of both statements don't match
|
167
|
+
assert_not_equal(statement[2].subject.variable_id,updated_statement[2].subject.variable_id)
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_find_variable
|
172
|
+
|
173
|
+
# Test a variable with the correct id is returned
|
174
|
+
assert(@simple_statement.find_variable(@var_a.variable_id).kind_of?(Variable))
|
175
|
+
assert_equal(@var_a.variable_id,@simple_statement.find_variable(@var_a.variable_id).variable_id)
|
176
|
+
|
177
|
+
# Attempt to retrieve a variable that doesn't exist
|
178
|
+
assert_raise(FailedToFindVariableError){@simple_statement.find_variable(Variable.variable_id+1)}
|
179
|
+
|
180
|
+
# Attempt to find a variable used in the statement i.e. not declared in the statement
|
181
|
+
assert_nothing_raised(){@statement_b.find_variable(@var_b.variable_id)}
|
182
|
+
assert_equal(@var_b.variable_id,@statement_b.find_variable(@var_b.variable_id).variable_id)
|
183
|
+
|
184
|
+
assert_kind_of(Variable,@statement_b.find_variable(@var_b.variable_id))
|
185
|
+
assert_kind_of(Variable,@statement_b.find_variable(@var_c.variable_id))
|
186
|
+
|
187
|
+
# Test that returned variable isn't the original instance
|
188
|
+
assert_not_equal(@var_b.object_id, @statement_b.find_variable(@var_b.variable_id))
|
189
|
+
|
190
|
+
# Test find_variable a return statement
|
191
|
+
assert(@return_statement_a.find_variable(@var_b.variable_id).kind_of?(Variable))
|
192
|
+
assert_equal(@var_b.variable_id,@return_statement_a.find_variable(@var_b.variable_id).variable_id)
|
193
|
+
|
194
|
+
# Test that an unknown variable is retrieved and still unknown
|
195
|
+
assert_equal(true,@chop_wally.find_variable(@chopped_wally.variable_id).kind_of?(Unknown))
|
196
|
+
|
197
|
+
assert_equal(true,@statemnet_e.find_variable(@var_h.variable_id).kind_of?(Unknown))
|
198
|
+
assert_equal(true,@statemnet_f.find_variable(@var_i.variable_id).kind_of?(Unknown))
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
# Check that the statement is properly copied.
|
203
|
+
#
|
204
|
+
def test_copy
|
205
|
+
|
206
|
+
# Check that the variable_ids are different
|
207
|
+
assert_not_equal(@statement_b.object_id,@statement_b.copy.object_id)
|
208
|
+
|
209
|
+
# Check each of the variables within the statements
|
210
|
+
assert_equal(@statement_b.length,@statement_b.copy.length)
|
211
|
+
copied_statement = @statement_b.copy
|
212
|
+
@statement_b.each_with_index do |statement,i|
|
213
|
+
assert_not_equal(statement.object_id,copied_statement[i].object_id)
|
214
|
+
end
|
215
|
+
|
216
|
+
# Check that the statement_type is maintained for copied statements.
|
217
|
+
statement_1 = Statement.new(@var_a,Equal.new,Literal.new('Daggerfall'))
|
218
|
+
#statement_1.statement_type = StatementStructure::DECLARATION_STATEMENT
|
219
|
+
assert_equal(statement_1.copy.statement_type,statement_1.statement_type)
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
# Tests it can identifiy the structure of the statement.
|
224
|
+
#
|
225
|
+
def test_statement_type
|
226
|
+
assert_equal(StatementStructure::DECLARATION_STATEMENT,@statement_b.statement_type)
|
227
|
+
assert_equal(StatementStructure::RETURN_STATEMENT,@return_statement_a.statement_type)
|
228
|
+
|
229
|
+
# Test some poorly structured statements
|
230
|
+
assert_raises(UnknownStatementType){Statement.new(RequirementsVariable.new,RequirementsVariable.new).statement_type}
|
231
|
+
end
|
232
|
+
|
233
|
+
# Presumes the statement is a declaration statement and returns the
|
234
|
+
# specified variable in context.
|
235
|
+
#
|
236
|
+
def test_find_variable_in_declaration_statement
|
237
|
+
|
238
|
+
# Attempt to retrieve both variables used in the statement (var_c = var_b.chop)
|
239
|
+
assert(@statement_b.send(:find_variable_in_declaration_statement,@var_c).kind_of?(Variable))
|
240
|
+
assert(@statement_b.send(:find_variable_in_declaration_statement,@var_b).kind_of?(Variable))
|
241
|
+
|
242
|
+
# Attempt to retrieve variable not used in statement
|
243
|
+
assert(@statement_b.send(:find_variable_in_declaration_statement,@var_b).kind_of?(Variable))
|
244
|
+
|
245
|
+
# Attempt to retrieve variable for statement with three variables
|
246
|
+
assert(@statement_c.send(:find_variable_in_declaration_statement,@var_e).kind_of?(Variable))
|
247
|
+
assert(@statement_c.send(:find_variable_in_declaration_statement,@var_f).kind_of?(Variable))
|
248
|
+
assert(@statement_c.send(:find_variable_in_declaration_statement,@var_g).kind_of?(Variable))
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_required_variable_ids
|
253
|
+
|
254
|
+
# Confirm that the simple statement var = 'daggerfall' has no dependencies
|
255
|
+
assert_equal(0,@simple_statement.required_variable_ids.length)
|
256
|
+
|
257
|
+
# Confirm varA = varB.chop has one dependency
|
258
|
+
assert_equal(1,@statement_b.required_variable_ids.length)
|
259
|
+
assert_equal(@var_b.variable_id,@statement_b.required_variable_ids.first)
|
260
|
+
|
261
|
+
assert_equal(2,Parser.run('var3 = var1 + var2').required_variable_ids.length)
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_to_literal_string
|
266
|
+
assert_equal("var='Daggerfall'",@simple_statement.to_literal_string)
|
267
|
+
end
|
268
|
+
|
269
|
+
# Tests that unrealised variables can be identified in a statement
|
270
|
+
#
|
271
|
+
def test_unrealised_variables
|
272
|
+
|
273
|
+
# 1. var = 'test'
|
274
|
+
example_1 = Statement.new(Unknown.new,Equal.new,'test'.to_literal)
|
275
|
+
assert_equal(1,example_1.unrealised_variables.length)
|
276
|
+
|
277
|
+
# 2. Test NilVariables aren't regared as unrealised
|
278
|
+
example_2 = Statement.new(Unknown.new,Equal.new,NilVariable.new)
|
279
|
+
assert_equal(1,example_2.unrealised_variables.length)
|
280
|
+
|
281
|
+
# 3. Check that a undeclared String Variable is caught
|
282
|
+
example_3 = Statement.new(Unknown.new,Equal.new,StringVariable.new(nil))
|
283
|
+
assert_equal(2,example_3.unrealised_variables.length)
|
284
|
+
|
285
|
+
# 4. Check that statements can contain no unreleasid variables
|
286
|
+
manny = StringVariable.new('Manny')
|
287
|
+
example_4 = Statement.new(FixnumVariable.new(5),Equal.new,InstanceCallContainer.new(manny,StringLength.new))
|
288
|
+
assert_equal(0,example_4.unrealised_variables.length)
|
289
|
+
|
290
|
+
# 5. Check the instance calls are caught
|
291
|
+
nil_string_variable = StringVariable.new(nil)
|
292
|
+
unknown_example_5 = Unknown.new
|
293
|
+
example_5 = Statement.new(unknown_example_5,Equal.new,InstanceCallContainer.new(nil_string_variable,StringLength.new))
|
294
|
+
assert_equal(2,example_5.unrealised_variables.length)
|
295
|
+
assert(example_5.unrealised_variables.any? {|x| x.variable_id == nil_string_variable.variable_id})
|
296
|
+
assert(example_5.unrealised_variables.any? {|x| x.variable_id == unknown_example_5.variable_id})
|
297
|
+
|
298
|
+
# 6. Check that .push methods are properly caught
|
299
|
+
# e.g. var_34.push(var_24)
|
300
|
+
vault_101 = Unknown.new() # e.g ArrayVariable
|
301
|
+
butch = Unknown.new # e.g. StringVariable
|
302
|
+
example_6 = Statement.new(InstanceCallContainer.new(vault_101,Push.new,butch))
|
303
|
+
assert_equal(2,example_6.unrealised_variables.length)
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_variables
|
308
|
+
|
309
|
+
# 1. Check that the write number of variables are returned
|
310
|
+
# e.g. var_xx.push(var_xx)
|
311
|
+
vault_101 = Unknown.new() # e.g ArrayVariable
|
312
|
+
butch = Unknown.new # e.g. StringVariable
|
313
|
+
example_1 = Statement.new(InstanceCallContainer.new(vault_101,Push.new,butch))
|
314
|
+
assert_equal(2,example_1.variables.length)
|
315
|
+
|
316
|
+
# 2. Check that literals are ignored
|
317
|
+
assert_equal(0,@three_times.variables.length)
|
318
|
+
|
319
|
+
# 3. Check that accessed arrays are caught
|
320
|
+
# var_xx = var_a[0]
|
321
|
+
countries = Statement.new(Unknown.new,Equal.new,ArrayAccess.new(['U.K','France','Poland'].to_var,0))
|
322
|
+
assert_equal(2,countries.variables.length)
|
323
|
+
|
324
|
+
# 4. Check array access using a variable
|
325
|
+
pip = 'pip'.to_var
|
326
|
+
wooter = 'wooter'.to_var
|
327
|
+
people = [pip,wooter].to_var
|
328
|
+
people_access = Statement.new(Unknown.new,Equal.new,ArrayAccess.new(people,1.to_var))
|
329
|
+
assert_equal(3,people_access.variables.length)
|
330
|
+
assert(people_access.variables.any? {|x| x.variable_id == people.variable_id})
|
331
|
+
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_write
|
335
|
+
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_to_declaration
|
339
|
+
|
340
|
+
# Check that statement returns a declaration statement
|
341
|
+
assert_equal(true,@simple_statement.to_declaration.kind_of?(VariableDeclaration))
|
342
|
+
|
343
|
+
# Check to_declaration command when excluding a variable
|
344
|
+
assert_equal(
|
345
|
+
"Statement.new(var_#{@var_c.variable_id}, Equal.new(), InstanceCallContainer.new(StringVariable.new('Arena'), Chop.new()))",
|
346
|
+
@statement_b.to_declaration([@var_c.variable_id]).write
|
347
|
+
)
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_find_all_required_runtime_methods
|
352
|
+
|
353
|
+
# Check that any empty array is returned if there are no runtime methods used
|
354
|
+
assert_equal(0,@simple_statement.find_all_required_runtime_methods.length)
|
355
|
+
|
356
|
+
# 1. Create a statement that calls a runtime method
|
357
|
+
static_statement = Statement.new
|
358
|
+
#static_statement.statement_type = StatementStructure::MISC_STATEMENT
|
359
|
+
return_statement_method = RuntimeMethod.new(MethodUsage.new(),static_statement.to_var)
|
360
|
+
return_statement = Statement.new(Return.new,'sparky')
|
361
|
+
#return_statement.statement_type = StatementStructure::RETURN_STATEMENT
|
362
|
+
return_declaration_statement = Statement.new(Return.new,return_statement.to_declaration )
|
363
|
+
#return_declaration_statement.statement_type = StatementStructure::RETURN_STATEMENT
|
364
|
+
return_statement_method.push(return_declaration_statement)
|
365
|
+
|
366
|
+
# 1a. Create the statement that contains the method call
|
367
|
+
statement_with_method_call = Statement.new(Unknown.new,Equal.new,DefCall.new(static_statement.to_var,return_statement_method))
|
368
|
+
#statement_with_method_call.statement_type = StatementStructure::DECLARATION_STATEMENT
|
369
|
+
assert_equal(1,statement_with_method_call.find_all_required_runtime_methods.length)
|
370
|
+
assert(statement_with_method_call.find_all_required_runtime_methods.kind_of?(Array))
|
371
|
+
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_realise2
|
375
|
+
|
376
|
+
# 1. Test that a statement can realise itself with a pasted in history instance
|
377
|
+
# a. First create the context of the statement so the history instance can be created
|
378
|
+
runtime_method_1 = RuntimeMethod.new(MethodUsage.new)
|
379
|
+
unknown_variable_1 = Unknown.new
|
380
|
+
statement_1 = Statement.new(unknown_variable_1,Equal.new,'sparky'.to_literal)
|
381
|
+
#statement_1.statement_type = StatementStructure::DECLARATION_STATEMENT
|
382
|
+
runtime_method_1.push(statement_1)
|
383
|
+
|
384
|
+
# b. Now get the history instance for the runime method with the statement
|
385
|
+
runtime_method_1_history = runtime_method_1.history(ParametersContainer.new)
|
386
|
+
|
387
|
+
# c. Check that the statement can be realised with the history instance
|
388
|
+
realised_statement = statement_1.realise2(runtime_method_1_history)
|
389
|
+
assert_equal(StringVariable,realised_statement.find_variable(unknown_variable_1.variable_id).class)
|
390
|
+
assert_equal('sparky',realised_statement.find_variable(unknown_variable_1.variable_id).value)
|
391
|
+
|
392
|
+
# 2. Test that a statement that calls a method can be realised
|
393
|
+
# a. Create the method that is called
|
394
|
+
return_sparky = Statement.new(Return.new,'sparky'.to_declaration)
|
395
|
+
#return_sparky.statement_type = StatementStructure::DECLARATION_STATEMENT
|
396
|
+
calling_runtime_method_2 = RuntimeMethod.new(MethodUsage.new,'sparky'.to_var,return_sparky)
|
397
|
+
|
398
|
+
# b. Create the method that calls "calling_runtime_method_2"
|
399
|
+
runtime_method_2 = RuntimeMethod.new(MethodUsage.new)
|
400
|
+
unknown_variable_2 = Unknown.new
|
401
|
+
statement_2 = Statement.new(unknown_variable_2,Equal.new,DefCall.new('sparky'.to_var,calling_runtime_method_2))
|
402
|
+
#statement_2.statement_type = StatementStructure::DECLARATION_STATEMENT
|
403
|
+
runtime_method_2.push(statement_2)
|
404
|
+
|
405
|
+
# c. Retrieve the history instance for the runtime method
|
406
|
+
history_2 = runtime_method_2.history(ParametersContainer.new,[calling_runtime_method_2])
|
407
|
+
|
408
|
+
assert_equal(true,statement_2.realise2(history_2).find_variable(unknown_variable_2.variable_id).kind_of?(StringVariable))
|
409
|
+
assert_equal('sparky',statement_2.realise2(history_2).find_variable(unknown_variable_2.variable_id).value)
|
410
|
+
|
411
|
+
# 3. Try complex return type e.g StatementVaraible
|
412
|
+
# a. Create the method that is called
|
413
|
+
# def called_method
|
414
|
+
# return Statement.new(Return.new,'sparky')
|
415
|
+
# end
|
416
|
+
#
|
417
|
+
blank_statement = Statement.new
|
418
|
+
#blank_statement.statement_type = StatementStructure::MISC_STATEMENT
|
419
|
+
called_runtime_method_3 = RuntimeMethod.new(MethodUsage.new,blank_statement.to_var)
|
420
|
+
|
421
|
+
# b. Create the statement that is returned as a variable.
|
422
|
+
returned_statement_variable = Statement.new(Return.new,'sparky')
|
423
|
+
declared_return_statement_var = Unknown.new
|
424
|
+
#declare_return_statement = Statement.new(declared_return_statement_var,Equal.new,returned_statement_variable.to_declaration)
|
425
|
+
return_return_statement = Statement.new(Return.new,returned_statement_variable.to_declaration)
|
426
|
+
#return_return_statement.statement_type = StatementStructure::RETURN_STATEMENT
|
427
|
+
#declare_return_statement = StatementStructure::DECLARATION_STATEMENT
|
428
|
+
called_runtime_method_3.push(return_return_statement)
|
429
|
+
|
430
|
+
# c. Create the method that includes a call to "called_runtime_method_3"
|
431
|
+
runtime_method_3 = RuntimeMethod.new(MethodUsage.new)
|
432
|
+
unknown_variable_3 = Unknown.new
|
433
|
+
statement_3 = Statement.new(unknown_variable_3,Equal.new,DefCall.new(blank_statement.to_var,called_runtime_method_3))
|
434
|
+
#statement_3.statement_type = StatementStructure::DECLARATION_STATEMENT
|
435
|
+
runtime_method_3.push(statement_3)
|
436
|
+
|
437
|
+
# d. Retrieve the history object for "runtime_method_3"
|
438
|
+
history_3 = runtime_method_3.history(ParametersContainer.new,[called_runtime_method_3])
|
439
|
+
assert_equal(true, statement_3.realise2(history_3).find_variable(unknown_variable_3.variable_id).kind_of?(StatementVariable) )
|
440
|
+
|
441
|
+
end
|
442
|
+
|
443
|
+
def test_classes_match?
|
444
|
+
|
445
|
+
# Test a simple return statement for both negative and positive results
|
446
|
+
return_statement = Statement.new(Return.new,6.to_literal)
|
447
|
+
assert(return_statement.classes_match?(Return,Literal))
|
448
|
+
assert_equal(false,return_statement.classes_match?(Return,Unknown))
|
449
|
+
assert_equal(false,return_statement.classes_match?(Return,Literal,Unknown))
|
450
|
+
|
451
|
+
end
|
452
|
+
|
453
|
+
def test_statement_type
|
454
|
+
|
455
|
+
# Test that statement type is saved correctly - even after copying
|
456
|
+
return_statement = Statement.new(Return.new,6.to_literal)
|
457
|
+
#return_statement.statement_type = StatementStructure::RETURN_STATEMENT
|
458
|
+
assert_equal(return_statement.statement_type,StatementStructure::RETURN_STATEMENT)
|
459
|
+
assert_equal(return_statement.copy.statement_type,StatementStructure::RETURN_STATEMENT)
|
460
|
+
|
461
|
+
# Test that return statements can be dynamically identified
|
462
|
+
return_statement_without_statement_type = Statement.new(Return.new,8.to_literal)
|
463
|
+
assert_nothing_raised(){return_statement_without_statement_type.statement_type}
|
464
|
+
assert_equal(return_statement_without_statement_type.statement_type,StatementStructure::RETURN_STATEMENT)
|
465
|
+
|
466
|
+
end
|
467
|
+
|
468
|
+
def test_replace_variable_if
|
469
|
+
|
470
|
+
# Create a simple statement will have it's variable replaced
|
471
|
+
# unknown = 7
|
472
|
+
statement_a_unknown = Unknown.new
|
473
|
+
statement_a = Statement.new(statement_a_unknown,Equal.new,7.to_literal)
|
474
|
+
assert(statement_a.first.kind_of?(Unknown))
|
475
|
+
modified_statement_a = statement_a.replace_variable_if(FixnumVariable.new(7)) {|x| x.uniq_id == statement_a_unknown.uniq_id }
|
476
|
+
assert(modified_statement_a.first.kind_of?(FixnumVariable))
|
477
|
+
|
478
|
+
# Create a statement with an instance call container
|
479
|
+
# unknown = 'test'.chop
|
480
|
+
statement_b_unknown = Unknown.new
|
481
|
+
statement_b = Statement.new(Unknown.new,Equal.new,InstanceCallContainer.new(statement_b_unknown,Chop.new))
|
482
|
+
modified_statement_b = statement_b.replace_variable_if('test'.to_var) do |x|
|
483
|
+
x.uniq_id == statement_b_unknown.uniq_id
|
484
|
+
end
|
485
|
+
assert(modified_statement_b.kind_of?(Statement))
|
486
|
+
assert_equal(3,modified_statement_b.length)
|
487
|
+
assert_not_equal(modified_statement_b[2].subject.variable_id,statement_b_unknown.variable_id)
|
488
|
+
|
489
|
+
# Create a statement with parameters in the statement
|
490
|
+
# ['goo'].push('jon')
|
491
|
+
statement_c_unknown = Unknown.new
|
492
|
+
statement_c = Statement.new(InstanceCallContainer.new(['goo'].to_var,Push.new,statement_c_unknown))
|
493
|
+
modified_statement_c = statement_c.replace_variable_if('jon'.to_var) do |x|
|
494
|
+
x.uniq_id == statement_c_unknown.uniq_id
|
495
|
+
end
|
496
|
+
assert(modified_statement_c.kind_of?(Statement))
|
497
|
+
assert_not_equal(modified_statement_c[0][0].uniq_id,statement_c_unknown.uniq_id)
|
498
|
+
|
499
|
+
# Create a statement with no matches
|
500
|
+
# unknown = 5 + 6
|
501
|
+
statement_d = Statement.new(Unknown.new,Equal.new,5.to_var,Addition.new,6.to_var)
|
502
|
+
modified_statement_d = statement_d.replace_variable_if('jon'.to_var) do |x|
|
503
|
+
x.uniq_id == 21312
|
504
|
+
end
|
505
|
+
assert_equal(statement_d.write,modified_statement_d.write)
|
506
|
+
|
507
|
+
# Create an instance call statement with no matches
|
508
|
+
# unknown = var_a.length
|
509
|
+
statement_e = Statement.new(Unknown.new,Equal.new,InstanceCallContainer.new('richardson'.to_var,StringLength.new))
|
510
|
+
modified_statement_e = statement_e.replace_variable_if('jon'.to_var) do |x|
|
511
|
+
if x.uniq_id == 3242
|
512
|
+
next true
|
513
|
+
end
|
514
|
+
false
|
515
|
+
end
|
516
|
+
assert_equal(statement_e.write,modified_statement_e.write)
|
517
|
+
|
518
|
+
end
|
519
|
+
|
520
|
+
def test_to_var
|
521
|
+
|
522
|
+
# Create a simple statement and check that it can be changed to a statement variable
|
523
|
+
assert_equal(StatementVariable,@simple_statement.to_var.class)
|
524
|
+
|
525
|
+
# Check that the content of the statement is pre-served
|
526
|
+
assert_equal(@simple_statement.write,@simple_statement.to_var.value.write)
|
527
|
+
assert_equal(@chop_wally.write,@chop_wally.to_var.value.write)
|
528
|
+
|
529
|
+
# Check that variable ids are maintained and classes are maintained
|
530
|
+
chop_wally_var = @chop_wally.to_var
|
531
|
+
@chop_wally.each_variable do |x|
|
532
|
+
assert_equal(x.variable_id,chop_wally_var.value.find_variable(x.variable_id).variable_id)
|
533
|
+
assert_equal(x.class,chop_wally_var.value.find_variable(x.variable_id).class)
|
534
|
+
end
|
535
|
+
|
536
|
+
# Check that the id of the generated statement variable can be set.
|
537
|
+
set_variable_id = 0
|
538
|
+
variable_with_set_id = @simple_statement.to_var(set_variable_id)
|
539
|
+
assert_equal(0,variable_with_set_id.variable_id)
|
540
|
+
|
541
|
+
# Change the id's are retained when using blocks
|
542
|
+
assert_equal(89,@simple_statement.to_var(89,101).variable_id)
|
543
|
+
# TODO I should check that ids are retained inside the value of the statement variable
|
544
|
+
#raise StandardError.new('jsadksadfjksd')
|
545
|
+
runtime_method_a = RuntimeMethod.new(MethodUsage.new)
|
546
|
+
runtime_method_a << @simple_statement
|
547
|
+
realised_runtime_method_a = runtime_method_a.realise2([])
|
548
|
+
assert_equal(@simple_statement.first.variable_id,realised_runtime_method_a.first.first.variable_id)
|
549
|
+
assert_equal(@simple_statement.first.uniq_id,realised_runtime_method_a.first.first.uniq_id)
|
550
|
+
|
551
|
+
end
|
552
|
+
|
553
|
+
def test_find_actual_variable
|
554
|
+
|
555
|
+
# 1. Check that the actual variable is returned from a statement
|
556
|
+
assert_equal(@simple_statement[0].variable_id,@simple_statement.find_actual_variable(@simple_statement[0].variable_id).variable_id)
|
557
|
+
assert_equal(@simple_statement[0].object_id,@simple_statement.find_actual_variable(@simple_statement[0].variable_id).object_id)
|
558
|
+
|
559
|
+
end
|
560
|
+
|
561
|
+
def test_select_all
|
562
|
+
|
563
|
+
# Check that both Unknown's are found within the statement
|
564
|
+
statement = Statement.new(Unknown.new,Equal.new,InstanceCallContainer.new(Unknown.new,Chop.new))
|
565
|
+
assert_equal(2,statement.select_all {|x| x.kind_of?(Unknown)}.length)
|
566
|
+
|
567
|
+
end
|
568
|
+
|
569
|
+
def test_equivalent?
|
570
|
+
|
571
|
+
# Check that 'unknown = method_call' and 'unknown = "Sparky"' aren't equivalent
|
572
|
+
unknown_method_call = Statement.new(
|
573
|
+
Unknown.new,Equal.new,DefCall.new(StringVariable.new('Sparky'),@return_sparky_method)
|
574
|
+
)
|
575
|
+
#unknown_method_call.statement_type = StatementStructure::DECLARATION_STATEMENT
|
576
|
+
unknown_sparky_declaration = Statement.new(
|
577
|
+
Unknown.new,Equal.new,'Sparky'.to_literal
|
578
|
+
)
|
579
|
+
#unknown_sparky_declaration.statement_type = StatementStructure::DECLARATION_STATEMENT
|
580
|
+
assert_equal(false,unknown_method_call.equivalent?(unknown_sparky_declaration))
|
581
|
+
assert_equal(false,unknown_sparky_declaration.equivalent?(unknown_method_call))
|
582
|
+
assert(true,unknown_sparky_declaration.equivalent?(unknown_sparky_declaration))
|
583
|
+
|
584
|
+
# Check that two 'unknown = MethodUsage.new' are caught as equivalent
|
585
|
+
statement_1 = Statement.new(Unknown.new,Equal.new,ClassMethodCallContainer.new(MethodUsageClass.new,New.new))
|
586
|
+
statement_2 = Statement.new(Unknown.new,Equal.new,ClassMethodCallContainer.new(MethodUsageClass.new,New.new))
|
587
|
+
assert_equal(true,statement_1.equivalent?(statement_2))
|
588
|
+
|
589
|
+
end
|
590
|
+
|
591
|
+
def test_exchange_variables
|
592
|
+
|
593
|
+
# Create a statement that includes a method variable and is replaced by a different variable
|
594
|
+
method_variable_1 = MethodParameter.new
|
595
|
+
unknown_variable_1 = Unknown.new
|
596
|
+
statement_1 = Statement.new(unknown_variable_1,Equal.new,InstanceCallContainer.new(method_variable_1,Chop.new))
|
597
|
+
pip = 'pip'.to_var
|
598
|
+
conversions = Hash.new()
|
599
|
+
conversions[method_variable_1.variable_id.to_s.to_sym] = pip.copy
|
600
|
+
assert(statement_1.exchange_variables(conversions).kind_of?(Statement))
|
601
|
+
assert_nothing_raised(){statement_1.exchange_variables(conversions).to_literal_string}
|
602
|
+
assert_equal(
|
603
|
+
'var_'+unknown_variable_1.variable_id.to_s+' = var_'+pip.variable_id.to_s+'.chop',
|
604
|
+
statement_1.exchange_variables(conversions).write
|
605
|
+
)
|
606
|
+
|
607
|
+
# Create a statement that modifies an existing variable.
|
608
|
+
|
609
|
+
|
610
|
+
# TODO Test with the same variable used twice in a statement e.g. var_a = var_b+var_b
|
611
|
+
|
612
|
+
end
|
613
|
+
|
614
|
+
def test_creates_variable?
|
615
|
+
|
616
|
+
# Check that a declaration statement creates a variable
|
617
|
+
statement_1 = Statement.new(Unknown.new,Equal.new,6.to_declaration)
|
618
|
+
assert(statement_1.creates_variable?)
|
619
|
+
|
620
|
+
# Check that a statement doesn't create a variable
|
621
|
+
statement_2 = Statement.new(Return.new,7.to_declaration)
|
622
|
+
assert_equal(false,statement_2.creates_variable?)
|
623
|
+
|
624
|
+
# Check that a statement that modifies a variable is detected
|
625
|
+
statement_3 = Statement.new(InstanceCallContainer.new([].to_var,Push.new,'antz'.to_literal))
|
626
|
+
assert_equal(true,statement_3.creates_variable?)
|
627
|
+
|
628
|
+
end
|
629
|
+
|
630
|
+
def test_created_variable
|
631
|
+
|
632
|
+
# Test that declaration statements are handles 'var_a = 'bramble jelly'
|
633
|
+
statement_1_unknown = Unknown.new
|
634
|
+
statement_1 = Statement.new(statement_1_unknown,Equal.new,'bramble jelly'.to_literal)
|
635
|
+
assert(statement_1.created_variable.kind_of?(Variable))
|
636
|
+
assert_equal(statement_1_unknown.variable_id,statement_1.created_variable.variable_id)
|
637
|
+
assert_not_nil(statement_1.created_variable_id)
|
638
|
+
assert_not_nil(statement_1.created_variable.uniq_id)
|
639
|
+
assert_equal(statement_1.created_variable.uniq_id,statement_1_unknown.uniq_id)
|
640
|
+
assert_equal(statement_1.created_variable.variable_id,statement_1.declared_variable.variable_id)
|
641
|
+
|
642
|
+
# Test that statements the don't create a variable are appropriatly handled
|
643
|
+
statement_2 = Statement.new(Return.new,'rowiage'.to_var)
|
644
|
+
assert_equal(false,statement_2.creates_variable?)
|
645
|
+
assert_raises(ImproperStatementUsageError){statement_2.created_variable}
|
646
|
+
|
647
|
+
# Test that modifying statements have a new created variable
|
648
|
+
statement_3_empty_array_var = [].to_var
|
649
|
+
statement_3_empty_array_var.copy
|
650
|
+
statement_3 = Statement.new(InstanceCallContainer.new(statement_3_empty_array_var,Push.new,'Normandy SR2'.to_literal))
|
651
|
+
assert(true,statement_3.creates_variable?)
|
652
|
+
assert_nothing_raised(){statement_3.created_variable}
|
653
|
+
assert(statement_3.created_variable.kind_of?(ArrayVariable))
|
654
|
+
assert_equal(statement_3.created_variable.variable_id,statement_3_empty_array_var.variable_id)
|
655
|
+
# assert_not_equal(
|
656
|
+
# statement_3.created_variable.uniq_id,
|
657
|
+
# statement_3_empty_array_var.uniq_id
|
658
|
+
# )
|
659
|
+
|
660
|
+
end
|
661
|
+
|
662
|
+
def test_tokens
|
663
|
+
# TODO This should be a Statement
|
664
|
+
assert_equal(
|
665
|
+
2,
|
666
|
+
Statement.new(Unknown.new,Equal.new,Unknown.new).tokens.length
|
667
|
+
)
|
668
|
+
end
|
669
|
+
|
670
|
+
def test_write_structure_simple
|
671
|
+
assert_equal("a = b",Parser.run("var1 = var2").write_structure)
|
672
|
+
assert_equal("a = b + c",Parser.run("var1 = var2 + var3").write_structure)
|
673
|
+
assert_equal("a = b + c",Parser.run("var1 = var2 + 7").write_structure)
|
674
|
+
assert_equal("a = b + c",Parser.run("var1 = var2 + 'adeley'").write_structure)
|
675
|
+
assert_equal("a.chop",Statement.new(Parser.run("var1.chop")).write_structure)
|
676
|
+
assert_equal("a = b.chop + c",Parser.run("var2 = var5.chop + 9").write_structure)
|
677
|
+
assert_equal("a = b.chop + a",Parser.run("var2 = var5.chop + var2").write_structure)
|
678
|
+
end
|
679
|
+
|
680
|
+
|
681
|
+
end
|