Exemplo n.º 1
0
        public static List <CsLineDetails> AssignBaseCommandId(List <CsLineDetails> lstLineDetails)
        {
            for (int len = 0; len < lstLineDetails.Count; len++)
            {
                var lineDetail    = lstLineDetails[len];
                var baseCommandId = GetBaseCommandId(lineDetail.ResolvedStatement);
                lineDetail.BaseCommandId = lineDetail.BaseCommandId == 0 ? baseCommandId : lineDetail.BaseCommandId;
                if (baseCommandId == 0)
                {
                    continue;
                }
                int bracketsCount = 0;
                for (int remLength = len + 1; remLength < lstLineDetails.Count; remLength++)
                {
                    var element = lstLineDetails[remLength];
                    // following lines are replaced with previous logic...
                    // this one is more trusted and checked it with multiple files...
                    var matches = OpenCloseBraceRegex.Matches(element.ResolvedStatement);
                    foreach (Match match in matches)
                    {
                        if (match.Groups["OpenMatch"].Success)
                        {
                            bracketsCount++;
                        }
                        if (match.Groups["CloseMatch"].Success)
                        {
                            bracketsCount--;
                        }
                    }
                    if (bracketsCount != 0)
                    {
                        continue;
                    }
                    if (baseCommandId == 1)
                    {
                        lstLineDetails[remLength].BaseCommandId = 2;
                    }
                    if (baseCommandId == 19)
                    {
                        lstLineDetails[remLength].BaseCommandId = 20;
                    }
                    if (baseCommandId == 8) // Set method name here...
                    {
                        string methodName       = MethodNameRegex.Match(lineDetail.ResolvedStatement).Groups["MethodName"].Value;
                        string actualMethodName = Regex.Replace(methodName, "<.*>", "").Trim();
                        lineDetail.MethodName = actualMethodName;
                        lstLineDetails[remLength].BaseCommandId = 9;
                    }
                    if (baseCommandId == 3)
                    {
                        lstLineDetails[remLength].BaseCommandId = 4;
                    }
                    if (baseCommandId == 10)
                    {
                        lstLineDetails[remLength].BaseCommandId = 2;
                        for (int ifLen = remLength - 1; ifLen >= 0; ifLen--)
                        {
                            if (lstLineDetails[ifLen].BaseCommandId != 2)
                            {
                                continue;
                            }
                            lstLineDetails[ifLen].BaseCommandId = 0;
                            break;
                        }
                    }
                    if (baseCommandId == 88)
                    {
                        lstLineDetails[remLength].BaseCommandId = 89;
                    }
                    if (baseCommandId == 78)
                    {
                        lstLineDetails[remLength].BaseCommandId = 79;
                    }
                    if (baseCommandId == 58)
                    {
                        lstLineDetails[remLength].BaseCommandId = 59;
                    }
                    if (baseCommandId == 99)
                    {
                        lstLineDetails[remLength].BaseCommandId = 100;
                    }
                    if (baseCommandId == 48)
                    {
                        lstLineDetails[remLength].BaseCommandId = 49;
                    }

                    break;
                }
            }

            return(lstLineDetails);
        }
Exemplo n.º 2
0
        // Return the source code location of the caller located callDepth frames up the stack.
        // ICU4N NOTE: In order for this to work in .NET Standard 1.x in Release mode, the
        // [MethodImpl(MethodImplOptions.NoInlining)] attribute must be added to each method/property this
        // searches for.
        protected static string SourceLocation()
        {
#if !FEATURE_STACKTRACE
            var sourceLines =
                Environment.StackTrace
                .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Reverse().ToList();

            using (var iter = sourceLines.GetEnumerator())
            {
                while (iter.MoveNext())
                {
                    var line = iter.Current;

                    if (line.Contains("System.Environment.GetStackTrace") || line.Contains("get_StackTrace"))
                    {
                        continue;
                    }

                    if (line.TrimStart().StartsWith("at NUnit.", StringComparison.Ordinal) || line.TrimStart().StartsWith("at Microsoft.VisualStudio", StringComparison.Ordinal) || line.Contains("Invoke"))
                    {
                        continue;
                    }

                    if (line.Contains("TestFmwk.cs") || line.Contains("AbstractTestLog.cs"))
                    {
                        continue;
                    }

                    var match = MethodNameRegex.Match(line);

                    if (match.Success)
                    {
                        var methodName = match.Groups["method"].Value;
                        if (methodName.StartsWith("Test", StringComparison.Ordinal) || methodName.StartsWith("test", StringComparison.Ordinal) || methodName.Equals("Main"))
                        {
                            var matchFileName = FileNameRegex.Match(line);
                            if (matchFileName.Success)
                            {
                                return(matchFileName.Groups["filename"].Value);
                            }

                            // If the regex fails, just return the line as is.
                            return(line);
                        }
                    }
                }
            }
#else
            // Walk up the stack to the first call site outside this file
            StackTrace trace = new StackTrace(true);
            foreach (var frame in trace.GetFrames())
            {
                string source = frame.GetFileName();
                if (source != null && !source.EndsWith("TestFmwk.cs", StringComparison.Ordinal) && !source.EndsWith("AbstractTestLog.cs", StringComparison.Ordinal))
                {
                    string methodName = frame.GetMethod().Name;
                    if (methodName != null &&
                        (methodName.StartsWith("Test", StringComparison.Ordinal) || methodName.StartsWith("test", StringComparison.Ordinal) || methodName.Equals("Main")))
                    {
                        return("(" + source + ":" + frame.GetFileLineNumber() + ") ");
                    }
                }
            }
#endif
            throw new Exception();
        }