Example #1
0
		/// <summary>
		/// Creates a document <see cref="Block"/> from the given template.
		/// </summary>
		/// <param name="template">The template.</param>
		/// <returns>The document <see cref="Block"/></returns>
		private Block CreateDocument(string template)
		{
			using (var reader = new StringReader(template))
			{
				using (var source = new SeekableTextReader(reader))
				{
					var errors = new ParserErrorSink();
					var parser = new HandlebarsParser();

					var context = new ParserContext(source, parser, errors, TagProviders);
					parser.Context = context;

					parser.ParseDocument();
					var results = context.CompleteParse();

					if (results.Success)
					{
						return results.Document;
					}

					throw new InvalidOperationException(
						string.Join("\n", results.Errors.Select(e => string.Format("{0}: {1}", e.Location, e.Message))));
				}
			}
		}
		private void ParserTest(string content, Block document, TagProvidersCollection providers = null)
		{
			providers = providers ?? TagProvidersCollection.Default;

			var output = new StringBuilder();
			using (var reader = new StringReader(content))
			{
				using (var source = new SeekableTextReader(reader))
				{
					var errors = new ParserErrorSink();
					var parser = new HandlebarsParser();

					var context = new ParserContext(source, parser, errors, providers);
					parser.Context = context;

					parser.ParseDocument();

					var results = context.CompleteParse();

					var comparer = new EquivalanceComparer(output, 0);

					Assert.True(comparer.Equals(document, results.Document), output.ToString());
				}
			}
		}