コード例 #1
0
            public void ThrowForNoSourceWhenIncludingRelativePath()
            {
                // Given
                IDocument[] documents =
                {
                    Context.GetDocument(Context.GetContentStream("foo ^\"test-a.txt\" bar"))
                };
                Include include = new Include();

                // When, Then
                Assert.Throws <AggregateException>(() => include.Execute(documents, Context).ToList());
            }
コード例 #2
0
            public void IncludeOnFirstCharacter()
            {
                // Given
                IDocument[] documents =
                {
                    Context.GetDocument(new FilePath("/TestFiles/Input/test.txt"), Context.GetContentStream("^\"test-a.txt\"foo"))
                };
                Include include = new Include();

                // When
                List <IDocument> results = include.Execute(documents, Context).ToList();

                // Then
                Assert.AreEqual("aaafoo", results.Single().Content);
            }
コード例 #3
0
            public void DoesNotThrowForNoSourceWhenIncludingAbsolutePath()
            {
                // Given
                IDocument[] documents =
                {
                    Context.GetDocument(Context.GetContentStream("foo ^\"/TestFiles/Input/test-a.txt\" bar"))
                };
                Include include = new Include();

                // When, Then
                List <IDocument> results = include.Execute(documents, Context).ToList();

                // Then
                Assert.AreEqual("foo aaa bar", results.Single().Content);
            }
コード例 #4
0
ファイル: IncludeFixture.cs プロジェクト: schulz3000/Wyam
            public void MultipleEscapeCharacters()
            {
                // Given
                IDocument[] documents =
                {
                    Context.GetDocument(new FilePath("/TestFiles/Input/test.txt"), "\\\\\\^\"test-a.txt\"foo")
                };
                Include include = new Include();

                // When
                List <IDocument> results = include.Execute(documents, Context).ToList();

                // Then
                Assert.AreEqual("\\\\^\"test-a.txt\"foo", results.Single().Content);
            }
コード例 #5
0
            public void IncludingAbsolutePath()
            {
                // Given
                IDocument[] documents =
                {
                    Context.GetDocument(
                        new FilePath("/TestFiles/Input/test.txt"),
                        Context.GetContentStream("x ^\"/TestFiles/test-above-input.txt\" y"))
                };
                Include include = new Include();

                // When
                List <IDocument> results = include.Execute(documents, Context).ToList();

                // Then
                Assert.AreEqual("x test y", results.Single().Content);
            }
コード例 #6
0
            public void MultipleAdjacentIncludes()
            {
                // Given
                IDocument[] documents =
                {
                    Context.GetDocument(
                        new FilePath("/TestFiles/Input/test.txt"),
                        Context.GetContentStream("x ^\"test-a.txt\"^\"test-b.txt\" z"))
                };
                Include include = new Include();

                // When
                List <IDocument> results = include.Execute(documents, Context).ToList();

                // Then
                Assert.AreEqual("x aaabbb z", results.Single().Content);
            }
コード例 #7
0
ファイル: IncludeFixture.cs プロジェクト: schulz3000/Wyam
            public void IncludingRelativePath()
            {
                // Given
                IDocument[] documents =
                {
                    Context.GetDocument(
                        new FilePath("/TestFiles/Input/test.txt"),
                        "x ^\"Subfolder/test-c.txt\" y")
                };
                Include include = new Include();

                // When
                List <IDocument> results = include.Execute(documents, Context).ToList();

                // Then
                Assert.AreEqual("x ccc y", results.Single().Content);
            }
コード例 #8
0
            public void FileNotFoundRemovesIncludeStatement()
            {
                // Given
                ThrowOnTraceEventType(System.Diagnostics.TraceEventType.Error);
                IDocument[] documents =
                {
                    Context.GetDocument(
                        new FilePath("/TestFiles/Input/test.txt"),
                        Context.GetContentStream("x ^\"test-c.txt\" y"))
                };
                Include include = new Include();

                // When
                List <IDocument> results = include.Execute(documents, Context).ToList();

                // Then
                Assert.AreEqual("x  y", results.Single().Content);
            }
コード例 #9
0
            public void IncludesFileRelativeToSource()
            {
                // Given
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/A");
                fileProvider.AddDirectory("/A/B");
                fileProvider.AddDirectory("/A/D");
                fileProvider.AddFile("/A/B/c.txt", "foo");
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };

                fileSystem.InputPaths.Clear();
                fileSystem.InputPaths.Add("/A");

                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument()
                {
                    Source = new FilePath("/A/D/x.txt")
                };

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>(null, "../B/c.txt")
                };
                Include shortcode = new Include();

                // When
                IShortcodeResult result = shortcode.Execute(args, string.Empty, document, context);

                // Then
                using (TextReader reader = new StreamReader(result.Stream))
                {
                    reader.ReadToEnd().ShouldBe("foo");
                }
            }
コード例 #10
0
            public void NestedIncludeWithInnerEscape()
            {
                // Given
                FileProvider.AddFile(
                    "/TestFiles/Input/test-outer.txt",
                    "3 \\^\"test-a.txt\" 4");
                IDocument[] documents =
                {
                    Context.GetDocument(
                        new FilePath("/TestFiles/Input/test.txt"),
                        Context.GetContentStream("1 ^\"test-outer.txt\" 2"))
                };
                Include include = new Include().WithRecursion(false);

                // When
                List <IDocument> results = include.Execute(documents, Context).ToList();

                // Then
                Assert.AreEqual("1 3 \\^\"test-a.txt\" 4 2", results.Single().Content);
            }
コード例 #11
0
ファイル: IncludeFixture.cs プロジェクト: schulz3000/Wyam
            public void NestedInclude()
            {
                // Given
                FileProvider.AddFile(
                    "/TestFiles/Input/test-outer.txt",
                    "3 ^\"test-a.txt\" 4");
                IDocument[] documents =
                {
                    Context.GetDocument(
                        new FilePath("/TestFiles/Input/test.txt"),
                        "1 ^\"test-outer.txt\" 2")
                };
                Include include = new Include();

                // When
                List <IDocument> results = include.Execute(documents, Context).ToList();

                // Then
                Assert.AreEqual("1 3 aaa 4 2", results.Single().Content);
            }
コード例 #12
0
            public void NullResultIfFileDoesNotExist()
            {
                // Given
                ThrowOnTraceEventType(System.Diagnostics.TraceEventType.Error);
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/A");
                fileProvider.AddDirectory("/A/B");
                fileProvider.AddFile("/A/B/c.txt", "foo");
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };

                fileSystem.InputPaths.Clear();
                fileSystem.InputPaths.Add("/A");

                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument();

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>(null, "B/d.txt")
                };
                Include shortcode = new Include();

                // When
                IShortcodeResult result = shortcode.Execute(args, string.Empty, document, context);

                // Then
                result.Stream.ShouldBeNull();
            }