File: StringAssertTests.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 (139 lines) | stat: -rw-r--r-- 4,403 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
// ****************************************************************
// 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.
// ****************************************************************

namespace NUnit.Framework.Tests
{
	[TestFixture]
	public class StringAssertTests : MessageChecker
	{
		[Test]
		public void Contains()
		{
			StringAssert.Contains( "abc", "abc" );
			StringAssert.Contains( "abc", "***abc" );
			StringAssert.Contains( "abc", "**abc**" );
		}

        [Test, ExpectedException(typeof(AssertionException))]
		public void ContainsFails()
		{
            expectedMessage =
                TextMessageWriter.Pfx_Expected + "String containing \"abc\"" + System.Environment.NewLine +
                TextMessageWriter.Pfx_Actual + "\"abxcdxbc\"" + System.Environment.NewLine;
            StringAssert.Contains("abc", "abxcdxbc");
		}

        [Test]
        public void DoesNotContain()
        {
            StringAssert.DoesNotContain("x", "abc");
        }

        [Test, ExpectedException(typeof(AssertionException))]
        public void DoesNotContainFails()
        {
            StringAssert.DoesNotContain("abc", "**abc**");
        }

        [Test]
		public void StartsWith()
		{
			StringAssert.StartsWith( "abc", "abcdef" );
			StringAssert.StartsWith( "abc", "abc" );
		}

        [Test, ExpectedException(typeof(AssertionException))]
		public void StartsWithFails()
		{
            expectedMessage =
                TextMessageWriter.Pfx_Expected + "String starting with \"xyz\"" + System.Environment.NewLine +
                TextMessageWriter.Pfx_Actual + "\"abcxyz\"" + System.Environment.NewLine;
            StringAssert.StartsWith("xyz", "abcxyz");
		}

        [Test]
        public void DoesNotStartWith()
        {
            StringAssert.DoesNotStartWith("x", "abc");
        }

        [Test, ExpectedException(typeof(AssertionException))]
        public void DoesNotStartWithFails()
        {
            StringAssert.DoesNotStartWith("abc", "abc**");
        }

        [Test]
		public void EndsWith()
		{
			StringAssert.EndsWith( "abc", "abc" );
			StringAssert.EndsWith( "abc", "123abc" );
		}

        [Test, ExpectedException(typeof(AssertionException))]
		public void EndsWithFails()
		{
            expectedMessage =
                TextMessageWriter.Pfx_Expected + "String ending with \"xyz\"" + System.Environment.NewLine +
                TextMessageWriter.Pfx_Actual + "\"abcdef\"" + System.Environment.NewLine;
            StringAssert.EndsWith( "xyz", "abcdef" );
		}

        [Test]
        public void DoesNotEndWith()
        {
            StringAssert.DoesNotEndWith("x", "abc");
        }

        [Test, ExpectedException(typeof(AssertionException))]
        public void DoesNotEndWithFails()
        {
            StringAssert.DoesNotEndWith("abc", "***abc");
        }

        [Test]
		public void CaseInsensitiveCompare()
		{
			StringAssert.AreEqualIgnoringCase( "name", "NAME" );
		}

        [Test, ExpectedException(typeof(AssertionException))]
		public void CaseInsensitiveCompareFails()
		{
            expectedMessage =
                "  Expected string length 4 but was 5. Strings differ at index 4." + System.Environment.NewLine
                + TextMessageWriter.Pfx_Expected + "\"Name\", ignoring case" + System.Environment.NewLine
                + TextMessageWriter.Pfx_Actual   + "\"NAMES\"" + System.Environment.NewLine
                + "  ---------------^" + System.Environment.NewLine;
            StringAssert.AreEqualIgnoringCase("Name", "NAMES");
		}

		[Test]		
		public void IsMatch()
		{
			StringAssert.IsMatch( "a?bc", "12a3bc45" );
		}

        [Test, ExpectedException(typeof(AssertionException))]
		public void IsMatchFails()
		{
            expectedMessage =
                TextMessageWriter.Pfx_Expected + "String matching \"a?b*c\"" + System.Environment.NewLine +
                TextMessageWriter.Pfx_Actual + "\"12ab456\"" + System.Environment.NewLine;
            StringAssert.IsMatch("a?b*c", "12ab456");
		}

		[Test]
		public void DifferentEncodingsOfSameStringAreNotEqual()
		{
			string input = "Hello World";
			byte[] data = System.Text.Encoding.Unicode.GetBytes( input );
			string garbage = System.Text.Encoding.UTF8.GetString( data );

			Assert.AreNotEqual( input, garbage );
		}
	}
}