public static CachedTemplate Parse(string input, bool bypass = false) { Guard.NotNull(input); CachedTemplate result; if (!bypass) { LockObject.EnterWriteLock(); try { if (Cache.TryGetValue(input, out result)) { return(result); } } finally { LockObject.ExitWriteLock(); } } Parser.TryParse(input, out var template, out var errorMessage); var error = TemplateError.Parse(errorMessage); result = new CachedTemplate(template, error); if (!bypass) { LockObject.EnterWriteLock(); try { Cache.Set(input, result); } finally { LockObject.ExitWriteLock(); } } return(result); }
public void Should_parse_with_open_line_numbers() { var result = TemplateError.Parse("Error Message at (10:20"); Assert.Equal(new TemplateError("Error Message at (10:20."), result); }
public void Should_parse_with_invalid_line_numbers() { var result = TemplateError.Parse("Error Message at (Test Value)"); Assert.Equal(new TemplateError("Error Message."), result); }
public void Should_parse_without_line_numbers() { var result = TemplateError.Parse("Error Message"); Assert.Equal(new TemplateError("Error Message."), result); }
public void Should_extract_line_number_only() { var result = TemplateError.Parse("Error at (10)"); Assert.Equal(new TemplateError("Error.", 10), result); }
public void Should_return_null_on_parse_when_message_is_empty() { var result = TemplateError.Parse(string.Empty); Assert.Null(result); }