void AssertFormat(string result, params object[] args)
        {
            foreach (object ob in args)
            {
                if (ob is string)
                {
                    formatter.IndentString = (string)ob;
                }
                if (ob is WrappingType)
                {
                    formatter.Wrap = (WrappingType)ob;
                }
                if (ob is bool)
                {
                    formatter.TabsAsSpaces = (bool)ob;
                }
                if (ob is int)
                {
                    formatter.MaxColumns = (int)ob;
                }
            }

            string id = result + string.Format(" IndentString:{0}, LeftMargin:{1}, MaxColumns:{2}, TabsAsSpaces:{3}, TabWidth:{4}, Wrap:{5}", formatter.IndentString, formatter.LeftMargin, formatter.MaxColumns, formatter.TabsAsSpaces, formatter.TabWidth, formatter.Wrap);

            id = id.Replace("\n", "\\n").Replace("\t", "\\t");

            formatter.Clear();
            formatter.Append(Text);
            Assert.AreEqual(result, formatter.ToString(), id);
        }
Esempio n. 2
0
        public override string ToString()
        {
            if (messages.Count == 0)
            {
                return(string.Empty);
            }

            CommitMessageStyle message_style = MessageFormat.Style;

            TextFormatter formatter = new TextFormatter();

            formatter.MaxColumns   = MessageFormat.MaxColumns;
            formatter.TabWidth     = MessageFormat.TabWidth;
            formatter.TabsAsSpaces = MessageFormat.TabsAsSpaces;

            if (message_style.Header.Length > 0)
            {
                string [,] tags = new string[, ] {
                    { "AuthorName", uinfo.Name }, { "AuthorEmail", uinfo.Email }
                };
                formatter.Append(StringParserService.Parse(message_style.Header, tags));
            }

            formatter.IndentString = message_style.Indent;

            int m_i = 0;

            string fileSeparator1 = message_style.FileSeparator;
            string fileSeparator2 = string.Empty;

            int si = message_style.FileSeparator.IndexOf('\n');

            if (si != -1 && si < message_style.FileSeparator.Length - 1)
            {
                fileSeparator1 = message_style.FileSeparator.Substring(0, si + 1);
                fileSeparator2 = message_style.FileSeparator.Substring(si + 1);
            }

            formatter.Wrap                 = WrappingType.Word;
            formatter.LeftMargin           = message_style.LineAlign;
            formatter.ParagraphStartMargin = 0;

            foreach (KeyValuePair <string, List <string> > message in messages)
            {
                List <string> paths = message.Value;
                paths.Sort((a, b) => a.Length.CompareTo(b.Length));

                formatter.BeginWord();

                formatter.Append(message_style.FirstFilePrefix);
                for (int i = 0, n = paths.Count; i < n; i++)
                {
                    if (i > 0)
                    {
                        formatter.Append(fileSeparator1);
                        formatter.EndWord();
                        formatter.BeginWord();
                        formatter.Append(fileSeparator2);
                    }
                    formatter.Append(paths [i]);
                }

                formatter.Append(message_style.LastFilePostfix);
                formatter.EndWord();
                formatter.Append(message.Key);

                if (m_i++ < messages.Count - 1)
                {
                    formatter.AppendLine();
                    for (int n = 0; n < message_style.InterMessageLines; n++)
                    {
                        formatter.AppendLine();
                    }
                }
            }

            for (int i = 0; i < MessageFormat.AppendNewlines; i++)
            {
                formatter.AppendLine();
            }

            return(formatter.ToString());
        }