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,9 +1,5 @@
using System.Collections.Generic; namespace IRCSharp.Tests.State;
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State
{
[TestClass] [TestClass]
public class Cap public class Cap
{ {
@ -128,4 +124,3 @@ namespace IRCSharp.Tests.State
CollectionAssert.AreEqual(new List<string>(), _server.AgreedCaps); CollectionAssert.AreEqual(new List<string>(), _server.AgreedCaps);
} }
} }
}

View File

@ -1,8 +1,5 @@
using IRCStates; namespace IRCSharp.Tests.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State
{
[TestClass] [TestClass]
public class Casemap public class Casemap
{ {
@ -55,4 +52,3 @@ namespace IRCSharp.Tests.State
Assert.AreEqual("newnickname", server.NickNameLower); Assert.AreEqual("newnickname", server.NickNameLower);
} }
} }
}

View File

@ -1,11 +1,5 @@
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] [TestClass]
public class Channel public class Channel
{ {
@ -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]
@ -198,4 +192,3 @@ namespace IRCSharp.Tests.State
channel.Users); channel.Users);
} }
} }
}

View File

@ -1,9 +1,5 @@
using System.Collections.Generic; namespace IRCSharp.Tests.State;
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State
{
[TestClass] [TestClass]
public class Emit public class Emit
{ {
@ -114,4 +110,3 @@ namespace IRCSharp.Tests.State
}, emit.Tokens); }, emit.Tokens);
} }
} }
}

View File

@ -1,11 +1,6 @@
using System.Collections.Generic; // ReSharper disable InconsistentNaming
using IRCStates; namespace IRCSharp.Tests.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
// ReSharper disable InconsistentNaming
namespace IRCSharp.Tests.State
{
[TestClass] [TestClass]
public class ISupport public class ISupport
{ {
@ -207,4 +202,3 @@ namespace IRCSharp.Tests.State
Assert.AreEqual(-1, _server.ISupport.Watch); Assert.AreEqual(-1, _server.ISupport.Watch);
} }
} }
}

View File

@ -1,9 +1,5 @@
using System.Collections.Generic; namespace IRCSharp.Tests.State;
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State
{
[TestClass] [TestClass]
public class Mode public class Mode
{ {
@ -176,4 +172,3 @@ namespace IRCSharp.Tests.State
CollectionAssert.AreEqual(new List<string> {"i", "w"}, _server.Modes); CollectionAssert.AreEqual(new List<string> {"i", "w"}, _server.Modes);
} }
} }
}

View File

@ -1,9 +1,5 @@
using System.Collections.Generic; namespace IRCSharp.Tests.State;
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State
{
[TestClass] [TestClass]
public class Motd public class Motd
{ {
@ -20,4 +16,3 @@ namespace IRCSharp.Tests.State
server.Motd); server.Motd);
} }
} }
}

View File

@ -1,8 +1,5 @@
using IRCStates; namespace IRCSharp.Tests.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State
{
[TestClass] [TestClass]
public class Sasl public class Sasl
{ {
@ -35,4 +32,3 @@ namespace IRCSharp.Tests.State
Assert.IsTrue(string.IsNullOrEmpty(_server.Account)); Assert.IsTrue(string.IsNullOrEmpty(_server.Account));
} }
} }
}

View File

@ -1,8 +1,5 @@
using IRCStates; namespace IRCSharp.Tests.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State
{
[TestClass] [TestClass]
public class User public class User
{ {
@ -295,4 +292,3 @@ namespace IRCSharp.Tests.State
Assert.AreEqual("tyrannosaurus hex", user.RealName); Assert.AreEqual("tyrannosaurus hex", user.RealName);
} }
} }
}

View File

@ -1,8 +1,5 @@
using IRCStates; namespace IRCSharp.Tests.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State
{
[TestClass] [TestClass]
public class Who public class Who
{ {
@ -58,4 +55,3 @@ namespace IRCSharp.Tests.State
Assert.AreEqual(user.Account, _server.Account); Assert.AreEqual(user.Account, _server.Account);
} }
} }
}

View File

@ -1,8 +1,7 @@
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; }
@ -27,4 +26,3 @@ namespace IRCSharp.Tests.Tokenization.Data
public List<string> Params { get; set; } public List<string> Params { get; set; }
} }
} }
}

View File

@ -1,7 +1,5 @@
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; }
@ -12,4 +10,3 @@ namespace IRCSharp.Tests.Tokenization.Data
public JoinModel.Atoms Atoms { get; set; } public JoinModel.Atoms Atoms { get; set; }
} }
} }
}

View File

@ -1,9 +1,5 @@
using System; namespace IRCSharp.Tests.Tokenization;
using IRCTokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.Tokenization
{
[TestClass] [TestClass]
public class Format public class Format
{ {
@ -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]
@ -102,4 +98,3 @@ 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,8 +1,5 @@
using IRCTokens; namespace IRCSharp.Tests.Tokenization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.Tokenization
{
[TestClass] [TestClass]
public class Hostmask public class Hostmask
{ {
@ -62,4 +59,3 @@ namespace IRCSharp.Tests.Tokenization
Assert.IsNull(line.Hostmask.NickName); Assert.IsNull(line.Hostmask.NickName);
} }
} }
}

View File

@ -1,14 +1,11 @@
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] [TestClass]
public class Parser public class Parser
{ {
@ -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}'");
} }
} }
@ -53,4 +50,3 @@ namespace IRCSharp.Tests.Tokenization
} }
} }
} }
}

View File

@ -1,10 +1,5 @@
using System.Collections.Generic; namespace IRCSharp.Tests.Tokenization;
using System.Text;
using IRCTokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.Tokenization
{
[TestClass] [TestClass]
public class StatefulDecoder public class StatefulDecoder
{ {
@ -86,4 +81,3 @@ namespace IRCSharp.Tests.Tokenization
Assert.AreEqual(string.Empty, _decoder.Pending); Assert.AreEqual(string.Empty, _decoder.Pending);
} }
} }
}

View File

@ -1,9 +1,5 @@
using System.Text; namespace IRCSharp.Tests.Tokenization;
using IRCTokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.Tokenization
{
[TestClass] [TestClass]
public class StatefulEncoder public class StatefulEncoder
{ {
@ -82,4 +78,3 @@ namespace IRCSharp.Tests.Tokenization
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,11 +1,5 @@
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] [TestClass]
public class Tokenization public class Tokenization
{ {
@ -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);