switch to global usings

This commit is contained in:
Ben Harris 2024-03-26 16:10:54 -04:00
parent a7b45f1e36
commit 325b3bb30d
21 changed files with 1739 additions and 1814 deletions

View File

@ -29,7 +29,7 @@ internal class Client(string host, int port, string nick)
while (true) while (true)
{ {
while (_encoder.PendingBytes.Any()) while (_encoder.PendingBytes.Length != 0)
{ {
foreach (var line in _encoder.Pop(_socket.Send(_encoder.PendingBytes))) foreach (var line in _encoder.Pop(_socket.Send(_encoder.PendingBytes)))
Console.WriteLine($"> {line.Format()}"); Console.WriteLine($"> {line.Format()}");

View File

@ -17,6 +17,16 @@
<ProjectReference Include="..\IRCTokens\IRCTokens.csproj" /> <ProjectReference Include="..\IRCTokens\IRCTokens.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Using Include="IRCTokens" />
<Using Include="IRCStates" />
<Using Include="System" />
<Using Include="System.Collections.Generic" />
<Using Include="System.Linq" />
<Using Include="System.Text" />
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="Tokenization\Data\msg-join.yaml"> <None Update="Tokenization\Data\msg-join.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -1,12 +1,8 @@
using System.Collections.Generic; namespace IRCSharp.Tests.State;
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State [TestClass]
public class Cap
{ {
[TestClass]
public class Cap
{
private Server _server; private Server _server;
[TestInitialize] [TestInitialize]
@ -127,5 +123,4 @@ namespace IRCSharp.Tests.State
CollectionAssert.AreEqual(new Dictionary<string, string>(), _server.AvailableCaps); CollectionAssert.AreEqual(new Dictionary<string, string>(), _server.AvailableCaps);
CollectionAssert.AreEqual(new List<string>(), _server.AgreedCaps); CollectionAssert.AreEqual(new List<string>(), _server.AgreedCaps);
} }
}
} }

View File

@ -1,11 +1,8 @@
using IRCStates; namespace IRCSharp.Tests.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State [TestClass]
public class Casemap
{ {
[TestClass]
public class Casemap
{
[TestMethod] [TestMethod]
public void Rfc1459() public void Rfc1459()
{ {
@ -54,5 +51,4 @@ namespace IRCSharp.Tests.State
Assert.AreEqual("NewNickname", server.NickName); Assert.AreEqual("NewNickname", server.NickName);
Assert.AreEqual("newnickname", server.NickNameLower); Assert.AreEqual("newnickname", server.NickNameLower);
} }
}
} }

View File

@ -1,14 +1,8 @@
using System; namespace IRCSharp.Tests.State;
using System.Collections.Generic;
using System.Linq;
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State [TestClass]
public class Channel
{ {
[TestClass]
public class Channel
{
private Server _server; private Server _server;
[TestInitialize] [TestInitialize]
@ -103,16 +97,16 @@ namespace IRCSharp.Tests.State
public void QuitSelf() public void QuitSelf()
{ {
_server.Parse(new("QUIT :i'm outta here")); _server.Parse(new("QUIT :i'm outta here"));
Assert.IsFalse(_server.Users.Any()); Assert.IsFalse(_server.Users.Count != 0);
Assert.IsFalse(_server.Channels.Any()); Assert.IsFalse(_server.Channels.Count != 0);
} }
[TestMethod] [TestMethod]
public void QuitSelfWithSource() public void QuitSelfWithSource()
{ {
_server.Parse(new(":nickname QUIT :i'm outta here")); _server.Parse(new(":nickname QUIT :i'm outta here"));
Assert.IsFalse(_server.Users.Any()); Assert.IsFalse(_server.Users.Count != 0);
Assert.IsFalse(_server.Channels.Any()); Assert.IsFalse(_server.Channels.Count != 0);
} }
[TestMethod] [TestMethod]
@ -197,5 +191,4 @@ namespace IRCSharp.Tests.State
CollectionAssert.AreEqual(new Dictionary<string, ChannelUser> {{user.NickNameLower, chanUser}}, CollectionAssert.AreEqual(new Dictionary<string, ChannelUser> {{user.NickNameLower, chanUser}},
channel.Users); channel.Users);
} }
}
} }

View File

@ -1,12 +1,8 @@
using System.Collections.Generic; namespace IRCSharp.Tests.State;
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State [TestClass]
public class Emit
{ {
[TestClass]
public class Emit
{
private Server _server; private Server _server;
[TestInitialize] [TestInitialize]
@ -113,5 +109,4 @@ namespace IRCSharp.Tests.State
"-i" "-i"
}, emit.Tokens); }, emit.Tokens);
} }
}
} }

View File

@ -1,14 +1,9 @@
using System.Collections.Generic; // ReSharper disable InconsistentNaming
using IRCStates; namespace IRCSharp.Tests.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
// ReSharper disable InconsistentNaming [TestClass]
public class ISupport
namespace IRCSharp.Tests.State
{ {
[TestClass]
public class ISupport
{
private Server _server; private Server _server;
[TestInitialize] [TestInitialize]
@ -206,5 +201,4 @@ namespace IRCSharp.Tests.State
_server.Parse(new("005 * WATCH *")); _server.Parse(new("005 * WATCH *"));
Assert.AreEqual(-1, _server.ISupport.Watch); Assert.AreEqual(-1, _server.ISupport.Watch);
} }
}
} }

View File

@ -1,12 +1,8 @@
using System.Collections.Generic; namespace IRCSharp.Tests.State;
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State [TestClass]
public class Mode
{ {
[TestClass]
public class Mode
{
private Server _server; private Server _server;
[TestInitialize] [TestInitialize]
@ -175,5 +171,4 @@ namespace IRCSharp.Tests.State
_server.Parse(new("221 * iw")); _server.Parse(new("221 * iw"));
CollectionAssert.AreEqual(new List<string> {"i", "w"}, _server.Modes); CollectionAssert.AreEqual(new List<string> {"i", "w"}, _server.Modes);
} }
}
} }

View File

@ -1,12 +1,8 @@
using System.Collections.Generic; namespace IRCSharp.Tests.State;
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State [TestClass]
public class Motd
{ {
[TestClass]
public class Motd
{
[TestMethod] [TestMethod]
public void MessageOfTheDay() public void MessageOfTheDay()
{ {
@ -19,5 +15,4 @@ namespace IRCSharp.Tests.State
CollectionAssert.AreEqual(new List<string> {"start of motd", "first line of motd", "second line of motd"}, CollectionAssert.AreEqual(new List<string> {"start of motd", "first line of motd", "second line of motd"},
server.Motd); server.Motd);
} }
}
} }

View File

@ -1,11 +1,8 @@
using IRCStates; namespace IRCSharp.Tests.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State [TestClass]
public class Sasl
{ {
[TestClass]
public class Sasl
{
private Server _server; private Server _server;
[TestInitialize] [TestInitialize]
@ -34,5 +31,4 @@ namespace IRCSharp.Tests.State
Assert.AreEqual("host1", _server.HostName); Assert.AreEqual("host1", _server.HostName);
Assert.IsTrue(string.IsNullOrEmpty(_server.Account)); Assert.IsTrue(string.IsNullOrEmpty(_server.Account));
} }
}
} }

View File

@ -1,11 +1,8 @@
using IRCStates; namespace IRCSharp.Tests.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State [TestClass]
public class User
{ {
[TestClass]
public class User
{
private Server _server; private Server _server;
[TestInitialize] [TestInitialize]
@ -294,5 +291,4 @@ namespace IRCSharp.Tests.State
Assert.AreEqual("new now know how", _server.RealName); Assert.AreEqual("new now know how", _server.RealName);
Assert.AreEqual("tyrannosaurus hex", user.RealName); Assert.AreEqual("tyrannosaurus hex", user.RealName);
} }
}
} }

View File

@ -1,11 +1,8 @@
using IRCStates; namespace IRCSharp.Tests.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State [TestClass]
public class Who
{ {
[TestClass]
public class Who
{
private Server _server; private Server _server;
[TestInitialize] [TestInitialize]
@ -57,5 +54,4 @@ namespace IRCSharp.Tests.State
Assert.IsNull(user.Account); Assert.IsNull(user.Account);
Assert.AreEqual(user.Account, _server.Account); Assert.AreEqual(user.Account, _server.Account);
} }
}
} }

View File

@ -1,10 +1,9 @@
using System.Collections.Generic; using YamlDotNet.Serialization;
using YamlDotNet.Serialization;
namespace IRCSharp.Tests.Tokenization.Data namespace IRCSharp.Tests.Tokenization.Data;
public class JoinModel
{ {
public class JoinModel
{
public List<Test> Tests { get; set; } public List<Test> Tests { get; set; }
public class Test public class Test
@ -26,5 +25,4 @@ namespace IRCSharp.Tests.Tokenization.Data
public List<string> Params { get; set; } public List<string> Params { get; set; }
} }
}
} }

View File

@ -1,9 +1,7 @@
using System.Collections.Generic; namespace IRCSharp.Tests.Tokenization.Data;
namespace IRCSharp.Tests.Tokenization.Data public class SplitModel
{ {
public class SplitModel
{
public List<Test> Tests { get; set; } public List<Test> Tests { get; set; }
public class Test public class Test
@ -11,5 +9,4 @@ namespace IRCSharp.Tests.Tokenization.Data
public string Input { get; set; } public string Input { get; set; }
public JoinModel.Atoms Atoms { get; set; } public JoinModel.Atoms Atoms { get; set; }
} }
}
} }

View File

@ -1,12 +1,8 @@
using System; namespace IRCSharp.Tests.Tokenization;
using IRCTokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.Tokenization [TestClass]
public class Format
{ {
[TestClass]
public class Format
{
[TestMethod] [TestMethod]
public void Tags() public void Tags()
{ {
@ -15,7 +11,7 @@ namespace IRCSharp.Tests.Tokenization
Tags = new() {{"id", "\\" + " " + ";" + "\r\n"}} Tags = new() {{"id", "\\" + " " + ";" + "\r\n"}}
}.Format(); }.Format();
Assert.AreEqual("@id=\\\\\\s\\:\\r\\n PRIVMSG #channel hello", line); Assert.AreEqual(@"@id=\\\s\:\r\n PRIVMSG #channel hello", line);
} }
[TestMethod] [TestMethod]
@ -101,5 +97,4 @@ namespace IRCSharp.Tests.Tokenization
{ {
Assert.ThrowsException<ArgumentException>(() => { new Line("PRIVMSG", ":#channel", "hello").Format(); }); Assert.ThrowsException<ArgumentException>(() => { new Line("PRIVMSG", ":#channel", "hello").Format(); });
} }
}
} }

View File

@ -1,11 +1,8 @@
using IRCTokens; namespace IRCSharp.Tests.Tokenization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.Tokenization [TestClass]
public class Hostmask
{ {
[TestClass]
public class Hostmask
{
[TestMethod] [TestMethod]
public void FullHostmask() public void FullHostmask()
{ {
@ -61,5 +58,4 @@ namespace IRCSharp.Tests.Tokenization
Assert.IsNull(line.Hostmask.UserName); Assert.IsNull(line.Hostmask.UserName);
Assert.IsNull(line.Hostmask.NickName); Assert.IsNull(line.Hostmask.NickName);
} }
}
} }

View File

@ -1,17 +1,14 @@
using System.Collections.Generic; using System.Globalization;
using System.Globalization;
using System.IO; using System.IO;
using IRCSharp.Tests.Tokenization.Data; using IRCSharp.Tests.Tokenization.Data;
using IRCTokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization.NamingConventions;
namespace IRCSharp.Tests.Tokenization namespace IRCSharp.Tests.Tokenization;
[TestClass]
public class Parser
{ {
[TestClass]
public class Parser
{
private static T LoadYaml<T>(string path) private static T LoadYaml<T>(string path)
{ {
var deserializer = new DeserializerBuilder() var deserializer = new DeserializerBuilder()
@ -33,7 +30,7 @@ namespace IRCSharp.Tests.Tokenization
$"command failed on: '{test.Input}'"); $"command failed on: '{test.Input}'");
Assert.AreEqual(atoms.Source, tokens.Source, $"source failed on: '{test.Input}'"); Assert.AreEqual(atoms.Source, tokens.Source, $"source failed on: '{test.Input}'");
CollectionAssert.AreEqual(atoms.Tags, tokens.Tags, $"tags failed on: '{test.Input}'"); CollectionAssert.AreEqual(atoms.Tags, tokens.Tags, $"tags failed on: '{test.Input}'");
CollectionAssert.AreEqual(atoms.Params ?? new List<string>(), tokens.Params, CollectionAssert.AreEqual(atoms.Params ?? [], tokens.Params,
$"params failed on: '{test.Input}'"); $"params failed on: '{test.Input}'");
} }
} }
@ -52,5 +49,4 @@ namespace IRCSharp.Tests.Tokenization
Assert.IsTrue(test.Matches.Contains(line), test.Description); Assert.IsTrue(test.Matches.Contains(line), test.Description);
} }
} }
}
} }

View File

@ -1,13 +1,8 @@
using System.Collections.Generic; namespace IRCSharp.Tests.Tokenization;
using System.Text;
using IRCTokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.Tokenization [TestClass]
public class StatefulDecoder
{ {
[TestClass]
public class StatefulDecoder
{
private IRCTokens.StatefulDecoder _decoder; private IRCTokens.StatefulDecoder _decoder;
[TestInitialize] [TestInitialize]
@ -85,5 +80,4 @@ namespace IRCSharp.Tests.Tokenization
_decoder.Clear(); _decoder.Clear();
Assert.AreEqual(string.Empty, _decoder.Pending); Assert.AreEqual(string.Empty, _decoder.Pending);
} }
}
} }

View File

@ -1,12 +1,8 @@
using System.Text; namespace IRCSharp.Tests.Tokenization;
using IRCTokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.Tokenization [TestClass]
public class StatefulEncoder
{ {
[TestClass]
public class StatefulEncoder
{
private IRCTokens.StatefulEncoder _encoder; private IRCTokens.StatefulEncoder _encoder;
[TestInitialize] [TestInitialize]
@ -81,5 +77,4 @@ namespace IRCSharp.Tests.Tokenization
_encoder.Push(new("PRIVMSG #channel :hello Ç")); _encoder.Push(new("PRIVMSG #channel :hello Ç"));
CollectionAssert.AreEqual(iso8859.GetBytes("PRIVMSG #channel :hello Ç\r\n"), _encoder.PendingBytes); CollectionAssert.AreEqual(iso8859.GetBytes("PRIVMSG #channel :hello Ç\r\n"), _encoder.PendingBytes);
} }
}
} }

View File

@ -1,14 +1,8 @@
using System.Collections.Generic; namespace IRCSharp.Tests.Tokenization;
using System.Linq;
using System.Text;
using IRCTokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.Tokenization [TestClass]
public class Tokenization
{ {
[TestClass]
public class Tokenization
{
[TestMethod] [TestMethod]
public void TagsMissing() public void TagsMissing()
{ {
@ -41,7 +35,7 @@ namespace IRCSharp.Tests.Tokenization
public void TagsOverlap() public void TagsOverlap()
{ {
var line = new Line(@"@id=1\\\s\\s PRIVMSG #channel"); var line = new Line(@"@id=1\\\s\\s PRIVMSG #channel");
Assert.AreEqual("1\\ \\s", line.Tags["id"]); Assert.AreEqual(@"1\ \s", line.Tags["id"]);
} }
[TestMethod] [TestMethod]
@ -122,13 +116,12 @@ namespace IRCSharp.Tests.Tokenization
public void NulByte() public void NulByte()
{ {
var decoder = new IRCTokens.StatefulDecoder(); var decoder = new IRCTokens.StatefulDecoder();
var bytes = Encoding.UTF8.GetBytes(":nick!user@host PRIVMSG #channel :hello") var bytes = ":nick!user@host PRIVMSG #channel :hello"u8.ToArray()
.Concat(Encoding.UTF8.GetBytes("\0")) .Concat("\0"u8.ToArray())
.Concat(Encoding.UTF8.GetBytes("world")) .Concat("world"u8.ToArray())
.ToArray(); .ToArray();
var line = decoder.Push(bytes, bytes.Length).First(); var line = decoder.Push(bytes, bytes.Length).First();
CollectionAssert.AreEqual(new List<string> {"#channel", "hello"}, line.Params); CollectionAssert.AreEqual(new List<string> {"#channel", "hello"}, line.Params);
} }
}
} }

View File

@ -212,10 +212,10 @@ namespace IRCTokens
foreach (var p in withoutLast) foreach (var p in withoutLast)
{ {
if (p.Contains(' ', StringComparison.Ordinal)) if (p.Contains(' ', StringComparison.Ordinal))
throw new ArgumentException(@"non-last parameters cannot have spaces", p); throw new ArgumentException("non-last parameters cannot have spaces", p);
if (p.StartsWith(':')) if (p.StartsWith(':'))
throw new ArgumentException(@"non-last parameters cannot start with colon", p); throw new ArgumentException("non-last parameters cannot start with colon", p);
} }
outs.AddRange(withoutLast); outs.AddRange(withoutLast);