Exemplo n.º 1
0
        public void DashStringDoesNotSplitAtNonmatchingDashes()
        {
            // Given
            Engine engine = new Engine();
            Metadata metadata = new Metadata(engine);
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(metadata).Clone(@"FM1
            FM2
            ---
            Content1
            Content2") };
            bool executed = false;
            FrontMatter frontMatter = new FrontMatter("-", new Execute(x =>
            {
                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 DefaultCtorSplitsAtDashes()
        {
            // Given
            Engine engine = new Engine();
            Metadata metadata = new Metadata(engine);
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(metadata).Clone(@"FM1
            FM2
            ---
            Content1
            Content2") };
            string frontMatterContent = null;
            FrontMatter frontMatter = new FrontMatter(new Execute(x =>
            {
                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);
        }
        public WorkMetadataYamlUnpacker(string key, bool flatten, params IModule[] modules)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            if (modules == null)
            {
                throw new ArgumentNullException("metadataModules");
            }

            _key = key;
            _flatten = flatten;
            var test2 = new FrontMatter(new Yaml(_key, _flatten));
            var test = new IModule[] { test2, };
            _modules = modules.Length == 0 ? new IModule[] { new FrontMatter(new Yaml(_key, _flatten)), } : modules;
        }
Exemplo n.º 4
0
        public void SingleCharWithRepeatedDelimiterWithTrailingSpacesSplitsAtCorrectLocation()
        {
            // Given
            Engine engine = new Engine();
            Metadata metadata = new Metadata(engine);
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(metadata).Clone(@"FM1
            FM2
            !!!!
            Content1
            Content2") };
            string frontMatterContent = null;
            FrontMatter frontMatter = new FrontMatter('!', new Execute(x =>
            {
                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();
            Metadata metadata = new Metadata(engine);
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(metadata).Clone(@"FM1
            FM2
              !!!!
            Content1
            Content2") };
            bool executed = false;
            FrontMatter frontMatter = new FrontMatter('!', new Execute(x =>
            {
                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();
            Metadata metadata = new Metadata(engine);
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(metadata).Clone(@"AA
            -
            XX"), new Document(metadata).Clone(@"BB
            -
            YY") };
            string frontMatterContent = string.Empty;
            FrontMatter frontMatter = new FrontMatter(new Execute(x =>
            {
                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 MatchingStringSplitsAtCorrectLocation()
        {
            // 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
            ABC
            Content1
            Content2") };
            string frontMatterContent = null;
            FrontMatter frontMatter = new FrontMatter("ABC", 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);
        }