Example #1
0
        [Test] public void TestExpandHtml()
        {
            var filepath = Path.GetTempFileName();
            var data     = Encoding.UTF8.GetBytes("include file\r\ntext data");

            // Shared read access doesn't work for DeleteOnClose files so might as well just use a normal file and delete on clean up
            using (var file = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.Read))
                file.Write(data, 0, data.Length);

            using (Scope.Create(null, () => Path_.DelFile(filepath)))
            {
                var template =
                    $"<root>\r\n" +
                    $"\t\t <!--#include file=\"{filepath}\"-->\r\n" +
                    $"<!--#var name=\"MyVar\" file=\"{filepath}\" value=\"text\\s+(?<value>\\w+)\"-->\r\n" +
                    $"  <!--#value name=\"MyVar\"-->\r\n" +
                    $"    <!--#value name=\"MyVar\"-->\r\n" +
                    $"</root>\r\n";
                const string result =
                    "<root>\r\n" +
                    "\t\t include file\r\n" +
                    "\t\t text data\r\n" +
                    "\r\n" +
                    "  data\r\n" +
                    "    data\r\n" +
                    "</root>\r\n";
                var r = Expand.Html(new StringSrc(template), Environment.CurrentDirectory);
                Assert.Equal(result, r);
            }
        }