mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 23:26:40 -08:00
Change to file-scoped namespaces
This commit is contained in:
@@ -13,10 +13,10 @@ using FourNumbers = System.ValueTuple<float, float, float, float>;
|
||||
using static System.Environment;
|
||||
using static Games.Common.IO.Strings;
|
||||
|
||||
namespace Games.Common.IO.TextIOTests
|
||||
namespace Games.Common.IO.TextIOTests;
|
||||
|
||||
public class ReadMethodTests
|
||||
{
|
||||
public class ReadMethodTests
|
||||
{
|
||||
[Theory]
|
||||
[MemberData(nameof(ReadStringTestCases))]
|
||||
[MemberData(nameof(Read2StringsTestCases))]
|
||||
@@ -162,5 +162,4 @@ namespace Games.Common.IO.TextIOTests
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@ using Xunit;
|
||||
using static System.Environment;
|
||||
using static Games.Common.IO.Strings;
|
||||
|
||||
namespace Games.Common.IO
|
||||
namespace Games.Common.IO;
|
||||
|
||||
public class TokenReaderTests
|
||||
{
|
||||
public class TokenReaderTests
|
||||
{
|
||||
private readonly StringWriter _outputWriter;
|
||||
|
||||
public TokenReaderTests()
|
||||
@@ -103,5 +103,4 @@ namespace Games.Common.IO
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace Games.Common.IO
|
||||
namespace Games.Common.IO;
|
||||
|
||||
public class TokenTests
|
||||
{
|
||||
public class TokenTests
|
||||
{
|
||||
[Theory]
|
||||
[MemberData(nameof(TokenTestCases))]
|
||||
public void Ctor_PopulatesProperties(string value, bool isNumber, float number)
|
||||
@@ -39,5 +39,4 @@ namespace Games.Common.IO
|
||||
{ "12e.5", false, float.NaN },
|
||||
{ "12e0.5", true, 12 }
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@ using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace Games.Common.IO
|
||||
namespace Games.Common.IO;
|
||||
|
||||
public class TokenizerTests
|
||||
{
|
||||
public class TokenizerTests
|
||||
{
|
||||
[Theory]
|
||||
[MemberData(nameof(TokenizerTestCases))]
|
||||
public void ParseTokens_SplitsStringIntoExpectedTokens(string input, string[] expected)
|
||||
@@ -30,5 +30,4 @@ namespace Games.Common.IO
|
||||
{ "\"a\"bc,de", new[] { "a" } },
|
||||
{ "a\"b,\" c,d\", f ,,g", new[] { "a\"b", " c,d", "f", "", "g" } }
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
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()
|
||||
: base(Console.In, Console.Out)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
/// Reads a <see cref="float" /> value from input.
|
||||
/// </summary>
|
||||
@@ -65,5 +65,4 @@ namespace Games.Common.IO
|
||||
/// </summary>
|
||||
/// <param name="message">The <see cref="string" /> to be written.</param>
|
||||
void WriteLine(string message);
|
||||
}
|
||||
}
|
||||
@@ -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 ExtraInput = "!Extra input ignored";
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,15 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
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 TextWriter _output;
|
||||
private readonly TokenReader _stringTokenReader;
|
||||
@@ -86,5 +86,4 @@ namespace Games.Common.IO
|
||||
Write(prompt + "? ");
|
||||
return _input.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Text;
|
||||
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*)?");
|
||||
|
||||
internal Token(string value)
|
||||
@@ -56,5 +56,4 @@ namespace Games.Common.IO
|
||||
return new Token(_builder.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ using System.Collections.Generic;
|
||||
|
||||
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 Predicate<Token> _isTokenValid;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Games.Common.IO
|
||||
|
||||
var tokens = new List<Token>();
|
||||
|
||||
while(tokens.Count < quantityNeeded)
|
||||
while (tokens.Count < quantityNeeded)
|
||||
{
|
||||
tokens.AddRange(ReadValidTokens(prompt, quantityNeeded - (uint)tokens.Count));
|
||||
prompt = "?";
|
||||
@@ -77,5 +77,4 @@ namespace Games.Common.IO
|
||||
yield return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
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 Separator = ',';
|
||||
|
||||
@@ -98,5 +98,4 @@ namespace Games.Common.IO
|
||||
public (ITokenizerState, Token.Builder) Consume(char character, Token.Builder tokenBuilder) =>
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user