コード例 #1
0
 public ParserTests()
 {
     _provider = new NamedShortcodeProvider
     {
         ["hello"]            = (args, content) => new ValueTask <string>("Hello world!"),
         ["named_or_default"] = (args, content) => new ValueTask <string>("Hello " + args.NamedOrDefault("name")),
     };
 }
コード例 #2
0
        public RenderBenchmarks()
        {
            _provider = new NamedShortcodeProvider
            {
                ["upper"] = (args, content, ctx) => new ValueTask <string>(content.ToUpperInvariant()),
            };

            _processor = new ShortcodesProcessor(_provider);
        }
コード例 #3
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]");
        }
コード例 #4
0
        public ParserTests()
        {
            _provider = new NamedShortcodeProvider
            {
                ["hello"]            = (args, content, ctx) => new ValueTask <string>("Hello world!"),
                ["named_or_default"] = (args, content, ctx) => new ValueTask <string>("Hello " + args.NamedOrDefault("name")),
                ["upper"]            = (args, content, ctx) => new ValueTask <string>(content.ToUpperInvariant()),
                ["positional"]       = (args, content, ctx) =>
                {
                    string result = "";

                    for (var i = 0; i < args.Count; i++)
                    {
                        result += $"{i}:{args.At(i)};";
                    }

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