-
Notifications
You must be signed in to change notification settings - Fork 0
/
UsernameTests.cs
112 lines (92 loc) · 2.86 KB
/
UsernameTests.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System.Buffers;
using Xunit;
using NippyWard.IRC.Parser.Tokens;
using NippyWard.Text;
namespace NippyWard.IRC.Parser.Tests
{
public class UsernameTests
{
[Fact]
public void SimpleUsernameTest()
=> AssertUsername("coolguy");
[Fact]
public void IdentUsernameTest()
=> AssertUsername("~coolguy");
[Fact]
public void ValidCharactersUsernameTest()
{
byte[] username = new byte[256 - 5];
int index = 0;
for(int i = 0; i < 256; i++)
{
//full utf-8 without NUL, CR, LF, SPACE or @
if(i is 0
or 13
or 10
or 32
or 64)
{
continue;
}
username[index++] = (byte)i;
}
Utf8StringSequenceSegment segment
= new Utf8StringSequenceSegment(username);
ReadOnlySequence<byte> utf8 = new ReadOnlySequence<byte>
(
segment,
0,
segment,
segment.Memory.Length
);
SequenceReader<byte> reader = new SequenceReader<byte>(utf8);
using Token token = IRCParser.ParseUsername(ref reader);
Assert.True(utf8.SequenceEquals(token.Sequence));
}
[Fact]
public void UserhostTest()
{
string userHost = "coolguy!~coolguy@localhost";
ReadOnlySequence<byte> sequence
= AssertHelpers.CreateReadOnlySequence(userHost);
SequenceReader<byte> reader = new SequenceReader<byte>(sequence);
using Token token = IRCParser.ParseUserHost(ref reader);
AssertHelpers.AssertFirstOfTokenTypeIsEqualTo
(
token,
TokenType.Nickname,
"coolguy"
);
AssertHelpers.AssertFirstOfTokenTypeIsEqualTo
(
token,
TokenType.Username,
"~coolguy"
);
AssertHelpers.AssertFirstOfTokenTypeIsEqualTo
(
token,
TokenType.Host,
"localhost"
);
}
#region helper methods
private static void AssertUsername
(
string username
)
{
ReadOnlySequence<byte> sequence
= AssertHelpers.CreateReadOnlySequence(username);
SequenceReader<byte> reader = new SequenceReader<byte>(sequence);
using Token token = IRCParser.ParseUsername(ref reader);
AssertHelpers.AssertFirstOfTokenTypeIsEqualTo
(
token,
TokenType.Username,
username
);
}
#endregion
}
}