File tree Expand file tree Collapse file tree
CodeJam.Main.Tests/Strings Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System . Text ;
2+
3+ using NUnit . Framework ;
4+
5+ namespace CodeJam . Strings
6+ {
7+ [ TestFixture ]
8+ public class StringBuilderExtensionsTests
9+ {
10+ [ Test ]
11+ public void IsNullOrEmptyConstructor ( )
12+ {
13+ Assert . IsTrue ( new StringBuilder ( ) . IsNullOrEmpty ( ) ) ;
14+ }
15+
16+ [ TestCase ( null , ExpectedResult = true ) ]
17+ [ TestCase ( "" , ExpectedResult = true ) ]
18+ [ TestCase ( "abc" , ExpectedResult = false ) ]
19+ public bool IsNullOrEmpty ( string source ) => new StringBuilder ( source ) . IsNullOrEmpty ( ) ;
20+
21+ [ Test ]
22+ public void NotNullNorEmptyConstructor ( )
23+ {
24+ Assert . IsFalse ( new StringBuilder ( ) . NotNullNorEmpty ( ) ) ;
25+ }
26+
27+ [ TestCase ( null , ExpectedResult = false ) ]
28+ [ TestCase ( "" , ExpectedResult = false ) ]
29+ [ TestCase ( "abc" , ExpectedResult = true ) ]
30+ public bool NotNullNorEmpty ( string source ) => new StringBuilder ( source ) . NotNullNorEmpty ( ) ;
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Text ;
3+
4+ using JetBrains . Annotations ;
5+
6+ namespace CodeJam . Strings
7+ {
8+ /// <summary>
9+ /// <see cref="StringBuilder"/> class extensions.
10+ /// </summary>
11+ [ PublicAPI ]
12+ public static class StringBuilderExtensions
13+ {
14+ /// <summary>
15+ /// Determines whether the StringBuilder is null or empty.
16+ /// </summary>
17+ /// <param name="value">The StringBuilder to test.</param>
18+ /// <returns>
19+ /// <c>true</c> if <paramref name="value"/> is null or empty; otherwise, <c>false</c>.
20+ /// </returns>
21+ [ Pure ]
22+ [ ContractAnnotation ( "value:null => true" ) ]
23+ public static bool IsNullOrEmpty ( [ CanBeNull ] this StringBuilder value ) =>
24+ value == null || value . Length == 0 ;
25+
26+ /// <summary>
27+ /// Determines whether the StringBuilder is neither null nor empty.
28+ /// </summary>
29+ /// <param name="value">The StringBuilder to test.</param>
30+ /// <returns>
31+ /// <c>true</c> if <paramref name="value"/> is not null and not empty; otherwise, <c>false</c>.
32+ /// </returns>
33+ [ Pure ]
34+ [ ContractAnnotation ( "value:null => false" ) ]
35+ public static bool NotNullNorEmpty ( [ CanBeNull ] this StringBuilder value ) =>
36+ ! IsNullOrEmpty ( value ) ;
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments