Regular expression pattern that matches USON (or Uson, user string object notation).
Inheritance: Regex
Exemplo n.º 1
0
        public void WhenParsingContentValue_ThenRetrievesValueOnlyGroup()
        {
            var value = "foo";
            var match = new UsonPattern().Matches(value).OfType <Match>().FirstOrDefault();

            Assert.NotNull(match);
            Assert.False(match.Groups[UsonPattern.NameGroup].Success);
            Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
            Assert.Equal("foo", match.Groups[UsonPattern.ValueGroup].Value);
        }
Exemplo n.º 2
0
		public void WhenParsingContentValue_ThenRetrievesValueOnlyGroup()
		{
			var value = "foo";
			var match = new UsonPattern().Matches(value).OfType<Match>().FirstOrDefault();

			Assert.NotNull(match);
			Assert.False(match.Groups[UsonPattern.NameGroup].Success);
			Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
			Assert.Equal("foo", match.Groups[UsonPattern.ValueGroup].Value);
		}
Exemplo n.º 3
0
        public void WhenParsingMultiplePropertyValues_ThenRetrievesNameValueGroups()
        {
            var value   = "tag:wpf platform:vspro";
            var matches = new UsonPattern().Matches(value).OfType <Match>().ToList();

            Assert.Equal(2, matches.Count);
            Assert.Equal("tag", matches[0].Groups[UsonPattern.NameGroup].Value);
            Assert.Equal("wpf", matches[0].Groups[UsonPattern.ValueGroup].Value);
            Assert.Equal("platform", matches[1].Groups[UsonPattern.NameGroup].Value);
            Assert.Equal("vspro", matches[1].Groups[UsonPattern.ValueGroup].Value);
        }
Exemplo n.º 4
0
        public void WhenParsingSingleValueWithEquals_ThenRetrievesNameValueGroups()
        {
            var value = "tag=foo";
            var match = new UsonPattern().Matches(value).OfType <Match>().FirstOrDefault();

            Assert.NotNull(match);
            Assert.True(match.Groups[UsonPattern.NameGroup].Success);
            Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
            Assert.Equal("tag", match.Groups[UsonPattern.NameGroup].Value);
            Assert.Equal("foo", match.Groups[UsonPattern.ValueGroup].Value);
        }
Exemplo n.º 5
0
        public void WhenParsingQuotedTimespanValue_ThenRetrievesNameValueGroups()
        {
            var value = "timeout:\"10:00:00\"";
            var match = new UsonPattern().Matches(value).OfType <Match>().FirstOrDefault();

            Assert.NotNull(match);
            Assert.True(match.Groups[UsonPattern.NameGroup].Success);
            Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
            Assert.Equal("timeout", match.Groups[UsonPattern.NameGroup].Value);
            Assert.Equal("\"10:00:00\"", match.Groups[UsonPattern.ValueGroup].Value);
        }
Exemplo n.º 6
0
        public void WhenParsingSingleQuotedPropertyValue_ThenRetrievesNameValueGroups()
        {
            var value = "tag:'hello world'";
            var match = new UsonPattern().Matches(value).OfType <Match>().FirstOrDefault();

            Assert.NotNull(match);
            Assert.True(match.Groups[UsonPattern.NameGroup].Success);
            Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
            Assert.Equal("tag", match.Groups[UsonPattern.NameGroup].Value);
            Assert.Equal("'hello world'", match.Groups[UsonPattern.ValueGroup].Value);
        }
Exemplo n.º 7
0
		public void WhenParsingSingleValue_ThenRetrievesNameValueGroups()
		{
			var value = "tag:foo";
			var match = new UsonPattern().Matches(value).OfType<Match>().FirstOrDefault();

			Assert.NotNull(match);
			Assert.True(match.Groups[UsonPattern.NameGroup].Success);
			Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
			Assert.Equal("tag", match.Groups[UsonPattern.NameGroup].Value);
			Assert.Equal("foo", match.Groups[UsonPattern.ValueGroup].Value);
		}
Exemplo n.º 8
0
        public void WhenParsingQuotedContent_ThenRetrievesAsSingleValueOnlyMatch()
        {
            var value   = "\"hello world\"";
            var matches = new UsonPattern().Matches(value).OfType <Match>();
            var match   = matches.FirstOrDefault();

            Assert.Equal(1, matches.Count());
            Assert.NotNull(match);
            Assert.False(match.Groups[UsonPattern.NameGroup].Success);
            Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
            Assert.Equal("\"hello world\"", match.Groups[UsonPattern.ValueGroup].Value);
        }
Exemplo n.º 9
0
        public void WhenParsingSingleQuotedValueWithSpaces_ThenRetrievesFullValue()
        {
            //AnalysisConsole.exe Source:"C:\Data\Message1.txt" Source:"C:\Data\Message2.txt" Database:"Data Source=.\\SQLExpress;Initial Catalog=AnalysisDatabase;Integrated Security=True;" Assembly:"C:\Temp\MyQueries1.dll" Assembly:"C:\Temp\MyQueries2.dll"
            var value = "Database:'Data Source=.\\SQLExpress;Initial Catalog=AnalysisDatabase;Integrated Security=True;'";
            var match = new UsonPattern().Matches(value).OfType <Match>().FirstOrDefault();

            Assert.NotNull(match);
            Assert.True(match.Groups[UsonPattern.NameGroup].Success);
            Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
            Assert.Equal("Database", match.Groups[UsonPattern.NameGroup].Value);
            Assert.True(match.Groups[UsonPattern.ValueGroup].Value.Contains("Integrated Security"), "Failed to find 'Integrated Security' in " + match.Groups[UsonPattern.ValueGroup].Value);
        }
Exemplo n.º 10
0
		public void WhenParsingQuotedContent_ThenRetrievesAsSingleValueOnlyMatch()
		{
			var value = "\"hello world\"";
			var matches = new UsonPattern().Matches(value).OfType<Match>();
			var match = matches.FirstOrDefault();

			Assert.Equal(1, matches.Count());
			Assert.NotNull(match);
			Assert.False(match.Groups[UsonPattern.NameGroup].Success);
			Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
			Assert.Equal("\"hello world\"", match.Groups[UsonPattern.ValueGroup].Value);
		}
Exemplo n.º 11
0
        public PropertyMatch(Match match)
        {
            this.IsDefault = !match.Groups[Regex.NameGroup].Success;
            this.Name      = match.Groups[Regex.NameGroup].Value;
            this.Path      = "";
            this.Value     = Regex.Unquote(match.Groups[Regex.ValueGroup].Value);

            if (this.Name.Contains('.'))
            {
                var paths = this.Name.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

                this.Path = string.Join(".", paths.Take(paths.Length - 1));
                this.Name = this.Name.Replace(this.Path, "");
            }

            if (this.Name.StartsWith("."))
            {
                this.Name = this.Name.Substring(1);
            }
        }
Exemplo n.º 12
0
		public void WhenParsingDoubleQuotedPropertyValue_ThenRetrievesNameValueGroups()
		{
			var value = "tag:\"hello world\"";
			var match = new UsonPattern().Matches(value).OfType<Match>().FirstOrDefault();

			Assert.NotNull(match);
			Assert.True(match.Groups[UsonPattern.NameGroup].Success);
			Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
			Assert.Equal("tag", match.Groups[UsonPattern.NameGroup].Value);
			Assert.Equal("\"hello world\"", match.Groups[UsonPattern.ValueGroup].Value);
		}
Exemplo n.º 13
0
        public void WhenUnquotingContent_ThenPreservesMiddleQuotes()
        {
            var value = "\"Joe's house\"";

            Assert.Equal("Joe's house", UsonPattern.Unquote(value));
        }
Exemplo n.º 14
0
        public void WhenUnquotingContent_ThenRemovesSingleQuotes()
        {
            var value = "'hello world'";

            Assert.Equal("hello world", UsonPattern.Unquote(value));
        }
Exemplo n.º 15
0
        public void WhenUnquotingStartQuoteOnly_ThenReturnsEmpty()
        {
            var value = "\"";

            Assert.Equal("", UsonPattern.Unquote(value));
        }
Exemplo n.º 16
0
        public void WhenUnquotingUnbalanced_ThenRemovesStartingQuote()
        {
            var value = "\"hello";

            Assert.Equal("hello", UsonPattern.Unquote(value));
        }
Exemplo n.º 17
0
        public void WhenUnquotingEmptyContent_ThenReturnsEmpty()
        {
            var value = "";

            Assert.Equal("", UsonPattern.Unquote(value));
        }
Exemplo n.º 18
0
		public void WhenParsingMultiplePropertyValues_ThenRetrievesNameValueGroups()
		{
			var value = "tag:wpf platform:vspro";
			var matches = new UsonPattern().Matches(value).OfType<Match>().ToList();

			Assert.Equal(2, matches.Count);
			Assert.Equal("tag", matches[0].Groups[UsonPattern.NameGroup].Value);
			Assert.Equal("wpf", matches[0].Groups[UsonPattern.ValueGroup].Value);
			Assert.Equal("platform", matches[1].Groups[UsonPattern.NameGroup].Value);
			Assert.Equal("vspro", matches[1].Groups[UsonPattern.ValueGroup].Value);
		}
Exemplo n.º 19
0
		public void WhenParsingQuotedTimespanValue_ThenRetrievesNameValueGroups()
		{
			var value = "timeout:\"10:00:00\"";
			var match = new UsonPattern().Matches(value).OfType<Match>().FirstOrDefault();

			Assert.NotNull(match);
			Assert.True(match.Groups[UsonPattern.NameGroup].Success);
			Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
			Assert.Equal("timeout", match.Groups[UsonPattern.NameGroup].Value);
			Assert.Equal("\"10:00:00\"", match.Groups[UsonPattern.ValueGroup].Value);
		}
Exemplo n.º 20
0
		public void WhenParsingSingleQuotedValueWithSpaces_ThenRetrievesFullValue()
		{
			//AnalysisConsole.exe Source:"C:\Data\Message1.txt" Source:"C:\Data\Message2.txt" Database:"Data Source=.\\SQLExpress;Initial Catalog=AnalysisDatabase;Integrated Security=True;" Assembly:"C:\Temp\MyQueries1.dll" Assembly:"C:\Temp\MyQueries2.dll"
			var value = "Database:'Data Source=.\\SQLExpress;Initial Catalog=AnalysisDatabase;Integrated Security=True;'";
			var match = new UsonPattern().Matches(value).OfType<Match>().FirstOrDefault();

			Assert.NotNull(match);
			Assert.True(match.Groups[UsonPattern.NameGroup].Success);
			Assert.True(match.Groups[UsonPattern.ValueGroup].Success);
			Assert.Equal("Database", match.Groups[UsonPattern.NameGroup].Value);
			Assert.True(match.Groups[UsonPattern.ValueGroup].Value.Contains("Integrated Security"), "Failed to find 'Integrated Security' in " + match.Groups[UsonPattern.ValueGroup].Value);
		}