Пример #1
0
        public void Init(GherkinBuffer buffer, bool isPartialScan)
        {
            gherkinBuffer = buffer;

            InitializeFirstBlock(gherkinBuffer.GetLineStartPosition(gherkinBuffer.LineOffset));
            Asserter.Assert(currentFileBlockBuilder != null, "no current file block builder");
        }
Пример #2
0
        public void GetResults_ShowEachStringsMergedWithEachValueOfKeyValuePairs()
        {
            Query allStrings =
                new Query(typeof(TestMultiple)).ShowEach("Strings").ForEach("KeyValuePairs").
                Show("Value");
            IEnumerable <IDictionary <string, object> > results = allStrings.GetResults(item);

            Dictionary <string, object>[] expectedResult = new Dictionary <string, object>[]
            {
                new Result(
                    new KV("Strings",
                           "string1"),
                    new KV("Value",
                           "value1")),
                new Result(
                    new KV("Strings",
                           "string1"),
                    new KV("Value",
                           "value2")),
                new Result(
                    new KV("Strings",
                           "string2"),
                    new KV("Value",
                           "value1")),
                new Result(
                    new KV("Strings",
                           "string2"),
                    new KV("Value",
                           "value2"))
            };

            Asserter.Assert(new DictionaryContentAsserter <string, object>(expectedResult, results));
        }
        private GherkinTextBufferChange GetTextBufferChange(TextContentChangedEventArgs textContentChangedEventArgs)
        {
            Asserter.Assert(textContentChangedEventArgs.Changes.Count > 0, "There are no text changes");

            var startLine      = int.MaxValue;
            var endLine        = 0;
            var startPosition  = int.MaxValue;
            var endPosition    = 0;
            var lineCountDelta = 0;
            var positionDelta  = 0;

            var beforeTextSnapshot = textContentChangedEventArgs.Before;
            var afterTextSnapshot  = textContentChangedEventArgs.After;

            foreach (var change in textContentChangedEventArgs.Changes)
            {
                startLine = Math.Min(startLine, beforeTextSnapshot.GetLineNumberFromPosition(change.OldPosition));
                endLine   = Math.Max(endLine, afterTextSnapshot.GetLineNumberFromPosition(change.NewEnd));

                startPosition   = Math.Min(startPosition, change.OldPosition);
                endPosition     = Math.Max(endPosition, change.NewEnd);
                lineCountDelta += change.LineCountDelta;
                positionDelta  += change.Delta;
            }

            return(new GherkinTextBufferChange(
                       startLine == endLine ? GherkinTextBufferChangeType.SingleLine : GherkinTextBufferChangeType.MultiLine,
                       startLine, endLine,
                       startPosition, endPosition,
                       lineCountDelta, positionDelta,
                       afterTextSnapshot));
        }
Пример #4
0
        public void Permute_SingleItem_WithEmptyList_NoChange()
        {
            List <Dictionary <string, int> > result = GetSingleItemResult();

            Permuter.Permute(result, "int2", new int[] {});
            Asserter.Assert(new DictionaryContentAsserter <string, int>(GetSingleItemResult(), result));
        }
Пример #5
0
        public void GetResults_ShowStoredStringAndStoredStringsForEachChildren_ThreeItems()
        {
            Query allStoredIntsInChildren =
                new Query(typeof(PalasoTestItem)).Show("StoredString").ForEach("ChildItemList").Show(
                    "StoredString", "ChildStoredString");

            IEnumerable <IDictionary <string, object> > results =
                allStoredIntsInChildren.GetResults(item);

            Dictionary <string, object>[] expectedResult = new Dictionary <string, object>[]
            {
                new Result(
                    new KV(
                        "StoredString",
                        "top"),
                    new KV(
                        "ChildStoredString",
                        "1")),
                new Result(
                    new KV(
                        "StoredString",
                        "top"),
                    new KV(
                        "ChildStoredString",
                        "2")),
                new Result(
                    new KV(
                        "StoredString",
                        "top"),
                    new KV(
                        "ChildStoredString",
                        "3"))
            };
            Asserter.Assert(new DictionaryContentAsserter <string, object>(expectedResult, results));
        }
Пример #6
0
        public void Permute_TwoRowsWithSingleItem_WithEmptyListOfList_NoChange()
        {
            List <Dictionary <string, int> > result = GetTwoRowsWithSingleItemEachResult();

            Permuter.Permute(result, GetEmptyResult());

            Asserter.Assert(new DictionaryContentAsserter <string, int>(GetTwoRowsWithSingleItemEachResult(), result));
        }
Пример #7
0
        public void Permute_Empty_WithEmptyListOfList_Empty()
        {
            List <Dictionary <string, int> > result = GetEmptyResult();

            Permuter.Permute(result, GetEmptyResult());

            Asserter.Assert(new DictionaryContentAsserter <string, int>(GetEmptyResult(), result));
        }
Пример #8
0
        public void Permute_SingleRowWithTwoItems_WithEmptyListOfList_NoChange()
        {
            List <Dictionary <string, int> > result = GetSingleRowWithTwoItemsResult();

            Permuter.Permute(result, GetEmptyResult());

            Asserter.Assert(new DictionaryContentAsserter <string, int>(GetSingleRowWithTwoItemsResult(), result));
        }
Пример #9
0
        public void Permute_Empty_WithTwoRowsOfDoubleItems_TwoRowsOfDoubleItems()
        {
            List <Dictionary <string, int> > result = GetEmptyResult();

            Permuter.Permute(result, GetTwoRowsWithDoubleItemsResult());

            Asserter.Assert(new DictionaryContentAsserter <string, int>(GetTwoRowsWithDoubleItemsResult(), result));
        }
Пример #10
0
        public void GetResultsOnInQuery_With3NestedChildThirdIsNull_NoItems()
        {
            Query all = new Query(typeof(PalasoTestItem)).In("Child").In("Child").In("Child").Show("StoredString");
            IEnumerable <IDictionary <string, object> > results = all.GetResults(item);

            Dictionary <string, object>[] expectedResult = new Dictionary <string, object>[] {};

            Asserter.Assert(new DictionaryContentAsserter <string, object>(expectedResult, results));
        }
Пример #11
0
        public void GetResultsOnForEachQuery_AtLeastOneWithShow_SameAsWithShow()
        {
            Query queryWithAtLeastOne    = new Query(typeof(PalasoTestItem)).ForEach("ChildItemList").AtLeastOne().Show("StoredString");
            Query queryWithOutAtLeastOne = new Query(typeof(PalasoTestItem)).ForEach("ChildItemList").Show("StoredString");
            IEnumerable <IDictionary <string, object> > results        = queryWithAtLeastOne.GetResults(item);
            IEnumerable <IDictionary <string, object> > expectedResult = queryWithOutAtLeastOne.GetResults(item);

            Asserter.Assert(new DictionaryContentAsserter <string, object>(expectedResult, results));
        }
Пример #12
0
        public void GetResultsOnInQuery_WithShow_OneIntItem()
        {
            Query all = new Query(typeof(PalasoTestItem)).In("Child").Show("StoredInt");
            IEnumerable <IDictionary <string, object> > results = all.GetResults(item);

            Dictionary <string, object>[] expectedResult = new Dictionary <string, object>[]
            { new Result(new KV("StoredInt", 24)) };

            Asserter.Assert(new DictionaryContentAsserter <string, object>(expectedResult, results));
        }
Пример #13
0
        public bool IsMouseDown(MouseButton button)
        {
            Asserter.Assert(button != MouseButton.None, "button cannot equal MouseButton.None");

            if (button == MouseButton.Left)
            {
                return(_leftMouseButtonState == ButtonState.Pressed);
            }

            return(_rightMouseButtonState == ButtonState.Pressed);
        }
Пример #14
0
        public void Permute_Empty_WithSingleItem_SingleItem()
        {
            List <Dictionary <string, int> > result = GetEmptyResult();

            Permuter.Permute(result, "int", 9);

            IDictionary <string, int>[] expectedResult = new IDictionary <string, int>[]
            { CreateResult(new KI("int", 9)) };

            Asserter.Assert(new DictionaryContentAsserter <string, int>(expectedResult, result));
        }
Пример #15
0
        public static void RunParallel()
        {
            //const int SIZE = 1000000;
            const int SIZE = 100000;
            //const int SIZE = 10000;
            //const int SIZE = 1000;

            var xs = new List <string>(10240);

            for (int i = 0; i < SIZE; ++i)
            {
                xs.Add("Message #" + (i + 1));
                if (xs.Count % 10240 == 0)
                {
                    Console.WriteLine("count = {0} capacity = {1}", xs.Count, xs.Capacity);
                }
            }

            Console.WriteLine("count = {0} capacity = {1}", xs.Count, xs.Capacity);
            xs.Capacity = xs.Count;
            Console.WriteLine("count = {0} capacity = {1}", xs.Count, xs.Capacity);

            var ys = new List <string>();

            InstrumentedOperation.Test(() =>
            {
                Parallel.ForEach(xs, (x) =>
                {
                    //ys.Add(x);
                    lock (ys) ys.Add(x);
                });
            }, "Synchronization via lock");

            Asserter.Assert(ys.Count == xs.Count, "ys.Count ({0}) == xs.Count ({1})", ys.Count, xs.Count);

            ys = new List <string>();

            InstrumentedOperation.Test(() =>
            {
                Parallel.ForEach(xs,
                                 () => new List <string>(),

                                 (x, state, temp) =>
                {
                    //state.Break();
                    temp.Add(x);
                    return(temp);
                },

                                 (temp) => { lock (ys) ys.AddRange(temp); });
            }, "Synchronization via temporaries");

            Asserter.Assert(ys.Count == xs.Count, "ys.Count ({0}) == xs.Count ({1})", ys.Count, xs.Count);
        }
        public static SnapshotSpan CreateSpan(this IEnumerable <IGherkinFileBlock> changedBlocks, ITextSnapshot textSnapshot)
        {
            Asserter.Assert(changedBlocks.Any(), "there is no changed block");

            int minLineNumber = changedBlocks.First().GetStartLine();
            int maxLineNumber = changedBlocks.Last().GetEndLine();

            var minLine = textSnapshot.GetLineFromLineNumber(minLineNumber);
            var maxLine = minLineNumber == maxLineNumber ? minLine : textSnapshot.GetLineFromLineNumber(maxLineNumber);

            return(new SnapshotSpan(minLine.Start, maxLine.EndIncludingLineBreak));
        }
Пример #17
0
        public void Permute_SingleItem_WithSingleItem_SingleRowWithBothItems()
        {
            List <Dictionary <string, int> > result = GetSingleItemResult();

            Permuter.Permute(result, "value", 9);

            IDictionary <string, int>[] expectedResult = new Dictionary <string, int>[]
            {
                CreateResult(new KI("int", 2),
                             new KI("value", 9))
            };
            Asserter.Assert(new DictionaryContentAsserter <string, int>(expectedResult, result));
        }
Пример #18
0
        public void GetResults_ShowEachStrings_AllStrings()
        {
            Query allStrings = new Query(typeof(TestMultiple)).ShowEach("Strings");
            IEnumerable <IDictionary <string, object> > results = allStrings.GetResults(item);

            Dictionary <string, object>[] expectedResult = new Dictionary <string, object>[]
            {
                new Result(new KV("Strings",
                                  "string1")),
                new Result(new KV("Strings",
                                  "string2"))
            };

            Asserter.Assert(new DictionaryContentAsserter <string, object>(expectedResult, results));
        }
        public void Build(GherkinFileScope gherkinFileEditorInfo, int endLine, int contentEndLine)
        {
            Asserter.Assert(IsComplete, "The block builder is not complete");
            int blockRelativeEndLine        = endLine - KeywordLine;
            int blockRelativeContentEndLine = contentEndLine - KeywordLine;

            if (BlockType == typeof(IInvalidFileBlock))
            {
                Asserter.Assert(gherkinFileEditorInfo.InvalidFileEndingBlock == null, "no invalid file block");
                if (gherkinFileEditorInfo.InvalidFileEndingBlock == null)
                {
                    gherkinFileEditorInfo.InvalidFileEndingBlock =
                        new InvalidFileBlock(StartLine, endLine, blockRelativeContentEndLine, ClassificationSpans.ToArray(), OutliningRegions.ToArray(), Errors.ToArray());
                }
            }
            else if (BlockType == typeof(IHeaderBlock))
            {
                Asserter.Assert(gherkinFileEditorInfo.HeaderBlock == null, "no header block");
                if (gherkinFileEditorInfo.HeaderBlock == null)
                {
                    gherkinFileEditorInfo.HeaderBlock =
                        new HeaderBlock(Keyword, Title, KeywordLine, Tags.ToArray(), BlockRelativeStartLine, blockRelativeEndLine, blockRelativeContentEndLine, ClassificationSpans.ToArray(), OutliningRegions.ToArray(), Errors.ToArray());
                }
            }
            else if (BlockType == typeof(IBackgroundBlock))
            {
                Asserter.Assert(gherkinFileEditorInfo.BackgroundBlock == null, "no background block");
                if (gherkinFileEditorInfo.BackgroundBlock == null)
                {
                    gherkinFileEditorInfo.BackgroundBlock =
                        new BackgroundBlock(Keyword, Title, KeywordLine, BlockRelativeStartLine, blockRelativeEndLine, blockRelativeContentEndLine, ClassificationSpans.ToArray(), OutliningRegions.ToArray(), Errors.ToArray(), Steps.ToArray());
                }
            }
            else if (BlockType == typeof(IScenarioBlock))
            {
                var scenarioBlock = new ScenarioBlock(Keyword, Title, KeywordLine, BlockRelativeStartLine, blockRelativeEndLine, blockRelativeContentEndLine, ClassificationSpans.ToArray(), OutliningRegions.ToArray(), Errors.ToArray(), Steps.ToArray());
                gherkinFileEditorInfo.ScenarioBlocks.Add(scenarioBlock);
            }
            else if (BlockType == typeof(IScenarioOutlineBlock))
            {
                var scenarioBlock = new ScenarioOutlineBlock(Keyword, Title, KeywordLine, BlockRelativeStartLine, blockRelativeEndLine, blockRelativeContentEndLine, ClassificationSpans.ToArray(), OutliningRegions.ToArray(), Errors.ToArray(), Steps.ToArray(), ExampleSets.ToArray());
                gherkinFileEditorInfo.ScenarioBlocks.Add(scenarioBlock);
            }
            else
            {
                throw new NotSupportedException("Block type not supported: " + BlockType);
            }
        }
Пример #20
0
        private GherkinFileScopeChange MergePartialResult(IGherkinFileScope previousScope, IGherkinFileScope partialResult, IScenarioBlock firstAffectedScenario, IScenarioBlock firstUnchangedScenario, int lineCountDelta)
        {
            Debug.Assert(partialResult.HeaderBlock == null, "Partial parse cannot re-parse header");
            Debug.Assert(partialResult.BackgroundBlock == null, "Partial parse cannot re-parse background");

            var changedBlocks = new List <IGherkinFileBlock>();
            var shiftedBlocks = new List <IGherkinFileBlock>();

            var fileScope = new GherkinFileScope(previousScope.GherkinDialect, partialResult.TextSnapshot)
            {
                HeaderBlock     = previousScope.HeaderBlock,
                BackgroundBlock = previousScope.BackgroundBlock
            };

            // inserting the non-affected scenarios
            fileScope.ScenarioBlocks.AddRange(previousScope.ScenarioBlocks.TakeUntilItemExclusive(firstAffectedScenario));

            //inserting partial result
            fileScope.ScenarioBlocks.AddRange(partialResult.ScenarioBlocks);
            changedBlocks.AddRange(partialResult.ScenarioBlocks);
            if (partialResult.InvalidFileEndingBlock != null)
            {
                Asserter.Assert(firstUnchangedScenario == null, "first affected scenario is not null");
                // the last scenario was changed, but it became invalid
                fileScope.InvalidFileEndingBlock = partialResult.InvalidFileEndingBlock;
                changedBlocks.Add(fileScope.InvalidFileEndingBlock);
            }

            if (firstUnchangedScenario != null)
            {
                Asserter.Assert(partialResult.InvalidFileEndingBlock == null, "there is an invalid file ending block");

                // inserting the non-effected scenarios at the end
                var shiftedScenarioBlocks = previousScope.ScenarioBlocks.SkipFromItemInclusive(firstUnchangedScenario)
                                            .Select(scenario => scenario.Shift(lineCountDelta)).ToArray();
                fileScope.ScenarioBlocks.AddRange(shiftedScenarioBlocks);
                shiftedBlocks.AddRange(shiftedScenarioBlocks);

                if (previousScope.InvalidFileEndingBlock != null)
                {
                    fileScope.InvalidFileEndingBlock = previousScope.InvalidFileEndingBlock.Shift(lineCountDelta);
                    shiftedBlocks.Add(fileScope.InvalidFileEndingBlock);
                }
            }

            return(new GherkinFileScopeChange(fileScope, false, false, changedBlocks, shiftedBlocks));
        }
Пример #21
0
        public void Unlock()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("ProcessLock");
            }
            if (!_created)
            {
                throw new InvalidOperationException();
            }

            Asserter.Assert(_mutex != null, "_mutex != null", "_mutex cannot be null");

            _mutex.ReleaseMutex();
            _mutex   = null;
            _created = false;
        }
Пример #22
0
        private GherkinFileScopeChange PartialParse(GherkinTextBufferChange change, IGherkinFileScope previousScope)
        {
            _visualStudioTracer.Trace("Start incremental parsing", ParserTraceCategory);
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            _partialParseCount++;

            var textSnapshot = change.ResultTextSnapshot;

            var firstAffectedScenario = GetFirstAffectedScenario(change, previousScope);

            Asserter.Assert(firstAffectedScenario != null, "first affected scenario is null");
            int parseStartPosition = textSnapshot.GetLineFromLineNumber(firstAffectedScenario.GetStartLine()).Start;

            string fileContent = textSnapshot.GetText(parseStartPosition, textSnapshot.Length - parseStartPosition);

            var gherkinListener = new GherkinTextBufferPartialParserListener(
                previousScope.GherkinDialect,
                textSnapshot, _projectScope,
                previousScope,
                change.EndLine, change.LineCountDelta);

            var scanner = new GherkinScanner(previousScope.GherkinDialect, fileContent, firstAffectedScenario.GetStartLine());

            IScenarioBlock firstUnchangedScenario = null;

            try
            {
                scanner.Scan(gherkinListener);
            }
            catch (PartialListeningDoneException partialListeningDoneException)
            {
                firstUnchangedScenario = partialListeningDoneException.FirstUnchangedScenario;
            }

            var partialResult = gherkinListener.GetResult();

            var result = MergePartialResult(previousScope, partialResult, firstAffectedScenario, firstUnchangedScenario, change.LineCountDelta);

            stopwatch.Stop();
            TraceFinishParse(stopwatch, "incremental", result);
            return(result);
        }
Пример #23
0
        public static GherkinTextBufferChange Merge(GherkinTextBufferChange change1, GherkinTextBufferChange change2)
        {
            Asserter.Assert(change1.ResultTextSnapshot.Version.VersionNumber <= change2.ResultTextSnapshot.Version.VersionNumber, "different snapshot version numbers for merging");
            if (change1.Type == GherkinTextBufferChangeType.EntireFile || change2.Type == GherkinTextBufferChangeType.EntireFile)
            {
                return(CreateEntireBufferChange(change2.ResultTextSnapshot));
            }

            return(new GherkinTextBufferChange(
                       change1.Type == GherkinTextBufferChangeType.MultiLine || change2.Type == GherkinTextBufferChangeType.MultiLine ? GherkinTextBufferChangeType.MultiLine : GherkinTextBufferChangeType.SingleLine,
                       Math.Min(change1.StartLine, change2.StartLine),
                       Math.Max(change1.EndLine, change2.EndLine),
                       Math.Min(change1.StartPosition, change2.StartPosition),
                       Math.Max(change1.EndPosition, change2.EndPosition),
                       change1.LineCountDelta + change2.LineCountDelta,
                       change1.PositionDelta + change2.PositionDelta,
                       change2.ResultTextSnapshot));
        }
        /// <summary>
        /// Called the very first time the singleton instance is accessed, and thus, lazily
        /// instanced. This is automatically called in Awake() too.
        /// </summary>
        /// <param name="force"></param>
        /// <returns></returns>
        public override bool Init(bool force)
        {
            bool proceed = base.Init(force);

            if (!proceed)
            {
                return(false);
            }

            cam = FindObjectOfType <Camera>();
            Asserter.Assert(cam != null, "There is no camera in the scene!");
            gameObject.hideFlags = HideFlags.NotEditable;

            CreateGrid();
            BakeNeighbors();
            BakeObstacles();

            InitDebugRender();
            BuildGridMesh();

            return(true);
        }
Пример #25
0
        private IChainStep <T> ComputeChainSequence()
        {
            DirectedAcyclicGraph <IChainStep <T> > graph = new DirectedAcyclicGraph <IChainStep <T> >();

            foreach (var step in _steps.Values)
            {
                graph.AddNode(new GraphNode <IChainStep <T> >(step.Name, step));
            }

            foreach (var step in _steps.Values)
            {
                GraphNode <IChainStep <T> > node = graph.GetNode(step.Name);

                foreach (var dependency in step.Dependencies)
                {
                    if (dependency.MustExist)
                    {
                        Asserter.Assert(
                            _steps.ContainsKey(dependency.Name),
                            string.Format(
                                "Cannot execute chain '{0}' because step '{1}' has a mandatory dependency on step '{2}' and '{2}' cannot be found in the {0} chain.",
                                _name, step.Name, dependency.Name));
                    }

                    var dependentNode = graph.GetNode(dependency.Name);
                    node.AddDependent(dependentNode);
                }
            }

            var ordered = graph.ComputeDependencyOrderedList().Select(node => node.Item).ToArray();

            for (int i = ordered.Length - 2; i > 0; i--)
            {
                ordered[i].Successor = ordered[i + 1];
            }

            return(ordered[0]);
        }
Пример #26
0
 private static void AssertResult(IEnumerable <IDictionary <string, int> > expectedResult,
                                  IEnumerable <IDictionary <string, int> > actualResult)
 {
     Asserter.Assert(new DictionaryContentAsserter <string, int>(expectedResult, actualResult));
 }