~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to src/NUnitFramework/tests/TextMessageWriterTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ****************************************************************
2
 
// Copyright 2007, Charlie Poole
3
 
// This is free software licensed under the NUnit license. You may
4
 
// obtain a copy of the license at http://nunit.org.
5
 
// ****************************************************************
6
 
 
7
 
using System;
8
 
using System.Threading;
9
 
using System.Globalization;
10
 
 
11
 
namespace NUnit.Framework.Tests
12
 
{
13
 
    [TestFixture]
14
 
    public class TextMessageWriterTests : AssertionHelper
15
 
    {
16
 
        private TextMessageWriter writer;
17
 
 
18
 
                [SetUp]
19
 
                public void SetUp()
20
 
        {
21
 
            writer = new TextMessageWriter();
22
 
        }
23
 
 
24
 
        [Test]
25
 
        public void ConnectorIsWrittenWithSurroundingSpaces()
26
 
        {
27
 
            writer.WriteConnector("and");
28
 
            Expect(writer.ToString(), EqualTo(" and "));
29
 
        }
30
 
 
31
 
        [Test]
32
 
        public void PredicateIsWrittenWithTrailingSpace()
33
 
        {
34
 
            writer.WritePredicate("contains");
35
 
            Expect(writer.ToString(), EqualTo("contains "));
36
 
        }
37
 
 
38
 
        [Test]
39
 
        public void IntegerIsWrittenAsIs()
40
 
        {
41
 
            writer.WriteValue(42);
42
 
            Expect(writer.ToString(), EqualTo("42"));
43
 
        }
44
 
 
45
 
        [Test]
46
 
        public void StringIsWrittenWithQuotes()
47
 
        {
48
 
            writer.WriteValue("Hello");
49
 
            Expect(writer.ToString(), EqualTo("\"Hello\""));
50
 
        }
51
 
 
52
 
                // This test currently fails because control character replacement is
53
 
                // done at a higher level...
54
 
                // TODO: See if we should do it at a lower level
55
 
//            [Test]
56
 
//            public void ControlCharactersInStringsAreEscaped()
57
 
//            {
58
 
//                WriteValue("Best Wishes,\r\n\tCharlie\r\n");
59
 
//                Assert.That(writer.ToString(), Is.EqualTo("\"Best Wishes,\\r\\n\\tCharlie\\r\\n\""));
60
 
//            }
61
 
 
62
 
        [Test]
63
 
        public void FloatIsWrittenWithTrailingF()
64
 
        {
65
 
            writer.WriteValue(0.5f);
66
 
            Expect(writer.ToString(), EqualTo("0.5f"));
67
 
        }
68
 
 
69
 
        [Test]
70
 
        public void FloatIsWrittenToNineDigits()
71
 
        {
72
 
            writer.WriteValue(0.33333333333333f);
73
 
            int digits = writer.ToString().Length - 3;   // 0.dddddddddf
74
 
            Expect(digits, EqualTo(9));
75
 
            Expect(writer.ToString().Length, EqualTo(12));
76
 
        }
77
 
 
78
 
        [Test]
79
 
        public void DoubleIsWrittenWithTrailingD()
80
 
        {
81
 
            writer.WriteValue(0.5d);
82
 
            Expect(writer.ToString(), EqualTo("0.5d"));
83
 
        }
84
 
 
85
 
        [Test]
86
 
        public void DoubleIsWrittenToSeventeenDigits()
87
 
        {
88
 
            writer.WriteValue(0.33333333333333333333333333333333333333333333d);
89
 
            Expect(writer.ToString().Length, EqualTo(20)); // add 3 for leading 0, decimal and trailing d
90
 
        }
91
 
 
92
 
        [Test]
93
 
        public void DecimalIsWrittenWithTrailingM()
94
 
        {
95
 
            writer.WriteValue(0.5m);
96
 
            Expect(writer.ToString(), EqualTo("0.5m"));
97
 
        }
98
 
 
99
 
        [Test]
100
 
        public void DecimalIsWrittenToTwentyNineDigits()
101
 
        {
102
 
            writer.WriteValue(12345678901234567890123456789m);
103
 
            Expect(writer.ToString(), EqualTo("12345678901234567890123456789m"));
104
 
        }
105
 
 
106
 
                [Test]
107
 
                public void DateTimeTest()
108
 
                {
109
 
            writer.WriteValue(new DateTime(2007, 7, 4, 9, 15, 30, 123));
110
 
            Expect(writer.ToString(), EqualTo("2007-07-04 09:15:30.123"));
111
 
                }
112
 
 
113
 
        [Test]
114
 
        public void DisplayStringDifferences()
115
 
        {
116
 
            string s72 = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
117
 
            string exp = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXY...";
118
 
 
119
 
            writer.DisplayStringDifferences(s72, "abcde", 5, false, true);
120
 
//            string message = writer.ToString();
121
 
            Expect(writer.ToString(), EqualTo(
122
 
                TextMessageWriter.Pfx_Expected + Q(exp) + Environment.NewLine +
123
 
                TextMessageWriter.Pfx_Actual + Q("abcde") + Environment.NewLine +
124
 
                "  ----------------^" + Environment.NewLine));
125
 
        }
126
 
 
127
 
        [Test]
128
 
        public void DisplayStringDifferences_NoClipping()
129
 
        {
130
 
            string s72 = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
131
 
 
132
 
            writer.DisplayStringDifferences(s72, "abcde", 5, false, false);
133
 
//            string message = writer.ToString();
134
 
            Expect(writer.ToString(), EqualTo(
135
 
                TextMessageWriter.Pfx_Expected + Q(s72) + Environment.NewLine +
136
 
                TextMessageWriter.Pfx_Actual + Q("abcde") + Environment.NewLine +
137
 
                "  ----------------^" + Environment.NewLine));
138
 
        }
139
 
 
140
 
        private string Q(string s)
141
 
        {
142
 
            return "\"" + s + "\"";
143
 
        }
144
 
    }
145
 
}
 
1
// ****************************************************************
 
2
// Copyright 2007, Charlie Poole
 
3
// This is free software licensed under the NUnit license. You may
 
4
// obtain a copy of the license at http://nunit.org.
 
5
// ****************************************************************
 
6
 
 
7
using System;
 
8
using System.Threading;
 
9
using System.Globalization;
 
10
 
 
11
namespace NUnit.Framework.Tests
 
12
{
 
13
    [TestFixture]
 
14
    public class TextMessageWriterTests : AssertionHelper
 
15
    {
 
16
        private TextMessageWriter writer;
 
17
 
 
18
                [SetUp]
 
19
                public void SetUp()
 
20
        {
 
21
            writer = new TextMessageWriter();
 
22
        }
 
23
 
 
24
        [Test]
 
25
        public void ConnectorIsWrittenWithSurroundingSpaces()
 
26
        {
 
27
            writer.WriteConnector("and");
 
28
            Expect(writer.ToString(), EqualTo(" and "));
 
29
        }
 
30
 
 
31
        [Test]
 
32
        public void PredicateIsWrittenWithTrailingSpace()
 
33
        {
 
34
            writer.WritePredicate("contains");
 
35
            Expect(writer.ToString(), EqualTo("contains "));
 
36
        }
 
37
 
 
38
        [Test]
 
39
        public void IntegerIsWrittenAsIs()
 
40
        {
 
41
            writer.WriteValue(42);
 
42
            Expect(writer.ToString(), EqualTo("42"));
 
43
        }
 
44
 
 
45
        [Test]
 
46
        public void StringIsWrittenWithQuotes()
 
47
        {
 
48
            writer.WriteValue("Hello");
 
49
            Expect(writer.ToString(), EqualTo("\"Hello\""));
 
50
        }
 
51
 
 
52
                // This test currently fails because control character replacement is
 
53
                // done at a higher level...
 
54
                // TODO: See if we should do it at a lower level
 
55
//            [Test]
 
56
//            public void ControlCharactersInStringsAreEscaped()
 
57
//            {
 
58
//                WriteValue("Best Wishes,\r\n\tCharlie\r\n");
 
59
//                Assert.That(writer.ToString(), Is.EqualTo("\"Best Wishes,\\r\\n\\tCharlie\\r\\n\""));
 
60
//            }
 
61
 
 
62
        [Test]
 
63
        public void FloatIsWrittenWithTrailingF()
 
64
        {
 
65
            writer.WriteValue(0.5f);
 
66
            Expect(writer.ToString(), EqualTo("0.5f"));
 
67
        }
 
68
 
 
69
        [Test]
 
70
        public void FloatIsWrittenToNineDigits()
 
71
        {
 
72
            writer.WriteValue(0.33333333333333f);
 
73
            int digits = writer.ToString().Length - 3;   // 0.dddddddddf
 
74
            Expect(digits, EqualTo(9));
 
75
            Expect(writer.ToString().Length, EqualTo(12));
 
76
        }
 
77
 
 
78
        [Test]
 
79
        public void DoubleIsWrittenWithTrailingD()
 
80
        {
 
81
            writer.WriteValue(0.5d);
 
82
            Expect(writer.ToString(), EqualTo("0.5d"));
 
83
        }
 
84
 
 
85
        [Test]
 
86
        public void DoubleIsWrittenToSeventeenDigits()
 
87
        {
 
88
            writer.WriteValue(0.33333333333333333333333333333333333333333333d);
 
89
            Expect(writer.ToString().Length, EqualTo(20)); // add 3 for leading 0, decimal and trailing d
 
90
        }
 
91
 
 
92
        [Test]
 
93
        public void DecimalIsWrittenWithTrailingM()
 
94
        {
 
95
            writer.WriteValue(0.5m);
 
96
            Expect(writer.ToString(), EqualTo("0.5m"));
 
97
        }
 
98
 
 
99
        [Test]
 
100
        public void DecimalIsWrittenToTwentyNineDigits()
 
101
        {
 
102
            writer.WriteValue(12345678901234567890123456789m);
 
103
            Expect(writer.ToString(), EqualTo("12345678901234567890123456789m"));
 
104
        }
 
105
 
 
106
                [Test]
 
107
                public void DateTimeTest()
 
108
                {
 
109
            writer.WriteValue(new DateTime(2007, 7, 4, 9, 15, 30, 123));
 
110
            Expect(writer.ToString(), EqualTo("2007-07-04 09:15:30.123"));
 
111
                }
 
112
 
 
113
        [Test]
 
114
        public void DisplayStringDifferences()
 
115
        {
 
116
            string s72 = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
 
117
            string exp = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXY...";
 
118
 
 
119
            writer.DisplayStringDifferences(s72, "abcde", 5, false, true);
 
120
//            string message = writer.ToString();
 
121
            Expect(writer.ToString(), EqualTo(
 
122
                TextMessageWriter.Pfx_Expected + Q(exp) + Environment.NewLine +
 
123
                TextMessageWriter.Pfx_Actual + Q("abcde") + Environment.NewLine +
 
124
                "  ----------------^" + Environment.NewLine));
 
125
        }
 
126
 
 
127
        [Test]
 
128
        public void DisplayStringDifferences_NoClipping()
 
129
        {
 
130
            string s72 = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
 
131
 
 
132
            writer.DisplayStringDifferences(s72, "abcde", 5, false, false);
 
133
//            string message = writer.ToString();
 
134
            Expect(writer.ToString(), EqualTo(
 
135
                TextMessageWriter.Pfx_Expected + Q(s72) + Environment.NewLine +
 
136
                TextMessageWriter.Pfx_Actual + Q("abcde") + Environment.NewLine +
 
137
                "  ----------------^" + Environment.NewLine));
 
138
        }
 
139
 
 
140
        private string Q(string s)
 
141
        {
 
142
            return "\"" + s + "\"";
 
143
        }
 
144
    }
 
145
}