public static JSParserResult RunTest(string sourceName, string resultName) { var source = TestsHelper.GetEmbeddedText("JsParser.Test.Parser.Source." + sourceName); // Fix line endings in test files. All should be unix way, but on some GIT clients it is updated automatically. source = source.Replace("\r\n", "\n"); var settings = new JavascriptParserSettings() { Filename = sourceName, }; var actualResult = (new JavascriptParser(settings)).Parse(source); var outDir = "C:\\js_parser_units_output"; Directory.CreateDirectory(outDir); // Save actual hierarchy xml var serialized = SimpleHierarchySerializer.Serialize(actualResult.Nodes); File.WriteAllText(outDir + "\\" + resultName, serialized); // Load test data var resName = "JsParser.Test.Parser.ExpectedResult." + resultName; var passed = false; if (TestsHelper.CheckEmbeddedRes(resName)) { File.WriteAllText(outDir + "\\" + resultName, SimpleHierarchySerializer.Serialize(actualResult.Nodes)); var expectedresultSerialized = TestsHelper.GetEmbeddedText(resName); var expectedresult = SimpleHierarchySerializer.Deserialize <CodeNode>(expectedresultSerialized); // Save expected hierarchy serialized File.WriteAllText(outDir + "\\" + resultName + ".ex", expectedresultSerialized); if (HierarchyComparer.Compare(actualResult.Nodes, expectedresult, new CodeNodeAssertComparer())) { passed = true; } } Assert.IsTrue(passed); return(actualResult); }
public void SimpleHierarchySerializer_Test() { var testData = new Hierarchy <CodeNode>(new CodeNode("Node1", 0, 100, "Comment1")) { Children = new List <Hierarchy <CodeNode> > { new Hierarchy <CodeNode>(new CodeNode("S1", 1, 2)), new Hierarchy <CodeNode>(new CodeNode("S2", 2, 3)) } }; var serialized = SimpleHierarchySerializer.Serialize(testData); var deserialised = SimpleHierarchySerializer.Deserialize <CodeNode>(serialized); var isEqual = HierarchyComparer.Compare(testData, deserialised, CodeNode.GetDefaultComparer()); Assert.IsTrue(isEqual); }
public void SimpleHierarchySerializer_Test2() { var testData = new Hierarchy <CodeNode>(new CodeNode("Node1", 0, 100, "Comment1\r\nHere the second line")) { Children = new List <Hierarchy <CodeNode> > { new Hierarchy <CodeNode>(new CodeNode("S1", 1, 20, "{}\\/+-_=!@#$%^&*;:'<>")), new Hierarchy <CodeNode>(new CodeNode("S2", 20, 40, "Or some xml encoded &#A;&#D; &>")) { Children = new List <Hierarchy <CodeNode> > { new Hierarchy <CodeNode>(new CodeNode("D1", 20, 21)), new Hierarchy <CodeNode>(new CodeNode("D2", 30, 31)) } }, new Hierarchy <CodeNode>(new CodeNode("S3", 40, 60)) { Children = new List <Hierarchy <CodeNode> > { new Hierarchy <CodeNode>(new CodeNode("D3", 40, 41)), new Hierarchy <CodeNode>(new CodeNode("D4", 50, 55)) { Children = new List <Hierarchy <CodeNode> > { new Hierarchy <CodeNode>(new CodeNode("L1", 51, 52)) } } } }, new Hierarchy <CodeNode>(new CodeNode("S4", 60, 70)) } }; var serialized = SimpleHierarchySerializer.Serialize(testData); var deserialised = SimpleHierarchySerializer.Deserialize <CodeNode>(serialized); var isEqual = HierarchyComparer.Compare(testData, deserialised, CodeNode.GetDefaultComparer()); Assert.IsTrue(isEqual); }
/// <summary> /// Processes changes /// </summary> private void ProcessChanges(bool inPlayMode) { /* Calculating the single step change */ _stepDelta = HierarchyComparer.Compare( _oldHierarchy, _newHierarchy ); #if DEBUG if (DebugMode) { Debug.Log(_stepDelta); } #endif //Debug.Log(delta); /** * 2. Handle additions * a) Instantiate component * b) Record transform addition * */ if (inPlayMode) { /** * 1. PLAY mode * Leaving the processing to persistence logic * */ /** * In play mode we need a full delta, so we will be able to re-apply it * after the play mode is stopped * Tracking full delta with each change, because we don't know when * will be the last chance to track it before stopping the play mode * */ _fullDelta = HierarchyComparer.Compare( _originalHierarchy, _newHierarchy ); /** * IMPORTANT: * This was the source of the quite performance killing recursive bug * If this processing take place in play mode, OnHierarchyChange fires in each consequent frame, without ever stopping * TODO: do a special logic for reordering items in play mode * */ AdditionProcessor.Process(_stepDelta.TopLevelAdditions, _stepDelta.Additions); RemovalProcessor.Process(_stepDelta.Removals); MovesProcessor.Process(_stepDelta.Moves); /** * Accumulate delta * */ PersistenceManager.Instance.Delta = _fullDelta; //.Reset(); // TEMP -> create a direct Delta setter //PersistenceManager.Instance.Delta.Accumulate(_fullDelta); } else { /** * 2. EDIT mode * In edit mode, so handling the ordering information immediatelly * Note: the ordering information is all that has to be processed when adding a new component * or a prefab in Edit mode - other things (parent-child relationship etc.) is handled by Unity * */ EditModeAdditionsProcessor.Process(_stepDelta.TopLevelAdditions); EditModeRemovalProcessor.Process(_stepDelta.TopLevelRemovals); EditModeMovesProcessor.Process(_stepDelta.Moves); } _stepDelta.Reset(); // save the current hierarchy _oldHierarchy = _newHierarchy; EditorState.Instance.Adapter = ComponentRegistry.Instance.Get(EditorState.Instance.AdapterId, true) as ComponentAdapter; ChangesProcessedSignal.Emit(); }