/
StringSpecs.cs
96 lines (85 loc) · 2.75 KB
/
StringSpecs.cs
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
using System;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ruebee;
namespace Ruebee.Specs
{
[TestFixture]
public class StringSpecs
{
[Test]
public void can_detect_ascii_only()
{
"Hello there World!!".IsAsciiOnly().ShouldBeTrue();
"This is not Ascii →".IsAsciiOnly().ShouldBeFalse();
}
[Test]
public void can_get_bytesize()
{
"Hello".ByteSize().ShouldEqual(5);
"a→".ByteSize().ShouldEqual(4);
}
[Test]
public void can_capitalize()
{
"hello".Capitalize().ShouldEqual("Hello");
}
[Test]
public void can_center()
{
"hello".Center(4).ShouldEqual("hello");
"hello".Center(5).ShouldEqual("hello");
"hello".Center(7).ShouldEqual(" hello ");
"hello".Center(8).ShouldEqual(" hello ");
"hello".Center(9, '-').ShouldEqual("--hello--");
}
[Test]
public void can_chomp()
{
"hello".Chomp().ShouldEqual("hello");
"hello\r ".Chomp().ShouldEqual("hello");
"hello \r\n".Chomp().ShouldEqual("hello");
}
[Test]
public void can_chop()
{
"hello".Chop().ShouldEqual("hell");
"hello".Chop().Chop().ShouldEqual("hel");
}
[Test]
public void can_get_lines()
{
var lines = ("Hello there." + Environment.NewLine + "How are you?").Lines();
lines.Each(Console.WriteLine);
lines.First().ShouldEqual("Hello there.");
}
[Test]
public void can_perform_action_on_each_line()
{
var builder = new StringBuilder();
("Hello there." + Environment.NewLine + "How are you?")
.EachLine(l => builder.Append(l));
builder.ToString().ShouldEndWith("Hello there.How are you?");
}
[Test]
public void can_ljust()
{
"hello".LJust(4).ShouldEqual("hello");
"hello".LJust(20).ShouldEqual("hello ");
"hello".LJust(20, "1234").ShouldEqual("hello123412341234123");
}
[Test]
public void can_rjust()
{
"hello".RJust(4).ShouldEqual("hello");
"hello".RJust(20).ShouldEqual(" hello");
"hello".RJust(20, "1234").ShouldEqual("123412341234123hello");
}
[Test]
public void can_iterate_over_chars_multiple_times()
{
"abc".Loop(5).ShouldEqual("abcab");
}
}
}