コード例 #1
0
        public async Task ContextIsShareAcrossShortcodes()
        {
            var parser = new ShortcodesProcessor(new NamedShortcodeProvider
            {
                ["inc"] = (args, content, ctx) => { ctx["x"] = ctx.GetOrSetValue("x", 0) + 1; return(new ValueTask <string>(ctx["x"].ToString())); },
                ["val"] = (args, content, ctx) => new ValueTask <string>(ctx["x"].ToString())
            });

            Assert.Equal("122", await parser.EvaluateAsync($"[inc][inc][val]"));
        }
コード例 #2
0
        public async Task ShouldUseContextValue()
        {
            var parser = new ShortcodesProcessor(new NamedShortcodeProvider
            {
                ["hello"] = (args, content, ctx) => { return(new ValueTask <string>("message: " + ctx["message"].ToString())); }
            });

            Assert.Equal("message: Hello World!", await parser.EvaluateAsync($"[hello]", new Context {
                ["message"] = "Hello World!"
            }));
        }
コード例 #3
0
        public ValueTask <string> ProcessAsync(string input, Context context = null)
        {
            if (context == null)
            {
                context = new Context();
            }

            foreach (var contextProvider in _shortcodeContextProviders)
            {
                contextProvider.Contextualize(context);
            }

            return(_shortcodesProcessor.EvaluateAsync(input, context));
        }
コード例 #4
0
        public async Task PositionalArgumentMixedWithNamedArguments()
        {
            var provider = new NamedShortcodeProvider
            {
                ["hello"] = (args, content, ctx) =>
                {
                    Assert.Equal("1", args.At(0));
                    Assert.Equal("b", args.At(1));
                    Assert.Equal("d", args.Named("c"));
                    Assert.Equal("123", args.At(2));

                    return(new ValueTask <string>(""));
                }
            };

            var parser = new ShortcodesProcessor(_provider);
            await parser.EvaluateAsync("[hello 1 b c=d 123]");
        }
コード例 #5
0
        public async Task ProcessClosingShortcodes(string input, string expected)
        {
            var parser = new ShortcodesProcessor(_provider);

            Assert.Equal(expected, await parser.EvaluateAsync(input));
        }
コード例 #6
0
        public async Task DoesntProcessInputsWithoutBrackets(string input)
        {
            var parser = new ShortcodesProcessor();

            Assert.Same(input, await parser.EvaluateAsync(input));
        }
コード例 #7
0
        public async Task ValuesAreParsed(string input)
        {
            var parser = new ShortcodesProcessor(_provider);

            Assert.Equal($"0:{input};", await parser.EvaluateAsync($"[positional {input}]"));
        }
コード例 #8
0
        public async Task ArgumentsAreCaseInsensitive(string input, string expected)
        {
            var parser = new ShortcodesProcessor(_provider);

            Assert.Equal(expected, await parser.EvaluateAsync(input));
        }
コード例 #9
0
        public async Task NamedOrDefaultArguments(string input, string expected)
        {
            var parser = new ShortcodesProcessor(_provider);

            Assert.Equal(expected, await parser.EvaluateAsync(input));
        }
コード例 #10
0
 public ValueTask <string> Nop() => _processor.EvaluateAsync("Lorem ipsum dolor est");