Skip to content

Commit

Permalink
more tessts
Browse files Browse the repository at this point in the history
  • Loading branch information
LolaLollipop committed Nov 22, 2023
1 parent 712f81e commit 3f5da4c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 6 deletions.
2 changes: 1 addition & 1 deletion RueI/RueI/Parsing/ParserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void RemoveEndingTag<T>()
/// <summary>
/// Applies the <see cref="endingTags"/> and closing <see cref="SizeTags"/> tags to this <see cref="ParserContext"/>.
/// </summary>
internal void ApplyClosingTags()
public void ApplyClosingTags()
{
foreach (NoParamsTag tag in endingTags)
{
Expand Down
41 changes: 41 additions & 0 deletions RueITests/TestExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using RueI.Extensions;

namespace RueITest;

[TestClass]
public class TestExtensions
{
[TestMethod]
public void TestIComparable()
{
int seven = 7;

Assert.AreEqual(10, seven.Max(10));
Assert.AreEqual(7, seven.Max(5));

Assert.AreEqual(7, seven.MaxIf(true, 49));
Assert.AreEqual(49, seven.MaxIf(false, 49));
}

[TestMethod]
public void TestICollection()
{
List<int> list = new();

list.Add(1, 2, 3);

Assert.AreEqual(3, list.Count);
}

[TestMethod]
public void TestUniversal()
{
List<string> list = new();

"hello".AddTo(list);
"world".AddTo(list);

Assert.AreEqual(2, list.Count);
}
}
///"\"hello world - - - again\""
50 changes: 45 additions & 5 deletions RueITests/TestTags.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using RueI;
using RueI.Enums;
using RueI.Parsing;
using RueI.Parsing.Tags;
using System.Linq;
using RueI.Records;

namespace RueITest;

Expand All @@ -15,12 +16,51 @@ public class RealTag : NoParamsTag
{
public override string[] Names { get; } = { "hello" };

public override bool HandleTag(ParserContext context) => throw new NotImplementedException();
public override bool HandleTag(ParserContext context)
{
context.ResultBuilder.Append("hello from RealTag!");
return true;
}
}

[RichTextTag]
public class RealTagTwo : NoParamsTag
{
public override string[] Names { get; } = { "world" };

public override bool HandleTag(ParserContext context)
{
context.ResultBuilder.Append("world from RealTagTwo!");
return true;
}
}

[TestClass]
public class TestTags
{
[TestMethod]
public void TestParserContext()
{
ParserContext context = new();
context.AddEndingTag<RealTag>();

context.AddEndingTag<RealTagTwo>();
context.RemoveEndingTag<RealTagTwo>();

context.ApplyClosingTags();

Assert.AreEqual("hello from RealTag!", context.ResultBuilder.ToString());
}

[TestMethod]
[Description("Tests the measurement info parsing")]
public void CreateMeasurementInfo_ShouldSucceed()
{
Assert.IsTrue(MeasurementInfo.TryParse("50.5px", out MeasurementInfo info));
Assert.AreEqual(50.5, info.Value, 0.001);
Assert.AreEqual(MeasurementUnit.Pixels, info.Style);
}

[TestMethod]
public void TestTagBuilding()
{
Expand All @@ -29,14 +69,14 @@ public void TestTagBuilding()
builder.AddFromAssembly(typeof(TestTags).Assembly);
Parser parser = builder.Build();

Assert.AreEqual(1, parser.Tags.Count);
Assert.AreEqual(2, parser.Tags.Count);
Assert.IsTrue(parser.Tags.Values.Any(x => x.Contains(SharedTag<RealTag>.Singleton)));
}

[TestMethod]
[DataRow("\"hello !!! \nworld")]
[DataRow("hello world again\"")]
public void TestQuoteFailures(string input)
public void TestQuoteProcessing_ShouldNull(string input)
{
string? shouldNull = TagHelpers.ExtractFromQuotations(input);

Expand All @@ -47,7 +87,7 @@ public void TestQuoteFailures(string input)
[DataRow("\"hello world - - - again\"")]
[DataRow("hello \n\n\nworld")]
[DataRow("")]
public void TestQuoteSuccess(string input)
public void TestQuoteProcessing_ShouldExist(string input)
{
string? shouldExist = TagHelpers.ExtractFromQuotations(input);

Expand Down

0 comments on commit 3f5da4c

Please sign in to comment.