Change to file-scoped namespaces

This commit is contained in:
Andrew Cooper
2022-02-15 22:33:44 +11:00
parent fc92500074
commit 35f68dcf72
11 changed files with 642 additions and 653 deletions

View File

@@ -13,10 +13,10 @@ using FourNumbers = System.ValueTuple<float, float, float, float>;
using static System.Environment; using static System.Environment;
using static Games.Common.IO.Strings; using static Games.Common.IO.Strings;
namespace Games.Common.IO.TextIOTests namespace Games.Common.IO.TextIOTests;
public class ReadMethodTests
{ {
public class ReadMethodTests
{
[Theory] [Theory]
[MemberData(nameof(ReadStringTestCases))] [MemberData(nameof(ReadStringTestCases))]
[MemberData(nameof(Read2StringsTestCases))] [MemberData(nameof(Read2StringsTestCases))]
@@ -162,5 +162,4 @@ namespace Games.Common.IO.TextIOTests
} }
}; };
} }
}
} }

View File

@@ -8,10 +8,10 @@ using Xunit;
using static System.Environment; using static System.Environment;
using static Games.Common.IO.Strings; using static Games.Common.IO.Strings;
namespace Games.Common.IO namespace Games.Common.IO;
public class TokenReaderTests
{ {
public class TokenReaderTests
{
private readonly StringWriter _outputWriter; private readonly StringWriter _outputWriter;
public TokenReaderTests() public TokenReaderTests()
@@ -103,5 +103,4 @@ namespace Games.Common.IO
} }
}; };
} }
}
} }

View File

@@ -1,10 +1,10 @@
using FluentAssertions; using FluentAssertions;
using Xunit; using Xunit;
namespace Games.Common.IO namespace Games.Common.IO;
public class TokenTests
{ {
public class TokenTests
{
[Theory] [Theory]
[MemberData(nameof(TokenTestCases))] [MemberData(nameof(TokenTestCases))]
public void Ctor_PopulatesProperties(string value, bool isNumber, float number) public void Ctor_PopulatesProperties(string value, bool isNumber, float number)
@@ -39,5 +39,4 @@ namespace Games.Common.IO
{ "12e.5", false, float.NaN }, { "12e.5", false, float.NaN },
{ "12e0.5", true, 12 } { "12e0.5", true, 12 }
}; };
}
} }

View File

@@ -2,10 +2,10 @@ using System.Linq;
using FluentAssertions; using FluentAssertions;
using Xunit; using Xunit;
namespace Games.Common.IO namespace Games.Common.IO;
public class TokenizerTests
{ {
public class TokenizerTests
{
[Theory] [Theory]
[MemberData(nameof(TokenizerTestCases))] [MemberData(nameof(TokenizerTestCases))]
public void ParseTokens_SplitsStringIntoExpectedTokens(string input, string[] expected) public void ParseTokens_SplitsStringIntoExpectedTokens(string input, string[] expected)
@@ -30,5 +30,4 @@ namespace Games.Common.IO
{ "\"a\"bc,de", new[] { "a" } }, { "\"a\"bc,de", new[] { "a" } },
{ "a\"b,\" c,d\", f ,,g", new[] { "a\"b", " c,d", "f", "", "g" } } { "a\"b,\" c,d\", f ,,g", new[] { "a\"b", " c,d", "f", "", "g" } }
}; };
}
} }

View File

@@ -1,16 +1,15 @@
using System; using System;
namespace Games.Common.IO namespace Games.Common.IO;
/// <summary>
/// An implementation of <see cref="IReadWrite" /> with input begin read for STDIN and output being written to
/// STDOUT.
/// </summary>
public sealed class ConsoleIO : TextIO
{ {
/// <summary>
/// An implementation of <see cref="IReadWrite" /> with input begin read for STDIN and output being written to
/// STDOUT.
/// </summary>
public sealed class ConsoleIO : TextIO
{
public ConsoleIO() public ConsoleIO()
: base(Console.In, Console.Out) : base(Console.In, Console.Out)
{ {
} }
}
} }

View File

@@ -1,10 +1,10 @@
namespace Games.Common.IO namespace Games.Common.IO;
/// <summary>
/// Provides for input and output of strings and numbers.
/// </summary>
public interface IReadWrite
{ {
/// <summary>
/// Provides for input and output of strings and numbers.
/// </summary>
public interface IReadWrite
{
/// <summary> /// <summary>
/// Reads a <see cref="float" /> value from input. /// Reads a <see cref="float" /> value from input.
/// </summary> /// </summary>
@@ -65,5 +65,4 @@ namespace Games.Common.IO
/// </summary> /// </summary>
/// <param name="message">The <see cref="string" /> to be written.</param> /// <param name="message">The <see cref="string" /> to be written.</param>
void WriteLine(string message); void WriteLine(string message);
}
} }

View File

@@ -1,8 +1,7 @@
namespace Games.Common.IO namespace Games.Common.IO;
internal static class Strings
{ {
internal static class Strings
{
internal const string NumberExpected = "!Number expected - retry input line"; internal const string NumberExpected = "!Number expected - retry input line";
internal const string ExtraInput = "!Extra input ignored"; internal const string ExtraInput = "!Extra input ignored";
}
} }

View File

@@ -3,15 +3,15 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
namespace Games.Common.IO namespace Games.Common.IO;
/// <inheritdoc />
/// <summary>
/// Implements <see cref="IReadWrite" /> with input read from a <see cref="TextReader" /> and output written to a
/// <see cref="TextWriter" />.
/// </summary>
public class TextIO : IReadWrite
{ {
/// <inheritdoc />
/// <summary>
/// Implements <see cref="IReadWrite" /> with input read from a <see cref="TextReader" /> and output written to a
/// <see cref="TextWriter" />.
/// </summary>
public class TextIO : IReadWrite
{
private readonly TextReader _input; private readonly TextReader _input;
private readonly TextWriter _output; private readonly TextWriter _output;
private readonly TokenReader _stringTokenReader; private readonly TokenReader _stringTokenReader;
@@ -86,5 +86,4 @@ namespace Games.Common.IO
Write(prompt + "? "); Write(prompt + "? ");
return _input.ReadLine(); return _input.ReadLine();
} }
}
} }

View File

@@ -1,10 +1,10 @@
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Games.Common.IO namespace Games.Common.IO;
internal class Token
{ {
internal class Token
{
private static readonly Regex _numberPattern = new(@"^[+\-]?\d*(\.\d*)?([eE][+\-]?\d*)?"); private static readonly Regex _numberPattern = new(@"^[+\-]?\d*(\.\d*)?([eE][+\-]?\d*)?");
internal Token(string value) internal Token(string value)
@@ -56,5 +56,4 @@ namespace Games.Common.IO
return new Token(_builder.ToString()); return new Token(_builder.ToString());
} }
} }
}
} }

View File

@@ -3,10 +3,10 @@ using System.Collections.Generic;
using static Games.Common.IO.Strings; using static Games.Common.IO.Strings;
namespace Games.Common.IO namespace Games.Common.IO;
internal class TokenReader
{ {
internal class TokenReader
{
private readonly TextIO _io; private readonly TextIO _io;
private readonly Predicate<Token> _isTokenValid; private readonly Predicate<Token> _isTokenValid;
@@ -30,7 +30,7 @@ namespace Games.Common.IO
var tokens = new List<Token>(); var tokens = new List<Token>();
while(tokens.Count < quantityNeeded) while (tokens.Count < quantityNeeded)
{ {
tokens.AddRange(ReadValidTokens(prompt, quantityNeeded - (uint)tokens.Count)); tokens.AddRange(ReadValidTokens(prompt, quantityNeeded - (uint)tokens.Count));
prompt = "?"; prompt = "?";
@@ -77,5 +77,4 @@ namespace Games.Common.IO
yield return token; yield return token;
} }
} }
}
} }

View File

@@ -1,10 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Games.Common.IO namespace Games.Common.IO;
internal class Tokenizer
{ {
internal class Tokenizer
{
private const char Quote = '"'; private const char Quote = '"';
private const char Separator = ','; private const char Separator = ',';
@@ -98,5 +98,4 @@ namespace Games.Common.IO
public (ITokenizerState, Token.Builder) Consume(char character, Token.Builder tokenBuilder) => public (ITokenizerState, Token.Builder) Consume(char character, Token.Builder tokenBuilder) =>
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
}
} }