Ejemplo n.º 1
0
        public void TestAddedNodes01()
        {
            List <string> codes = new List <string>()
            {
                "a = 1;"
            };

            Guid           guid  = System.Guid.NewGuid();
            List <Subtree> added = new List <Subtree>();

            added.Add(CreateSubTreeFromCode(guid, codes[0]));

            var syncData = new GraphSyncData(null, added, null);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer      changeSetState = new ProtoScript.Runners.ChangeSetComputer(core);
            List <AssociativeNode> astList        = changeSetState.GetDeltaASTList(syncData);

            // Get expected ASTList
            // The list must be in the order that it is expected
            List <string> expectedCode = new List <string>()
            {
                "a = 1;"
            };
            List <AssociativeNode> expectedAstList = ProtoCore.Utils.CoreUtils.BuildASTList(core, expectedCode);

            // Compare ASTs to be equal
            for (int n = 0; n < astList.Count; ++n)
            {
                AssociativeNode node1   = astList[n];
                AssociativeNode node2   = expectedAstList[n];
                bool            isEqual = node1.Equals(node2);
                Assert.IsTrue(isEqual);
            }
        }
Ejemplo n.º 2
0
        public void TestAddedNodes01()
        {
            List<string> codes = new List<string>() 
            {
                "a = 1;"
            };

            Guid guid = System.Guid.NewGuid();
            List<Subtree> added = new List<Subtree>();
            added.Add(CreateSubTreeFromCode(guid, codes[0]));

            var syncData = new GraphSyncData(null, added, null);
         
            // Get astlist from ChangeSetComputer
            ChangeSetComputer changeSetState = new ProtoScript.Runners.ChangeSetComputer(core);
            List<AssociativeNode> astList = changeSetState.GetDeltaASTList(syncData);

            // Get expected ASTList
            // The list must be in the order that it is expected
            List<string> expectedCode = new List<string>() 
            {
                "a = 1;"
            };
            List<AssociativeNode> expectedAstList = ProtoCore.Utils.CoreUtils.BuildASTList(core, expectedCode);

            // Compare ASTs to be equal
            for (int n = 0; n < astList.Count; ++n)
            {
                AssociativeNode node1 = astList[n];
                AssociativeNode node2 = expectedAstList[n];
                bool isEqual = node1.Equals(node2);
                Assert.IsTrue(isEqual);
            }
        }
Ejemplo n.º 3
0
        public void TestPreviewModify1Node02()
        {
            List <string> codes = new List <string>()
            {
                // guid1
                @"
                    a = 1; 
                ",
                // guid2
                @"
                    x = a; 
                    y = x;
                ",
                // guid3
                @"
                    z = a; 
                ",
                // guid1
                @"
                    a = 10; 
                ",
            };

            Guid guid1 = System.Guid.NewGuid();
            Guid guid2 = System.Guid.NewGuid();
            Guid guid3 = System.Guid.NewGuid();

            // Create and run the graph
            ProtoScript.Runners.LiveRunner liveRunner = new ProtoScript.Runners.LiveRunner();
            List <Subtree> added = new List <Subtree>();

            added.Add(CreateSubTreeFromCode(guid1, codes[0]));
            added.Add(CreateSubTreeFromCode(guid2, codes[1]));
            added.Add(CreateSubTreeFromCode(guid3, codes[2]));
            var syncData = new GraphSyncData(null, added, null);

            liveRunner.UpdateGraph(syncData);


            // Modify [a = 1;] to [a = 10;]
            List <Subtree> modified = new List <Subtree>();

            modified.Add(CreateSubTreeFromCode(guid1, codes[3]));
            syncData = new GraphSyncData(null, null, modified);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer      changeSetState = new ProtoScript.Runners.ChangeSetComputer(liveRunner.Core);
            List <AssociativeNode> astList        = changeSetState.GetDeltaASTList(syncData);

            // Get the preview guids (affected graphs)
            List <Guid> reachableGuidList = changeSetState.EstimateNodesAffectedByASTList(astList);

            // Check if the the affected guids are in the list
            List <Guid> expectedGuid = new List <Guid> {
                guid2, guid3
            };

            AssertPreview(reachableGuidList, expectedGuid, 2);
        }
Ejemplo n.º 4
0
        public void TestPreviewModify1Node01()
        {
            List<string> codes = new List<string>() 
            {
               @"
                    a = 1;
                ",
                 
               @"
                    x = a;
                    y = x;
                ",

               @"
                    a = 10;
                ",
            };

            Guid guid1 = System.Guid.NewGuid();
            Guid guid2 = System.Guid.NewGuid();

            // Create and run the graph  [a = 1;] and [x = a; y = x;]
            ProtoScript.Runners.LiveRunner liveRunner = new ProtoScript.Runners.LiveRunner();
            List<Subtree> added = new List<Subtree>();
            added.Add(CreateSubTreeFromCode(guid1, codes[0]));
            added.Add(CreateSubTreeFromCode(guid2, codes[1]));
            var syncData = new GraphSyncData(null, added, null);
            liveRunner.UpdateGraph(syncData);


            // Modify [a = 1;] to [a = 10;] 
            List<Subtree> modified = new List<Subtree>();
            modified.Add(CreateSubTreeFromCode(guid1, codes[2]));
            syncData = new GraphSyncData(null, null, modified);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer changeSetState = new ProtoScript.Runners.ChangeSetComputer(liveRunner.Core);
            List<AssociativeNode> astList = changeSetState.GetDeltaASTList(syncData);

            // Get the the preview guids (affected graphs)
            List<Guid> reachableGuidList = changeSetState.EstimateNodesAffectedByASTList(astList);

            // Check if the the affected guids are in the list
            List<Guid> expectedGuid = new List<Guid>{guid2};
            AssertPreview(reachableGuidList, expectedGuid, 1);
        }
Ejemplo n.º 5
0
        public void TestModified02()
        {
            List <string> codes = new List <string>()
            {
                "a = 1; b = 1;",
                "c = 1;"
            };

            // Add nodes a = 1, b = 1
            Guid           guid  = System.Guid.NewGuid();
            List <Subtree> added = new List <Subtree>();

            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[0]));
            var syncData = new GraphSyncData(null, added, null);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer      changeSetState = new ProtoScript.Runners.ChangeSetComputer(core, runtimeCore);
            List <AssociativeNode> astList        = changeSetState.GetDeltaASTList(syncData);

            // Modify contents to c = 1
            List <Subtree> modified = new List <Subtree>();

            modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[1]));
            syncData = new GraphSyncData(null, null, modified);

            // Get astlist from ChangeSetComputer
            astList = changeSetState.GetDeltaASTList(syncData);

            // Get expected ASTList
            // The list must be in the order that it is expected
            List <string> expectedCode = new List <string>()
            {
                "b = null; a = null; c = 1;"
            };
            List <AssociativeNode> expectedAstList = ProtoCore.Utils.CoreUtils.BuildASTList(core, expectedCode);

            // Compare ASTs to be equal
            for (int n = 0; n < astList.Count; ++n)
            {
                AssociativeNode node1   = astList[n];
                AssociativeNode node2   = expectedAstList[n];
                bool            isEqual = node1.Equals(node2);
                Assert.IsTrue(isEqual);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deep clone the change set computer
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public ChangeSetComputer Clone()
        {
            ChangeSetComputer comp = new ChangeSetComputer(this.core, this.runtimeCore);

            comp.currentSubTreeList = new Dictionary<Guid, Subtree>();
            foreach (var subTreePairs in currentSubTreeList)
            {
                comp.currentSubTreeList.Add(subTreePairs.Key, subTreePairs.Value); 
            }

            comp.csData = new ChangeSetData();
            comp.csData.ContainsDeltaAST = csData.ContainsDeltaAST;
            comp.csData.DeletedBinaryExprASTNodes = new List<AssociativeNode>(csData.DeletedBinaryExprASTNodes);
            comp.csData.DeletedFunctionDefASTNodes = new List<AssociativeNode>(csData.DeletedFunctionDefASTNodes);
            comp.csData.RemovedBinaryNodesFromModification = new List<AssociativeNode>(csData.RemovedBinaryNodesFromModification);
            comp.csData.ModifiedNodesForRuntimeSetValue = new List<AssociativeNode>(csData.ModifiedNodesForRuntimeSetValue);
            comp.csData.RemovedFunctionDefNodesFromModification = new List<AssociativeNode>(csData.RemovedFunctionDefNodesFromModification);
            comp.csData.ForceExecuteASTList = new List<AssociativeNode>(csData.ForceExecuteASTList);
            comp.csData.ModifiedFunctions = new List<AssociativeNode>(csData.ModifiedFunctions);
            comp.csData.ModifiedNestedLangBlock = new List<AssociativeNode>(csData.ModifiedNestedLangBlock);
            return comp;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Re-initializes the LiveRunner to reset the VM 
 /// Used temporarily when importing libraries on-demand during delta execution
 /// Will be deprecated once this is supported by the core language
 /// </summary>
 public void ReInitializeLiveRunner()
 {
     runner = new ProtoScriptRunner();
     deltaSymbols = 0;
     InitCore();
     staticContext = new ProtoCore.CompileTime.Context();
     changeSetComputer = new ChangeSetComputer(runnerCore, runtimeCore);
     CLRModuleType.ClearTypes();
 }
Ejemplo n.º 8
0
        public LiveRunner(Configuration configuration)
        {
            this.configuration = configuration;

            runner = new ProtoScriptRunner();

            InitCore();

            taskQueue = new Queue<Task>();

            workerThread = new Thread(new ThreadStart(TaskExecMethod));
            workerThread.IsBackground = true;
            workerThread.Start();

            staticContext = new ProtoCore.CompileTime.Context();

            terminating = false;
            changeSetComputer = new ChangeSetComputer(runnerCore, runtimeCore);
            changeSetApplier = new ChangeSetApplier();
        }
Ejemplo n.º 9
0
        public LiveRunner(Configuration configuration)
        {
            this.configuration = configuration;

            runner = new ProtoScriptRunner();

            InitCore();

            staticContext = new ProtoCore.CompileTime.Context();

            changeSetComputer = new ChangeSetComputer(runnerCore, runtimeCore);
            changeSetApplier = new ChangeSetApplier();
        }
Ejemplo n.º 10
0
        public void TestPreviewModify2Nodes02()
        {
            List <string> codes = new List <string>()
            {
                @"
                    a = 1;
                ",

                @"
                    b = 2;
                ",

                @"
                    x = a;
                ",

                @"
                    y = b;
                ",

                @"
                    z = b;
                ",

                @"
                    a = 10;
                ",
                @"
                    b = 20;
                ",
            };

            Guid guid1 = System.Guid.NewGuid();
            Guid guid2 = System.Guid.NewGuid();
            Guid guid3 = System.Guid.NewGuid();
            Guid guid4 = System.Guid.NewGuid();
            Guid guid5 = System.Guid.NewGuid();

            // Create and run the graph
            List <Subtree> added = new List <Subtree>();

            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[0]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid2, codes[1]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid3, codes[2]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid4, codes[3]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid5, codes[4]));
            var syncData = new GraphSyncData(null, added, null);

            liveRunner.UpdateGraph(syncData);


            // Modify [a = 1;] to [a = 10;]
            // Modify [b = 2;] to [b = 20;]
            List <Subtree> modified = new List <Subtree>();

            modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[5]));
            modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid2, codes[6]));
            syncData = new GraphSyncData(null, null, modified);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer      changeSetState = new ProtoScript.Runners.ChangeSetComputer(liveRunner.Core, liveRunner.RuntimeCore);
            List <AssociativeNode> astList        = changeSetState.GetDeltaASTList(syncData);

            // Get the the preview guids (affected graphs)
            List <Guid> reachableGuidList = changeSetState.EstimateNodesAffectedByASTList(astList);

            // Check if the the affected guids are in the list
            List <Guid> expectedGuid = new List <Guid> {
                guid1, guid2, guid3, guid4, guid5
            };

            AssertPreview(reachableGuidList, expectedGuid);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Re-initializes the LiveRunner to reset the VM 
        /// Used temporarily when importing libraries on-demand during delta execution
        /// Will be deprecated once this is supported by the core language
        /// </summary>
        public void ReInitializeLiveRunner()
        {
            runner = new ProtoScriptTestRunner();

            executionOptions = new Options();
            deltaSymbols = 0;

            coreOptions = null;
            InitOptions();
            InitCore();

            staticContext = new ProtoCore.CompileTime.Context();

            changeSetComputer = new ChangeSetComputer(runnerCore);

            CLRModuleType.ClearTypes();
        }
Ejemplo n.º 12
0
        private void InitRunner(Options options)
        {
            graphCompiler = GraphToDSCompiler.GraphCompiler.CreateInstance();
            graphCompiler.SetCore(GraphUtilities.GetCore());
            runner = new ProtoScriptTestRunner();

            executionOptions = options;
            InitOptions();
            InitCore();


            taskQueue = new Queue<Task>();

            workerThread = new Thread(new ThreadStart(TaskExecMethod));


            workerThread.IsBackground = true;
            workerThread.Start();

            staticContext = new ProtoCore.CompileTime.Context();

            terminating = false;
            changeSetComputer = new ChangeSetComputer(runnerCore);
            changeSetApplier = new ChangeSetApplier();
        }
Ejemplo n.º 13
0
        public LiveRunner(Configuration configuration)
        {
            this.configuration = configuration;

            graphCompiler = GraphCompiler.CreateInstance();
            graphCompiler.SetCore(GraphUtilities.GetCore());

            runner = new ProtoScriptTestRunner();

            InitCore();

            taskQueue = new Queue<Task>();

            workerThread = new Thread(new ThreadStart(TaskExecMethod));
            workerThread.IsBackground = true;
            workerThread.Start();

            staticContext = new ProtoCore.CompileTime.Context();

            terminating = false;
            changeSetComputer = new ChangeSetComputer(runnerCore);
            changeSetApplier = new ChangeSetApplier();
        }
        public void TestModified02()
        {
            List<string> codes = new List<string>() 
            {
                "a = 1; b = 1;",
                "c = 1;"
            };

            // Add nodes a = 1, b = 1
            Guid guid = System.Guid.NewGuid();
            List<Subtree> added = new List<Subtree>();
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[0]));
            var syncData = new GraphSyncData(null, added, null);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer changeSetState = new ProtoScript.Runners.ChangeSetComputer(core, runtimeCore);
            List<AssociativeNode> astList = changeSetState.GetDeltaASTList(syncData);

            // Modify contents to c = 1
            List<Subtree> modified = new List<Subtree>();
            modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[1]));
            syncData = new GraphSyncData(null, null, modified);

            // Get astlist from ChangeSetComputer
            astList = changeSetState.GetDeltaASTList(syncData);

            // Get expected ASTList
            // The list must be in the order that it is expected
            List<string> expectedCode = new List<string>() 
            {
                "b = null; a = null; c = 1;"
            };
            List<AssociativeNode> expectedAstList = ProtoCore.Utils.CoreUtils.BuildASTList(core, expectedCode);

            // Compare ASTs to be equal
            for (int n = 0; n < astList.Count; ++n)
            {
                AssociativeNode node1 = astList[n];
                AssociativeNode node2 = expectedAstList[n];
                bool isEqual = node1.Equals(node2);
                Assert.IsTrue(isEqual);
            }
        }
Ejemplo n.º 15
0
        public void TestPreviewModify2Nodes02()
        {
            List<string> codes = new List<string>() 
            {
               @"
                    a = 1;
                ",
                 
               @"
                    b = 2;
                ",

               @"
                    x = a;
                ",

               @"
                    y = b;
                ",

               @"
                    z = b;
                ",
                 
               @"
                    a = 10;
                ",
               @"
                    b = 20;
                ",
            };

            Guid guid1 = System.Guid.NewGuid();
            Guid guid2 = System.Guid.NewGuid();
            Guid guid3 = System.Guid.NewGuid();
            Guid guid4 = System.Guid.NewGuid();
            Guid guid5 = System.Guid.NewGuid();

            // Create and run the graph 
            List<Subtree> added = new List<Subtree>();
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[0]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid2, codes[1]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid3, codes[2]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid4, codes[3]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid5, codes[4]));
            var syncData = new GraphSyncData(null, added, null);
            liveRunner.UpdateGraph(syncData);


            // Modify [a = 1;] to [a = 10;] 
            // Modify [b = 2;] to [b = 20;] 
            List<Subtree> modified = new List<Subtree>();
            modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[5]));
            modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid2, codes[6]));
            syncData = new GraphSyncData(null, null, modified);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer changeSetState = new ProtoScript.Runners.ChangeSetComputer(liveRunner.Core, liveRunner.RuntimeCore);
            List<AssociativeNode> astList = changeSetState.GetDeltaASTList(syncData);

            // Get the the preview guids (affected graphs)
            List<Guid> reachableGuidList = changeSetState.EstimateNodesAffectedByASTList(astList);

            // Check if the the affected guids are in the list
            List<Guid> expectedGuid = new List<Guid> { guid1, guid2, guid3, guid4, guid5 };
            AssertPreview(reachableGuidList, expectedGuid);
        }