Skip to content

Commit

Permalink
TESTS!!!!!!!!!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
LolaLollipop committed Nov 22, 2023
1 parent 5fd1b40 commit da9d0fe
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ RueI/obj
_site/
api/
References/
packages/
RueITests/obj
RueITests/bin
10 changes: 10 additions & 0 deletions RueI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RueI", "RueI\RueI.csproj", "{5A7DFDD8-78E1-418F-928B-AA4BC1289AA9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RueITests", "RueITests\RueITests.csproj", "{91D7C5BF-1273-4E70-BE19-7EC8907E2DAC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Exiled|Any CPU = Debug Exiled|Any CPU
Expand All @@ -20,6 +22,14 @@ Global
{5A7DFDD8-78E1-418F-928B-AA4BC1289AA9}.Release Exiled|Any CPU.Build.0 = Debug|Any CPU
{5A7DFDD8-78E1-418F-928B-AA4BC1289AA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A7DFDD8-78E1-418F-928B-AA4BC1289AA9}.Release|Any CPU.Build.0 = Release|Any CPU
{91D7C5BF-1273-4E70-BE19-7EC8907E2DAC}.Debug Exiled|Any CPU.ActiveCfg = Debug|Any CPU
{91D7C5BF-1273-4E70-BE19-7EC8907E2DAC}.Debug Exiled|Any CPU.Build.0 = Debug|Any CPU
{91D7C5BF-1273-4E70-BE19-7EC8907E2DAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91D7C5BF-1273-4E70-BE19-7EC8907E2DAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91D7C5BF-1273-4E70-BE19-7EC8907E2DAC}.Release Exiled|Any CPU.ActiveCfg = Release|Any CPU
{91D7C5BF-1273-4E70-BE19-7EC8907E2DAC}.Release Exiled|Any CPU.Build.0 = Release|Any CPU
{91D7C5BF-1273-4E70-BE19-7EC8907E2DAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91D7C5BF-1273-4E70-BE19-7EC8907E2DAC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 0 additions & 5 deletions RueI/RueI/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public static partial class Constants
/// </summary>
public static TimeSpan HintRateLimit { get; } = TimeSpan.FromMilliseconds(0.525);

/// <summary>
/// Gets the default color for hints.
/// </summary>
public const string DEFAULTCOLOR = "#FFF";

/// <summary>
/// Gets a list of allowed sizes of color param tags, ignoring the hashtag.
/// </summary>
Expand Down
16 changes: 10 additions & 6 deletions RueI/RueI/DefaultParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@
using RueI.Parsing.Tags;

/// <summary>
/// Provides the default and main <see cref="Parser"/> for RueI.
/// Provides the default and main <see cref="RueI.Parser"/> for RueI.
/// </summary>
public static class DefaultParser
{
/// <summary>
/// Gets the default <see cref="Parser"/>.
/// Gets the default <see cref="RueI.Parser"/>.
/// </summary>
public static Parser Parser { get; } = GetParser();
public static Parser Parser { get; } = GetParser(typeof(DefaultParser).Assembly);

private static Parser GetParser()
/// <summary>
/// Gets a new <see cref="RueI.Parser"/> from an assembly by getting all of the <see cref="RichTextTagAttribute"/> classes.
/// </summary>
/// <returns>A new <see cref="RueI.Parser"/>.</returns>
/// <remarks>This method is used for unit testing.</remarks>
private static Parser GetParser(Assembly assembly)
{
ParserBuilder builder = new();
Assembly currentAssembly = typeof(DefaultParser).Assembly;

MethodInfo addTag = typeof(ParserBuilder).GetMethod(nameof(ParserBuilder.AddTag));

foreach (Type type in currentAssembly.GetTypes())
foreach (Type type in assembly.GetTypes())
{
if (type.GetCustomAttributes(typeof(RichTextTagAttribute), true).Any() && type.IsSubclassOf(typeof(RichTextTag)))
{
Expand Down
5 changes: 5 additions & 0 deletions RueI/RueI/Parsing/ParserBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public sealed class ParserBuilder
{
private readonly List<RichTextTag> currentTags = ListPool<RichTextTag>.Shared.Rent(10);

/// <summary>
/// Gets the number of tags within this <see cref="ParserBuilder"/>.
/// </summary>
public int TagsCount=> currentTags.Count;

/// <summary>
/// Initializes a new instance of the <see cref="ParserBuilder"/> class.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions RueITests/RueITests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RueI\RueI.csproj" />
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions RueITests/TestTags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using RueI.Parsing.Tags;

namespace RueITest
{
[TestClass]
public class TestTags
{
[TestMethod]
public void TestUtility()
{
string? shouldExist = TagHelpers.ExtractFromQuotations("hello world");
string? shouldExist2 = TagHelpers.ExtractFromQuotations("\"hello world - - - again\"");

string? shouldNull = TagHelpers.ExtractFromQuotations("\"hello !!! \nworld");
string? shouldNull2 = TagHelpers.ExtractFromQuotations("hello world again\"");

Assert.IsNotNull(shouldExist);
Assert.IsNotNull(shouldExist2);

Assert.IsNull(shouldNull);
Assert.IsNull(shouldNull2);
}
}
}
1 change: 1 addition & 0 deletions RueITests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;

0 comments on commit da9d0fe

Please sign in to comment.