diff --git a/RueI/RueI/Parsing/ParserContext.cs b/RueI/RueI/Parsing/ParserContext.cs index fe3d652..2d79a98 100644 --- a/RueI/RueI/Parsing/ParserContext.cs +++ b/RueI/RueI/Parsing/ParserContext.cs @@ -83,7 +83,7 @@ public void RemoveEndingTag() /// /// Applies the and closing tags to this . /// - internal void ApplyClosingTags() + public void ApplyClosingTags() { foreach (NoParamsTag tag in endingTags) { diff --git a/RueITests/TestExtensions.cs b/RueITests/TestExtensions.cs new file mode 100644 index 0000000..393177a --- /dev/null +++ b/RueITests/TestExtensions.cs @@ -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 list = new(); + + list.Add(1, 2, 3); + + Assert.AreEqual(3, list.Count); + } + + [TestMethod] + public void TestUniversal() + { + List list = new(); + + "hello".AddTo(list); + "world".AddTo(list); + + Assert.AreEqual(2, list.Count); + } +} +///"\"hello world - - - again\"" \ No newline at end of file diff --git a/RueITests/TestTags.cs b/RueITests/TestTags.cs index 6b3d472..ed0c0f5 100644 --- a/RueITests/TestTags.cs +++ b/RueITests/TestTags.cs @@ -1,7 +1,8 @@ using RueI; +using RueI.Enums; using RueI.Parsing; using RueI.Parsing.Tags; -using System.Linq; +using RueI.Records; namespace RueITest; @@ -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(); + + context.AddEndingTag(); + context.RemoveEndingTag(); + + 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() { @@ -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.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); @@ -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);