コード例 #1
0
        public MatcherParseResult parseLine(int lineNumber, string line)
        {
            int currentIndex   = 0;
            int currentMatcher = 0;
            List <IComparable> resultValues = new List <IComparable>();

            foreach (IMatcher <IComparable> matcher in Matchers)
            {
                // skip whitespace
                for (; currentIndex < line.Length; currentIndex++)
                {
                    if (!char.IsWhiteSpace(line[currentIndex]))
                    {
                        break;
                    }
                }

                IMatcherResult <IComparable> matcherResult = matcher.match(line, currentIndex);
                if (matcherResult == null)
                {
                    LogAtom failed = new LogAtom(line, lineNumber);
                    failed.MetaValues = resultValues;

                    // not very sophisticated empiric method to decide if a line is a new atom or belongs to previous
                    if (currentMatcher < MatchesNeededForAtomDetected)
                    {
                        // failed, not even an atom
                        failed.MetaValues.Clear();
                        return(new MatcherParseResult(failed));
                    }
                    else
                    {
                        // failed, new atom
                        return(new MatcherParseResult(failed, false));
                    }
                }
                else
                {
                    resultValues.Add(matcherResult.Value);
                    currentIndex = matcherResult.NextIndex;
                }
                currentMatcher++;
            }

            // new (successful) atom
            resultValues.Add(RemainingLineMatcher.match(line, currentIndex).Value);
            LogAtom success = new LogAtom(line, lineNumber);

            success.MetaValues = resultValues;
            return(new MatcherParseResult(success, true));
        }
コード例 #2
0
ファイル: MatcherRunner.cs プロジェクト: tammylotter/NExpect
        public static void ProcessMatcherResult(
            bool negated,
            IMatcherResult result
            )
        {
            var isPass = negated
                ? !result.Passed
                : result.Passed;

            if (isPass)
            {
                return;
            }
            Assertions.Throw(result.Message, result.LocalException);
        }
コード例 #3
0
        public void RunMatcher(Func <T, IMatcherResult> matcher)
        {
            IMatcherResult result = null;

            try
            {
                result = matcher(Actual);
                var isPass = _negated ? !result.Passed : result.Passed;
                if (isPass)
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                // TODO: make this better, ie, include the exception as an inner
                Assertion.Throw(ex.Message);
                return;
            }
            Assertion.Throw(result.Message);
        }