Skip to content

Commit

Permalink
Helix Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
occluder committed Jun 12, 2024
1 parent 960815d commit 0e0f7ef
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 43 deletions.
89 changes: 62 additions & 27 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,22 @@ csharp_style_var_for_built_in_types = false
csharp_style_var_when_type_is_apparent = true

# Expression-bodied members
csharp_style_expression_bodied_accessors = true
csharp_style_expression_bodied_constructors = false
csharp_style_expression_bodied_indexers = true
csharp_style_expression_bodied_lambdas = true
csharp_style_expression_bodied_local_functions = when_on_single_line
csharp_style_expression_bodied_methods = when_on_single_line
csharp_style_expression_bodied_operators = when_on_single_line
csharp_style_expression_bodied_properties = when_on_single_line
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = when_on_single_line:silent
csharp_style_expression_bodied_methods = when_on_single_line:silent
csharp_style_expression_bodied_operators = when_on_single_line:silent
csharp_style_expression_bodied_properties = when_on_single_line:silent

# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:silent
csharp_style_prefer_extended_property_pattern = true
csharp_style_prefer_not_pattern = true:warning
csharp_style_prefer_pattern_matching = true:suggestion
csharp_style_prefer_switch_expression = true
csharp_style_prefer_switch_expression = true:suggestion

# Null-checking preferences
csharp_style_conditional_delegate_call = true:warning
Expand All @@ -107,36 +107,36 @@ csharp_preferred_modifier_order = public,private,protected,internal,file,static,
csharp_style_prefer_readonly_struct = true:silent

# Code-block preferences
csharp_prefer_braces = when_multiline
csharp_prefer_simple_using_statement = true
csharp_prefer_braces = when_multiline:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_prefer_method_group_conversion = true
csharp_style_prefer_top_level_statements = false
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = false:silent

# Expression-level preferences
csharp_prefer_simple_default_expression = true
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_deconstructed_variable_declaration = true:warning
csharp_style_implicit_object_creation_when_type_is_apparent = true
csharp_style_inlined_variable_declaration = true
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_prefer_index_operator = true:silent
csharp_style_prefer_local_over_anonymous_function = true
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:warning
csharp_style_prefer_range_operator = true
csharp_style_prefer_tuple_swap = true
csharp_style_prefer_utf8_string_literals = true
csharp_style_prefer_range_operator = true:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
csharp_style_throw_expression = true:silent
csharp_style_unused_value_assignment_preference = discard_variable:warning
csharp_style_unused_value_assignment_preference = discard_variable:silent
csharp_style_unused_value_expression_statement_preference = discard_variable:warning

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:warning

# New line preferences
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
csharp_style_allow_embedded_statements_on_same_line_experimental = false
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false:silent
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false:silent
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false:silent
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:silent
csharp_style_allow_embedded_statements_on_same_line_experimental = false:silent

#### C# Formatting Rules ####

Expand Down Expand Up @@ -247,3 +247,38 @@ dotnet_diagnostic.S1075.severity = suggestion

# S1450: Private fields only used as local variables in methods should become local variables
dotnet_diagnostic.S1450.severity = suggestion
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_coalesce_expression = true:warning
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:warning
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = false:silent
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_readonly_field = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
dotnet_code_quality_unused_parameters = non_public:silent
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
5 changes: 5 additions & 0 deletions MiniTwitch.Helix.Test/Converters/EnumConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace MiniTwitch.Helix.Test.Converters;

public class EnumConverterTest
{
}
42 changes: 42 additions & 0 deletions MiniTwitch.Helix.Test/Converters/IntConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Text;
using MiniTwitch.Helix.Internal.Json;

namespace MiniTwitch.Helix.Test.Converters;

public class IntConverterTest
{
[Fact]
public void Read_Int()
{
var r = IntConverter.ReadInt(Encoding.UTF8.GetBytes("12345"));
Assert.Equal(12345, r);
}

[Fact]
public void Read_Long()
{
var r = IntConverter.ReadInt(Encoding.UTF8.GetBytes("8223372036854780000"));
Assert.Equal(0, r);
}

[Fact]
public void Read_Empty()
{
var r = IntConverter.ReadInt(Span<byte>.Empty);
Assert.Equal(0, r);
}

[Fact]
public void Read_Null()
{
var r2 = IntConverter.ReadInt(Encoding.UTF8.GetBytes("null"));
Assert.Equal(0, r2);
}

[Fact]
public void Read_Undefined()
{
var r2 = IntConverter.ReadInt(Encoding.UTF8.GetBytes("forsen"));
Assert.Equal(0, r2);
}
}
42 changes: 42 additions & 0 deletions MiniTwitch.Helix.Test/Converters/LongConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Text;
using MiniTwitch.Helix.Internal.Json;

namespace MiniTwitch.Helix.Test.Converters;

public class LongConverterTest
{
[Fact]
public void Read_Int()
{
var r = LongConverter.ReadLong(Encoding.UTF8.GetBytes("12345"));
Assert.Equal(12345, r);
}

[Fact]
public void Read_Long()
{
var r = LongConverter.ReadLong(Encoding.UTF8.GetBytes("8223372036854780000"));
Assert.Equal(8223372036854780000, r);
}

[Fact]
public void Read_Empty()
{
var r = LongConverter.ReadLong(Span<byte>.Empty);
Assert.Equal(0, r);
}

[Fact]
public void Read_Null()
{
var r2 = LongConverter.ReadLong(Encoding.UTF8.GetBytes("null"));
Assert.Equal(0, r2);
}

[Fact]
public void Read_Undefined()
{
var r2 = LongConverter.ReadLong(Encoding.UTF8.GetBytes("forsen"));
Assert.Equal(0, r2);
}
}
44 changes: 44 additions & 0 deletions MiniTwitch.Helix.Test/Converters/OptionalLongConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Text;
using MiniTwitch.Helix.Internal.Json;

namespace MiniTwitch.Helix.Test.Converters;

public class OptionalLongConverterTest
{
[Fact]
public void Read_Int()
{
var r = OptionalLongConverter.ReadLong(Encoding.UTF8.GetBytes("12345"));
var val = Assert.NotNull(r);
Assert.Equal(12345, val);
}

[Fact]
public void Read_Long()
{
var r = OptionalLongConverter.ReadLong(Encoding.UTF8.GetBytes("8223372036854780000"));
var val = Assert.NotNull(r);
Assert.Equal(8223372036854780000, val);
}

[Fact]
public void Read_Empty()
{
var r = OptionalLongConverter.ReadLong(Span<byte>.Empty);
Assert.Null(r);
}

[Fact]
public void Read_Null()
{
var r2 = OptionalLongConverter.ReadLong(Encoding.UTF8.GetBytes("null"));
Assert.Null(r2);
}

[Fact]
public void Read_Undefined()
{
var r2 = OptionalLongConverter.ReadLong(Encoding.UTF8.GetBytes("forsen"));
Assert.Null(r2);
}
}
27 changes: 27 additions & 0 deletions MiniTwitch.Helix.Test/MiniTwitch.Helix.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MiniTwitch.Helix\MiniTwitch.Helix.csproj" />
</ItemGroup>

</Project>
74 changes: 74 additions & 0 deletions MiniTwitch.Helix.Test/SnakeCaseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using MiniTwitch.Helix.Internal.Json;

namespace MiniTwitch.Helix.Test;

public class SnakeCaseTest
{
[Fact]
public void From_SnakeCase()
{
ICaseConverter converter = SnakeCase.Instance;
string? converted = converter.ConvertFromCase("hello_world");
Assert.Equal("HelloWorld", converted);
}

[Fact]
public void From_Null_SnakeCase()
{
ICaseConverter converter = SnakeCase.Instance;
string? converted = converter.ConvertFromCase(null);
Assert.Null(converted);
}

[Fact]
public void From_Empty_SnakeCase()
{
ICaseConverter converter = SnakeCase.Instance;
string? converted = converter.ConvertFromCase(string.Empty);
Assert.NotNull(converted);
Assert.Empty(converted);
}

[Fact]
public void From_Space_SnakeCase()
{
ICaseConverter converter = SnakeCase.Instance;
string? converted = converter.ConvertFromCase(" ");
Assert.NotNull(converted);
Assert.Equal(" ", converted);
}

[Fact]
public void To_SnakeCase()
{
ICaseConverter converter = SnakeCase.Instance;
string? converted = converter.ConvertToCase("HelloForsenPajladaOne");
Assert.Equal("hello_forsen_pajlada_one", converted);
}

[Fact]
public void Null_To_SnakeCase()
{
ICaseConverter converter = SnakeCase.Instance;
string? converted = converter.ConvertToCase(null);
Assert.Null(converted);
}

[Fact]
public void Empty_To_SnakeCase()
{
ICaseConverter converter = SnakeCase.Instance;
string? converted = converter.ConvertToCase(string.Empty);
Assert.NotNull(converted);
Assert.Empty(converted);
}

[Fact]
public void Space_To_SnakeCase()
{
ICaseConverter converter = SnakeCase.Instance;
string? converted = converter.ConvertToCase(" ");
Assert.NotNull(converted);
Assert.Equal(" ", converted);
}
}
3 changes: 3 additions & 0 deletions MiniTwitch.Helix/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("MiniTwitch.Helix.Test")]
Loading

0 comments on commit 0e0f7ef

Please sign in to comment.