File: TextMessageWriterTests.cs

package info (click to toggle)
nunit 2.6.4+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 13,092 kB
  • ctags: 14,310
  • sloc: cs: 87,766; xml: 5,858; cpp: 512; sh: 198; makefile: 48; ansic: 8
file content (145 lines) | stat: -rw-r--r-- 4,732 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// ****************************************************************
// Copyright 2007, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org.
// ****************************************************************

using System;
using System.Threading;
using System.Globalization;

namespace NUnit.Framework.Tests
{
    [TestFixture]
    public class TextMessageWriterTests : AssertionHelper
    {
        private TextMessageWriter writer;

		[SetUp]
		public void SetUp()
        {
            writer = new TextMessageWriter();
        }

        [Test]
        public void ConnectorIsWrittenWithSurroundingSpaces()
        {
            writer.WriteConnector("and");
            Expect(writer.ToString(), EqualTo(" and "));
        }

        [Test]
        public void PredicateIsWrittenWithTrailingSpace()
        {
            writer.WritePredicate("contains");
            Expect(writer.ToString(), EqualTo("contains "));
        }

        [Test]
        public void IntegerIsWrittenAsIs()
        {
            writer.WriteValue(42);
            Expect(writer.ToString(), EqualTo("42"));
        }

        [Test]
        public void StringIsWrittenWithQuotes()
        {
            writer.WriteValue("Hello");
            Expect(writer.ToString(), EqualTo("\"Hello\""));
        }

		// This test currently fails because control character replacement is
		// done at a higher level...
		// TODO: See if we should do it at a lower level
//            [Test]
//            public void ControlCharactersInStringsAreEscaped()
//            {
//                WriteValue("Best Wishes,\r\n\tCharlie\r\n");
//                Assert.That(writer.ToString(), Is.EqualTo("\"Best Wishes,\\r\\n\\tCharlie\\r\\n\""));
//            }

        [Test]
        public void FloatIsWrittenWithTrailingF()
        {
            writer.WriteValue(0.5f);
            Expect(writer.ToString(), EqualTo("0.5f"));
        }

        [Test]
        public void FloatIsWrittenToNineDigits()
        {
            writer.WriteValue(0.33333333333333f);
            int digits = writer.ToString().Length - 3;   // 0.dddddddddf
            Expect(digits, EqualTo(9));
            Expect(writer.ToString().Length, EqualTo(12));
        }

        [Test]
        public void DoubleIsWrittenWithTrailingD()
        {
            writer.WriteValue(0.5d);
            Expect(writer.ToString(), EqualTo("0.5d"));
        }

        [Test]
        public void DoubleIsWrittenToSeventeenDigits()
        {
            writer.WriteValue(0.33333333333333333333333333333333333333333333d);
            Expect(writer.ToString().Length, EqualTo(20)); // add 3 for leading 0, decimal and trailing d
        }

        [Test]
        public void DecimalIsWrittenWithTrailingM()
        {
            writer.WriteValue(0.5m);
            Expect(writer.ToString(), EqualTo("0.5m"));
        }

        [Test]
        public void DecimalIsWrittenToTwentyNineDigits()
        {
            writer.WriteValue(12345678901234567890123456789m);
            Expect(writer.ToString(), EqualTo("12345678901234567890123456789m"));
        }

		[Test]
		public void DateTimeTest()
		{
            writer.WriteValue(new DateTime(2007, 7, 4, 9, 15, 30, 123));
            Expect(writer.ToString(), EqualTo("2007-07-04 09:15:30.123"));
		}

        [Test]
        public void DisplayStringDifferences()
        {
            string s72 = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
            string exp = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXY...";

            writer.DisplayStringDifferences(s72, "abcde", 5, false, true);
//            string message = writer.ToString();
            Expect(writer.ToString(), EqualTo(
                TextMessageWriter.Pfx_Expected + Q(exp) + Environment.NewLine +
                TextMessageWriter.Pfx_Actual + Q("abcde") + Environment.NewLine +
                "  ----------------^" + Environment.NewLine));
        }

        [Test]
        public void DisplayStringDifferences_NoClipping()
        {
            string s72 = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";

            writer.DisplayStringDifferences(s72, "abcde", 5, false, false);
//            string message = writer.ToString();
            Expect(writer.ToString(), EqualTo(
                TextMessageWriter.Pfx_Expected + Q(s72) + Environment.NewLine +
                TextMessageWriter.Pfx_Actual + Q("abcde") + Environment.NewLine +
                "  ----------------^" + Environment.NewLine));
        }

        private string Q(string s)
        {
            return "\"" + s + "\"";
        }
    }
}