Exemplo n.º 1
0
            public void DashStringDoesNotSplitAtNonmatchingDashes()
            {
                // Given
                Engine engine = new Engine();
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs =
                {
                    context.GetDocument(@"FM1
                FM2
                ---
                Content1
                Content2")
                };
                bool executed = false;
                FrontMatter frontMatter = new FrontMatter("-", new Execute((x, ctx) =>
                {
                    executed = true;
                    return new[] {x};
                }));

                // When
                IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

                // Then
                Assert.AreEqual(1, documents.Count());
                Assert.IsFalse(executed);
                Assert.AreEqual(@"FM1
                FM2
                ---
                Content1
                Content2", documents.First().Content);
            }
Exemplo n.º 2
0
            public void DefaultCtorIgnoresDelimiterOnFirstLine()
            {
                // Given
                Engine engine = new Engine();
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs =
                {
                    context.GetDocument(@"---
                FM1
                FM2
                ---
                Content1
                Content2")
                };
                string frontMatterContent = null;
                FrontMatter frontMatter = new FrontMatter(new Execute((x, ctx) =>
                {
                    frontMatterContent = x.Content;
                    return new[] {x};
                }));

                // When
                IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

                // Then
                Assert.AreEqual(1, documents.Count());
                Assert.AreEqual(@"FM1
                FM2
                ", frontMatterContent);
                Assert.AreEqual(@"Content1
                Content2", documents.First().Content);
            }
Exemplo n.º 3
0
        public void DefaultCtorSplitsAtDashes()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(engine, pipeline).Clone(@"FM1
FM2
---
Content1
Content2") };
            string frontMatterContent = null;
            FrontMatter frontMatter = new FrontMatter(new Execute((x, ctx) =>
            {
                frontMatterContent = x.Content;
                return new [] {x};
            }));

            // When
            IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

            // Then
            Assert.AreEqual(1, documents.Count());
            Assert.AreEqual(@"FM1
FM2
", frontMatterContent);
            Assert.AreEqual(@"Content1
Content2", documents.First().Content);
        }
Exemplo n.º 4
0
            public void SingleCharWithSingleDelimiterSplitsAtCorrectLocation()
            {
                // Given
                Engine engine = new Engine();
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs =
                {
                    context.GetDocument(@"FM1
                FM2
                !
                Content1
                Content2")
                };
                string frontMatterContent = null;
                FrontMatter frontMatter = new FrontMatter('!', new Execute((x, ctx) =>
                {
                    frontMatterContent = x.Content;
                    return new[] {x};
                }));

                // When
                IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

                // Then
                Assert.AreEqual(1, documents.Count());
                Assert.AreEqual(@"FM1
                FM2
                ", frontMatterContent);
                Assert.AreEqual(@"Content1
                Content2", documents.First().Content);
            }
Exemplo n.º 5
0
            public void SingleCharWithRepeatedDelimiterWithLeadingSpacesDoesNotSplit()
            {
                // Given
                Engine engine = new Engine();
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs =
                {
                    context.GetDocument(@"FM1
                FM2
                  !!!!
                Content1
                Content2")
                };
                bool executed = false;
                FrontMatter frontMatter = new FrontMatter('!', new Execute((x, ctx) =>
                {
                    executed = true;
                    return new[] {x};
                }));

                // When
                IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

                // Then
                Assert.AreEqual(1, documents.Count());
                Assert.IsFalse(executed);
                Assert.AreEqual(@"FM1
                FM2
                  !!!!
                Content1
                Content2", documents.First().Content);
            }
Exemplo n.º 6
0
            public void MultipleInputDocumentsResultsInMultipleOutputs()
            {
                // Given
                Engine engine = new Engine();
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs =
                {
                    context.GetDocument(@"AA
                -
                XX"),
                    context.GetDocument(@"BB
                -
                YY")
                };
                string frontMatterContent = string.Empty;
                FrontMatter frontMatter = new FrontMatter(new Execute((x, ctx) =>
                {
                    frontMatterContent += x.Content;
                    return new[] {x};
                }));

                // When
                IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

                // Then
                Assert.AreEqual(2, documents.Count());
                Assert.AreEqual(@"AA
                BB
                ", frontMatterContent);
                Assert.AreEqual(@"XX", documents.First().Content);
                Assert.AreEqual(@"YY", documents.Skip(1).First().Content);
            }
Exemplo n.º 7
0
        public void SingleCharWithRepeatedDelimiterWithExtraLinesSplitsAtCorrectLocation()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(engine, pipeline).Clone(@"FM1
FM2

!!!!

Content1
Content2") };
            string frontMatterContent = null;
            FrontMatter frontMatter = new FrontMatter('!', new Execute((x, ctx) =>
            {
                frontMatterContent = x.Content;
                return new[] { x };
            }));

            // When
            IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

            // Then
            Assert.AreEqual(1, documents.Count());
            Assert.AreEqual(@"FM1
FM2

", frontMatterContent);
            Assert.AreEqual(@"
Content1
Content2", documents.First().Content);
        }