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 (_encoder.PendingBytes.Any())
while (_encoder.PendingBytes.Length != 0)
{
foreach (var line in _encoder.Pop(_socket.Send(_encoder.PendingBytes)))
Console.WriteLine($"> {line.Format()}");

View File

@ -17,6 +17,16 @@
<ProjectReference Include="..\IRCTokens\IRCTokens.csproj" />
</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>
<None Update="Tokenization\Data\msg-join.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,8 @@
using System.Collections.Generic;
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State;
namespace IRCSharp.Tests.State
[TestClass]
public class Motd
{
[TestClass]
public class Motd
{
[TestMethod]
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"},
server.Motd);
}
}
}

View File

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

View File

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

View File

@ -1,11 +1,8 @@
using IRCStates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.State;
namespace IRCSharp.Tests.State
[TestClass]
public class Who
{
[TestClass]
public class Who
{
private Server _server;
[TestInitialize]
@ -57,5 +54,4 @@ namespace IRCSharp.Tests.State
Assert.IsNull(user.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 class Test
@ -26,5 +25,4 @@ namespace IRCSharp.Tests.Tokenization.Data
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 class Test
@ -11,5 +9,4 @@ namespace IRCSharp.Tests.Tokenization.Data
public string Input { get; set; }
public JoinModel.Atoms Atoms { get; set; }
}
}
}

View File

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

View File

@ -1,11 +1,8 @@
using IRCTokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IRCSharp.Tests.Tokenization;
namespace IRCSharp.Tests.Tokenization
[TestClass]
public class Hostmask
{
[TestClass]
public class Hostmask
{
[TestMethod]
public void FullHostmask()
{
@ -61,5 +58,4 @@ namespace IRCSharp.Tests.Tokenization
Assert.IsNull(line.Hostmask.UserName);
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 IRCSharp.Tests.Tokenization.Data;
using IRCTokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YamlDotNet.Serialization;
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)
{
var deserializer = new DeserializerBuilder()
@ -33,7 +30,7 @@ namespace IRCSharp.Tests.Tokenization
$"command 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.Params ?? new List<string>(), tokens.Params,
CollectionAssert.AreEqual(atoms.Params ?? [], tokens.Params,
$"params failed on: '{test.Input}'");
}
}
@ -52,5 +49,4 @@ namespace IRCSharp.Tests.Tokenization
Assert.IsTrue(test.Matches.Contains(line), test.Description);
}
}
}
}

View File

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

View File

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

View File

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

View File

@ -212,10 +212,10 @@ namespace IRCTokens
foreach (var p in withoutLast)
{
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(':'))
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);