Beispiel #1
0
        /// <summary>
        /// Display the expected and actual string values on separate lines. If
        /// the mismatch parameter is >=0, an additional line is displayed line
        /// containing a caret that points to the mismatch point.
        /// </summary>
        /// <param name="expected">The expected string value</param>
        /// <param name="actual">The actual string value</param>
        /// <param name="mismatch">The point at which the strings don't match or -1</param>
        /// <param name="ignoreCase">If true, case is ignored in string comparisons</param>
        public override void DisplayStringDifferences(string expected, string actual, int mismatch, bool ignoreCase)
        {
            // Maximum string we can display without truncating
            int maxStringLength = MAX_LINE_LENGTH
                                  - PrefixLength // Allow for prefix
                                  - 2;           // 2 quotation marks

            expected = MsgUtils.ConvertWhitespace(MsgUtils.ClipString(expected, maxStringLength, mismatch));
            actual   = MsgUtils.ConvertWhitespace(MsgUtils.ClipString(actual, maxStringLength, mismatch));

            // The mismatch position may have changed due to clipping or white
            // space conversion
            mismatch = MsgUtils.FindMismatchPosition(expected, actual, 0, ignoreCase);

            TextWriter.Write(Pfx_Expected);
            WriteExpectedValue(expected);
            if (ignoreCase)
            {
                WriteModifier(Resources.IgnoringCase);
            }
            TextWriter.WriteLine();
            WriteActualLine(actual);
            //DisplayDifferences(expected, actual);
            if (mismatch >= 0)
            {
                WriteCaretLine(mismatch);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Write the constraint description to a MessageWriter
 /// </summary>
 /// <param name="writer">The writer on which the description is displayed</param>
 public override void WriteDescriptionTo(MessageWriter writer)
 {
     writer.WritePredicate("String starting with");
     writer.WriteExpectedValue(MsgUtils.ClipString(expected, writer.MaxLineLength - 40, 0));
     if (this.caseInsensitive)
     {
         writer.WriteModifier("ignoring case");
     }
 }
        public void TestClipString()
        {
            Assert.AreEqual(s52, MsgUtils.ClipString(s52, 52, 0));

            Assert.AreEqual("abcdefghijklmnopqrstuvwxyz...",
                            MsgUtils.ClipString(s52, 29, 0));
            Assert.AreEqual("...ABCDEFGHIJKLMNOPQRSTUVWXYZ",
                            MsgUtils.ClipString(s52, 29, 26));
            Assert.AreEqual("...ABCDEFGHIJKLMNOPQRSTUV...",
                            MsgUtils.ClipString(s52, 28, 26));
        }
Beispiel #4
0
        /// <summary>
        /// Write the constraint description to a MessageWriter
        /// </summary>
        /// <exception cref="ArgumentNullException">if the message writer is null.</exception>
        /// <param name="writer">The writer on which the description is displayed</param>
        public override void WriteDescriptionTo(MessageWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            writer.WritePredicate(Resources.StringStartingWith);
            writer.WriteExpectedValue(MsgUtils.ClipString(_expected, writer.MaxLineLength - 40, 0));
            if (CaseInsensitive)
            {
                writer.WriteModifier(Resources.IgnoringCase);
            }
        }
Beispiel #5
0
 public void TestClipString(string input, int max, int start, string result)
 {
     Assert.AreEqual(result, MsgUtils.ClipString(input, max, start));
 }
Beispiel #6
0
 public void TestClipString(string input, int max, int start, string result)
 {
     System.Console.WriteLine("input=  \"{0}\"", input);
     System.Console.WriteLine("result= \"{0}\"", result);
     Assert.That(MsgUtils.ClipString(input, max, start), Is.EqualTo(result));
 }