Пример #1
0
		public void TestParser()
		{
			var parser = new Parser(ErrorAction.ThrowError);
			parser.AddAlphanumericSelectors();
			parser.AddAdditionalSelectorChars("_");
			parser.AddOperators(".");

			var formats = new[]{
				" aaa {bbb.ccc: ddd {eee} fff } ggg ",
				"{aaa} {bbb}",
				"{}",
				"{a:{b:{c:{d} } } }",
				"{a}",
				" aaa {bbb_bbb.CCC} ddd ",
			};
			var results = formats.Select(f => new { format = f, parsed = parser.ParseFormat(f) }).ToArray();

			// Verify that the reconstructed formats
			// match the original ones:

			results.TryAll(r => Assert.AreEqual(r.format, r.parsed.ToString())).ThrowIfNotEmpty();
		}
Пример #2
0
		public void Parser_Ignores_Exceptions()
		{
			var parser = new Parser(ErrorAction.Ignore);
			var invalidFormats = new[] {
				"{",
				"{0",
				"}",
				"0}",
				"{{{",
				"}}}",
				"{.}",
				"{.:}",
				"{..}",
				"{..:}",
				"{0.}",
				"{0.:}",
			};
			foreach (var format in invalidFormats)
			{
				var discard = parser.ParseFormat(format);
			}
		}
Пример #3
0
		private static Parser GetRegularParser()
		{
			var parser = new Parser(ErrorAction.ThrowError);
			parser.AddAlphanumericSelectors();
			parser.AddOperators(".");
			return parser;
		}