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]")); }
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!" })); }
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)); }
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]"); }
public async Task ProcessClosingShortcodes(string input, string expected) { var parser = new ShortcodesProcessor(_provider); Assert.Equal(expected, await parser.EvaluateAsync(input)); }
public async Task DoesntProcessInputsWithoutBrackets(string input) { var parser = new ShortcodesProcessor(); Assert.Same(input, await parser.EvaluateAsync(input)); }
public async Task ValuesAreParsed(string input) { var parser = new ShortcodesProcessor(_provider); Assert.Equal($"0:{input};", await parser.EvaluateAsync($"[positional {input}]")); }
public async Task ArgumentsAreCaseInsensitive(string input, string expected) { var parser = new ShortcodesProcessor(_provider); Assert.Equal(expected, await parser.EvaluateAsync(input)); }
public async Task NamedOrDefaultArguments(string input, string expected) { var parser = new ShortcodesProcessor(_provider); Assert.Equal(expected, await parser.EvaluateAsync(input)); }
public ValueTask <string> Nop() => _processor.EvaluateAsync("Lorem ipsum dolor est");