Exemple #1
0
        private static StringBuilder?PrepareToReportValue(string?name, int lineNumber)
        {
            if (!TryFindLastStepAtLineNumber(lineNumber, out var step, out var stepIndex))
            {
                if (_steps.Count >= ReportLimits.MaxStepCount)
                {
                    return(null);
                }
                step = new Step(lineNumber)
                {
                    LineSkipped = true
                };
                _steps.Add(step);
                stepIndex = _steps.Count - 1;
            }

            if (!_stepNotesCountPerLine.TryGetValue(step.LineNumber, out var countPerLine))
            {
                countPerLine = 0;
            }

            if (step.Notes == null)
            {
                countPerLine += 1;
                _stepNotesCountPerLine[step.LineNumber] = countPerLine;

                if (countPerLine == ReportLimits.MaxStepNotesPerLine + 1)
                {
                    step.Notes        = new StringBuilder("…");
                    _steps[stepIndex] = step;
                    return(null);
                }
            }

            if (countPerLine >= ReportLimits.MaxStepNotesPerLine + 1)
            {
                return(null);
            }

            step.ValueCount  += 1;
            _steps[stepIndex] = step;
            if (step.ValueCount > ReportLimits.MaxValuesPerStep + 1)
            {
                return(null);
            }

            var notes = step.Notes;

            if (notes == null)
            {
                notes             = new StringBuilder();
                step.Notes        = notes;
                _steps[stepIndex] = step;
            }

            if (notes.Length > 0)
            {
                notes.Append(", ");
            }

            if (step.ValueCount == ReportLimits.MaxValuesPerStep + 1)
            {
                notes.Append("…");
                return(null);
            }

            if (name != null)
            {
                ValuePresenter.AppendStringTo(notes, name, ReportLimits.ValueName);
                notes.Append(": ");
            }

            return(notes);
        }
Exemple #2
0
        public static void ReportValue <T>(T value, string name, int lineNumber)
        {
            if (!TryFindLastStepAtLineNumber(lineNumber, out var step, out var stepIndex))
            {
                if (_steps.Count >= ReportLimits.MaxStepCount)
                {
                    return;
                }
                step = new Step(lineNumber)
                {
                    LineSkipped = true
                };
                _steps.Add(step);
                stepIndex = _steps.Count - 1;
            }

            if (!_stepNotesCountPerLine.TryGetValue(step.LineNumber, out int countPerLine))
            {
                countPerLine = 0;
            }

            if (step.Notes == null)
            {
                countPerLine += 1;
                _stepNotesCountPerLine[step.LineNumber] = countPerLine;

                if (countPerLine == ReportLimits.MaxStepNotesPerLine + 1)
                {
                    step.Notes        = new StringBuilder("…");
                    _steps[stepIndex] = step;
                    return;
                }
            }

            if (countPerLine >= ReportLimits.MaxStepNotesPerLine + 1)
            {
                return;
            }

            step.ValueCount += 1;
            if (step.ValueCount > ReportLimits.MaxValuesPerStep + 1)
            {
                _steps[stepIndex] = step;
                return;
            }

            var notes = step.Notes;

            if (notes == null)
            {
                notes      = new StringBuilder();
                step.Notes = notes;
            }

            if (notes.Length > 0)
            {
                notes.Append(", ");
            }

            if (step.ValueCount == ReportLimits.MaxValuesPerStep + 1)
            {
                notes.Append("…");
                _steps[stepIndex] = step;
                return;
            }

            if (name != null)
            {
                ValuePresenter.AppendStringTo(notes, name, ReportLimits.ValueName);
                notes.Append(": ");
            }
            ValuePresenter.AppendTo(notes, value, ReportLimits.ValueValue);
            // Have to reassign in case we set Notes
            _steps[stepIndex] = step;
        }