Skip to content

Commit 2060d95

Browse files
author
Meerow
authored
Adds Tests for SubText
Adds Tests for SubText
2 parents 5210025 + a5d2f53 commit 2060d95

File tree

2 files changed

+99
-34
lines changed

2 files changed

+99
-34
lines changed

src/Yaapii.Atoms/Text/SubText.cs

+17-34
Original file line numberDiff line numberDiff line change
@@ -33,80 +33,63 @@ public sealed class SubText : TextEnvelope
3333
/// <summary>
3434
/// Extracted subtext from a <see cref="string"/>.
3535
/// </summary>
36-
/// <param name="text">text to extreact from</param>
37-
/// <param name="strt">where to start</param>
38-
public SubText(String text, int strt) : this(new LiveText(text), strt)
36+
public SubText(String text, int start) : this(new LiveText(text), start)
3937
{ }
4038

4139
/// <summary>
4240
/// Extracted subtext from a <see cref="string"/>.
4341
/// </summary>
44-
/// <param name="text">text to extract from</param>
45-
/// <param name="strt">where to start</param>
46-
/// <param name="end">where to end</param>
47-
public SubText(String text, int strt, int end) : this(
42+
public SubText(String text, int start, int length) : this(
4843
new LiveText(text),
49-
strt,
50-
end
44+
start,
45+
length
5146
)
5247
{ }
5348

5449
/// <summary>
5550
/// Extracted subtext from a <see cref="IText"/>.
5651
/// </summary>
57-
/// <param name="text">text to extract from</param>
58-
/// <param name="strt">where to start</param>
59-
public SubText(IText text, int strt) : this(
52+
public SubText(IText text, int start) : this(
6053
text,
61-
new Live<Int32>(strt),
62-
new Live<Int32>(() => text.AsString().Length - strt)
54+
new Live<Int32>(start),
55+
new Live<Int32>(() => text.AsString().Length - start)
6356
)
6457
{ }
6558

6659
/// <summary>
6760
/// Extracted subtext from a <see cref="IText"/>.
6861
/// </summary>
69-
/// <param name="text">text to extract from</param>
70-
/// <param name="strt">where to start</param>
71-
/// <param name="end">where to end</param>
72-
public SubText(IText text, int strt, int end) : this(
62+
public SubText(IText text, int start, int length) : this(
7363
text,
74-
new Live<Int32>(strt),
75-
new Live<Int32>(end)
64+
new Live<Int32>(start),
65+
new Live<Int32>(length)
7666
)
7767
{ }
7868

7969
/// <summary>
8070
/// Extracted subtext from a <see cref="IText"/>.
8171
/// </summary>
82-
/// <param name="text">text to extract from</param>
83-
/// <param name="strt">where to start encapsulated in a scalar</param>
84-
/// <param name="len">where to end encapsulated in a scalar</param>
85-
/// <param name="live">should the object build its value live, every time it is used?</param>
8672
public SubText(
8773
IText text,
88-
Live<Int32> strt,
89-
Live<Int32> len,
74+
Live<Int32> start,
75+
Live<Int32> length,
9076
bool live = false
9177
) : this(
9278
text,
93-
() => strt.Value(),
94-
() => len.Value()
79+
() => start.Value(),
80+
() => length.Value()
9581
)
9682
{ }
9783

9884
/// <summary>
9985
/// Extracted subtext from a <see cref="IText"/>.
10086
/// </summary>
101-
/// <param name="text">text to extract from</param>
102-
/// <param name="strt">where to start encapsulated in a scalar</param>
103-
/// <param name="len">where to end encapsulated in a scalar</param>
104-
public SubText(IText text, Func<Int32> strt, Func<Int32> len) : base(() =>
87+
public SubText(IText text, Func<Int32> start, Func<Int32> length) : base(() =>
10588
{
10689
return
10790
text.AsString().Substring(
108-
strt(),
109-
len()
91+
start(),
92+
length()
11093
);
11194
},
11295
false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// MIT License
2+
//
3+
// Copyright(c) 2022 ICARUS Consulting GmbH
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
using System;
24+
using System.Threading.Tasks;
25+
using Xunit;
26+
using Yaapii.Atoms.Text;
27+
28+
namespace Yaapii.Atoms.Text.Tests
29+
{
30+
public sealed class SubTextText
31+
{
32+
[Fact]
33+
public void CutString()
34+
{
35+
Assert.Equal(
36+
"the_end",
37+
new SubText(
38+
"this_is:the_end",
39+
8
40+
).AsString()
41+
);
42+
}
43+
44+
[Fact]
45+
public void CutStringwithLength()
46+
{
47+
Assert.Equal(
48+
"the",
49+
new SubText(
50+
"this_is:the_end",
51+
8,
52+
3
53+
).AsString()
54+
);
55+
}
56+
57+
[Fact]
58+
public void CutIText()
59+
{
60+
Assert.Equal(
61+
"the_end",
62+
new SubText(
63+
new LiveText("this_is:the_end"),
64+
8
65+
).AsString()
66+
);
67+
}
68+
69+
[Fact]
70+
public void CutITextwithLength()
71+
{
72+
Assert.Equal(
73+
"the",
74+
new SubText(
75+
new LiveText("this_is:the_end"),
76+
8,
77+
3
78+
).AsString()
79+
);
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)