Skip to content

Commit

Permalink
file scoped namespaces (#1452)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 24, 2024
1 parent 4d20abc commit dfe6226
Show file tree
Hide file tree
Showing 385 changed files with 25,785 additions and 26,175 deletions.
31 changes: 15 additions & 16 deletions src/Humanizer.Tests/ArticlePrefixSortTests.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
namespace Humanizer.Tests
namespace Humanizer.Tests;

public class ArticlePrefixSortTests
{
public class ArticlePrefixSortTests
{
[Theory]
[InlineData(new[] { "Ant", "The Theater", "The apple", "Fox", "Bear" }, new[] { "Ant", "The apple", "Bear", "Fox", "The Theater" })]
[InlineData(new[] { "An Ant", "The Theater", "the apple", "a Fox", "Bear" }, new[] { "An Ant", "the apple", "Bear", "a Fox", "The Theater" })]
[InlineData(new[] { "Ant", "A Theater", "an apple", "Fox", "Bear" }, new[] { "Ant", "an apple", "Bear", "Fox", "A Theater" })]
[InlineData(new[] { " Ant ", " A Theater ", " an apple ", " Fox", "Bear " }, new[] { "A Theater", "an apple", "Ant", "Bear", "Fox" })]
[InlineData(new[] { "The General Theory of Relativity" }, new[] { "The General Theory of Relativity" })]
public void SortStringArrayIgnoringArticlePrefixes(string[] input, string[] expectedOutput) =>
Assert.Equal(expectedOutput, EnglishArticle.PrependArticleSuffix(EnglishArticle.AppendArticlePrefix(input)));
[Theory]
[InlineData(new[] { "Ant", "The Theater", "The apple", "Fox", "Bear" }, new[] { "Ant", "The apple", "Bear", "Fox", "The Theater" })]
[InlineData(new[] { "An Ant", "The Theater", "the apple", "a Fox", "Bear" }, new[] { "An Ant", "the apple", "Bear", "a Fox", "The Theater" })]
[InlineData(new[] { "Ant", "A Theater", "an apple", "Fox", "Bear" }, new[] { "Ant", "an apple", "Bear", "Fox", "A Theater" })]
[InlineData(new[] { " Ant ", " A Theater ", " an apple ", " Fox", "Bear " }, new[] { "A Theater", "an apple", "Ant", "Bear", "Fox" })]
[InlineData(new[] { "The General Theory of Relativity" }, new[] { "The General Theory of Relativity" })]
public void SortStringArrayIgnoringArticlePrefixes(string[] input, string[] expectedOutput) =>
Assert.Equal(expectedOutput, EnglishArticle.PrependArticleSuffix(EnglishArticle.AppendArticlePrefix(input)));

[Fact]
public void An_Empty_String_Array_Throws_ArgumentOutOfRangeException()
{
[Fact]
public void An_Empty_String_Array_Throws_ArgumentOutOfRangeException()
{
string[] items = [];
void action() => EnglishArticle.AppendArticlePrefix(items);
Assert.Throws<ArgumentOutOfRangeException>(action);
}
}
}
}
65 changes: 32 additions & 33 deletions src/Humanizer.Tests/BitFieldEnumHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
namespace Humanizer.Tests
{
[UseCulture("en")]
public class BitFieldEnumHumanizeTests
{
[Fact]
public void CanHumanizeSingleWordDescriptionAttribute() =>
Assert.Equal(BitFlagEnumTestsResources.MemberWithSingleWordDisplayAttribute, BitFieldEnumUnderTest.RED.Humanize());
namespace Humanizer.Tests;

[Fact]
public void CanHumanizeMultipleWordDescriptionAttribute() =>
Assert.Equal(BitFlagEnumTestsResources.MemberWithMultipleWordDisplayAttribute, BitFieldEnumUnderTest.DARK_GRAY.Humanize());
[UseCulture("en")]
public class BitFieldEnumHumanizeTests
{
[Fact]
public void CanHumanizeSingleWordDescriptionAttribute() =>
Assert.Equal(BitFlagEnumTestsResources.MemberWithSingleWordDisplayAttribute, BitFieldEnumUnderTest.RED.Humanize());

[Fact]
public void CanHumanizeMultipleValueBitFieldEnum()
{
var xoredBitFlag = BitFieldEnumUnderTest.RED | BitFieldEnumUnderTest.DARK_GRAY;
Assert.Equal(BitFlagEnumTestsResources.ExpectedResultWhenBothValuesXored, xoredBitFlag.Humanize());
}
[Fact]
public void CanHumanizeMultipleWordDescriptionAttribute() =>
Assert.Equal(BitFlagEnumTestsResources.MemberWithMultipleWordDisplayAttribute, BitFieldEnumUnderTest.DARK_GRAY.Humanize());

[Fact]
public void CanHumanizeShortSingleWordDescriptionAttribute() =>
Assert.Equal(BitFlagEnumTestsResources.MemberWithSingleWordDisplayAttribute, ShortBitFieldEnumUnderTest.RED.Humanize());
[Fact]
public void CanHumanizeMultipleValueBitFieldEnum()
{
var xoredBitFlag = BitFieldEnumUnderTest.RED | BitFieldEnumUnderTest.DARK_GRAY;
Assert.Equal(BitFlagEnumTestsResources.ExpectedResultWhenBothValuesXored, xoredBitFlag.Humanize());
}

[Fact]
public void CanHumanizeShortMultipleWordDescriptionAttribute() =>
Assert.Equal(BitFlagEnumTestsResources.MemberWithMultipleWordDisplayAttribute, ShortBitFieldEnumUnderTest.DARK_GRAY.Humanize());
[Fact]
public void CanHumanizeShortSingleWordDescriptionAttribute() =>
Assert.Equal(BitFlagEnumTestsResources.MemberWithSingleWordDisplayAttribute, ShortBitFieldEnumUnderTest.RED.Humanize());

[Fact]
public void CanHumanizeShortMultipleValueBitFieldEnum()
{
var xoredBitFlag = ShortBitFieldEnumUnderTest.RED | ShortBitFieldEnumUnderTest.DARK_GRAY;
Assert.Equal(BitFlagEnumTestsResources.ExpectedResultWhenBothValuesXored, xoredBitFlag.Humanize());
}
[Fact]
public void CanHumanizeShortMultipleWordDescriptionAttribute() =>
Assert.Equal(BitFlagEnumTestsResources.MemberWithMultipleWordDisplayAttribute, ShortBitFieldEnumUnderTest.DARK_GRAY.Humanize());

[Fact]
public void CanHumanizeBitFieldEnumWithZeroValue() =>
Assert.Equal(BitFlagEnumTestsResources.None, BitFieldEnumUnderTest.NONE.Humanize());
[Fact]
public void CanHumanizeShortMultipleValueBitFieldEnum()
{
var xoredBitFlag = ShortBitFieldEnumUnderTest.RED | ShortBitFieldEnumUnderTest.DARK_GRAY;
Assert.Equal(BitFlagEnumTestsResources.ExpectedResultWhenBothValuesXored, xoredBitFlag.Humanize());
}
}

[Fact]
public void CanHumanizeBitFieldEnumWithZeroValue() =>
Assert.Equal(BitFlagEnumTestsResources.None, BitFieldEnumUnderTest.NONE.Humanize());
}
53 changes: 26 additions & 27 deletions src/Humanizer.Tests/BitFieldEnumUnderTest.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
using System.ComponentModel.DataAnnotations;

namespace Humanizer.Tests
namespace Humanizer.Tests;

[Flags]
public enum BitFieldEnumUnderTest : int
{
[Flags]
public enum BitFieldEnumUnderTest : int
{
[Display(Description = BitFlagEnumTestsResources.None)]
NONE = 0,
[Display(Description = BitFlagEnumTestsResources.MemberWithSingleWordDisplayAttribute)]
RED = 1,
[Display(Description = BitFlagEnumTestsResources.MemberWithMultipleWordDisplayAttribute)]
DARK_GRAY = 2
}
[Display(Description = BitFlagEnumTestsResources.None)]
NONE = 0,
[Display(Description = BitFlagEnumTestsResources.MemberWithSingleWordDisplayAttribute)]
RED = 1,
[Display(Description = BitFlagEnumTestsResources.MemberWithMultipleWordDisplayAttribute)]
DARK_GRAY = 2
}

[Flags]
public enum ShortBitFieldEnumUnderTest : short
{
[Display(Description = BitFlagEnumTestsResources.MemberWithSingleWordDisplayAttribute)]
RED = 1,
[Display(Description = BitFlagEnumTestsResources.MemberWithMultipleWordDisplayAttribute)]
DARK_GRAY = 2
}
[Flags]
public enum ShortBitFieldEnumUnderTest : short
{
[Display(Description = BitFlagEnumTestsResources.MemberWithSingleWordDisplayAttribute)]
RED = 1,
[Display(Description = BitFlagEnumTestsResources.MemberWithMultipleWordDisplayAttribute)]
DARK_GRAY = 2
}

public class BitFlagEnumTestsResources
{
public const string None = "None";
public const string MemberWithSingleWordDisplayAttribute = "Red";
public const string MemberWithMultipleWordDisplayAttribute = "Dark Gray";
public class BitFlagEnumTestsResources
{
public const string None = "None";
public const string MemberWithSingleWordDisplayAttribute = "Red";
public const string MemberWithMultipleWordDisplayAttribute = "Dark Gray";

public const string ExpectedResultWhenBothValuesXored = "Red and Dark Gray";
}
}
public const string ExpectedResultWhenBothValuesXored = "Red and Dark Gray";
}
85 changes: 42 additions & 43 deletions src/Humanizer.Tests/Bytes/ArithmeticTests.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
namespace Humanizer.Tests.Bytes
namespace Humanizer.Tests.Bytes;

public class ArithmeticTests
{
public class ArithmeticTests
[Fact]
public void Add()
{
[Fact]
public void Add()
{
var size1 = ByteSize.FromBytes(1);
var result = size1.Add(size1);

Assert.Equal(2, result.Bytes);
Assert.Equal(16, result.Bits);
}

[Fact]
public void AddBits()
{
[Fact]
public void AddBits()
{
var size = ByteSize.FromBytes(1).AddBits(8);

Assert.Equal(2, size.Bytes);
Assert.Equal(16, size.Bits);
}

[Fact]
public void AddBytes()
{
[Fact]
public void AddBytes()
{
var size = ByteSize.FromBytes(1).AddBytes(1);

Assert.Equal(2, size.Bytes);
Assert.Equal(16, size.Bits);
}

[Fact]
public void AddKilobytes()
{
[Fact]
public void AddKilobytes()
{
var size = ByteSize.FromKilobytes(2).AddKilobytes(2);

Assert.Equal(4 * 1024 * 8, size.Bits);
Assert.Equal(4 * 1024, size.Bytes);
Assert.Equal(4, size.Kilobytes);
}

[Fact]
public void AddMegabytes()
{
[Fact]
public void AddMegabytes()
{
var size = ByteSize.FromMegabytes(2).AddMegabytes(2);

Assert.Equal(4 * 1024 * 1024 * 8, size.Bits);
Expand All @@ -51,9 +51,9 @@ public void AddMegabytes()
Assert.Equal(4, size.Megabytes);
}

[Fact]
public void AddGigabytes()
{
[Fact]
public void AddGigabytes()
{
var size = ByteSize.FromGigabytes(2).AddGigabytes(2);

Assert.Equal(4d * 1024 * 1024 * 1024 * 8, size.Bits);
Expand All @@ -63,9 +63,9 @@ public void AddGigabytes()
Assert.Equal(4d, size.Gigabytes);
}

[Fact]
public void AddTerabytes()
{
[Fact]
public void AddTerabytes()
{
var size = ByteSize.FromTerabytes(2).AddTerabytes(2);

Assert.Equal(4d * 1024 * 1024 * 1024 * 1024 * 8, size.Bits);
Expand All @@ -76,28 +76,28 @@ public void AddTerabytes()
Assert.Equal(4d, size.Terabytes);
}

[Fact]
public void Subtract()
{
[Fact]
public void Subtract()
{
var size = ByteSize.FromBytes(4).Subtract(ByteSize.FromBytes(2));

Assert.Equal(16, size.Bits);
Assert.Equal(2, size.Bytes);
}

[Fact]
public void IncrementOperator()
{
[Fact]
public void IncrementOperator()
{
var size = ByteSize.FromBytes(2);
size++;

Assert.Equal(24, size.Bits);
Assert.Equal(3, size.Bytes);
}

[Fact]
public void NegativeOperator()
{
[Fact]
public void NegativeOperator()
{
var size = ByteSize.FromBytes(2);

size = -size;
Expand All @@ -106,19 +106,19 @@ public void NegativeOperator()
Assert.Equal(-2, size.Bytes);
}

[Fact]
public void DecrementOperator()
{
[Fact]
public void DecrementOperator()
{
var size = ByteSize.FromBytes(2);
size--;

Assert.Equal(8, size.Bits);
Assert.Equal(1, size.Bytes);
}

[Fact]
public void PlusOperator()
{
[Fact]
public void PlusOperator()
{
var size1 = ByteSize.FromBytes(1);
var size2 = ByteSize.FromBytes(1);

Expand All @@ -127,15 +127,14 @@ public void PlusOperator()
Assert.Equal(2, result.Bytes);
}

[Fact]
public void MinusOperator()
{
[Fact]
public void MinusOperator()
{
var size1 = ByteSize.FromBytes(2);
var size2 = ByteSize.FromBytes(1);

var result = size1 - size2;

Assert.Equal(1, result.Bytes);
}
}
}
}
Loading

0 comments on commit dfe6226

Please sign in to comment.