Example #1
0
        public void UnQuotedValuePatternTest()
        {
            Regex regex = new Regex("^" + Pattern.UnQuotedValuePattern + "$");

            HelperFunction.ShouldMatch(regex, "roger123");
            HelperFunction.ShouldMatch(regex, "_hello");
            HelperFunction.ShouldMatch(regex, "funky_chicken");
            HelperFunction.ShouldMatch(regex, "_1_2_3");
            HelperFunction.ShouldMatch(regex, "Te.St.5_4");
            HelperFunction.ShouldMatch(regex, "\\");
            HelperFunction.ShouldMatch(regex, "C:\\Test");
            HelperFunction.ShouldMatch(regex, "C:\\Test\\");
            HelperFunction.ShouldMatch(regex, "\\\\Domain\\host");
            HelperFunction.ShouldMatch(regex, "Test\\ Directory");
            HelperFunction.ShouldMatch(regex, "@\\\\Domain\\host");
            HelperFunction.ShouldMatch(regex, "@Test\\ Directory");
            HelperFunction.ShouldNotMatch(regex, String.Empty);
            HelperFunction.ShouldNotMatch(regex, " ");
            HelperFunction.ShouldNotMatch(regex, "' '");
            HelperFunction.ShouldNotMatch(regex, "\" \"");
            HelperFunction.ShouldNotMatch(regex, "\\ .ab'");
            HelperFunction.ShouldNotMatch(regex, " ");
            HelperFunction.ShouldNotMatch(regex, "roger ");
            HelperFunction.ShouldNotMatch(regex, " roger");
            HelperFunction.ShouldNotMatch(regex, " roger ");
        }
Example #2
0
        public void StartOfNamePatternTest()
        {
            Regex regex = new Regex("^" + Pattern.StartOfNamedParamPattern + "$");

            HelperFunction.ShouldMatch(regex, "-");
            HelperFunction.ShouldMatch(regex, "--");
            HelperFunction.ShouldMatch(regex, "/");
        }
Example #3
0
        public void MatchProgramWithNoArguments()
        {
            string commandline = HelperFunction.MakeCommandLine(String.Empty);
            Match  match       = this.Regex.Match(commandline);

            HelperFunction.ValidateApplication(match);
            HelperFunction.ValidateArguments(match, 0);
        }
Example #4
0
        public void MatchProgramName()
        {
            string commandline = HelperFunction.MakeCommandLine(String.Empty);

            Regex programName = new Regex(this.ApplicationRegex);
            Match match       = programName.Match(commandline);

            HelperFunction.ValidateApplication(match);
        }
Example #5
0
        public void MatchSingleArgument_01()
        {
            string commandline = HelperFunction.MakeCommandLine("-a=b");
            Match  match       = this.Regex.Match(commandline);

            HelperFunction.ValidateApplication(match);
            HelperFunction.ValidateArguments(match, 1);
            HelperFunction.ValidateParameter(match, 0, "a", "b");
        }
Example #6
0
        public void NameValueSeparatorPatternTest()
        {
            Regex regex = new Regex("^" + Pattern.NameValueSeparatorPattern + "$");

            HelperFunction.ShouldMatch(regex, ":");
            HelperFunction.ShouldMatch(regex, " ");
            HelperFunction.ShouldMatch(regex, "   ");
            HelperFunction.ShouldMatch(regex, "=");
        }
Example #7
0
        public void MatchNestedString_02()
        {
            string commandline = HelperFunction.MakeCommandLine("--a \"'b c'\"");
            Match  match       = this.Regex.Match(commandline);

            HelperFunction.ValidateApplication(match);
            HelperFunction.ValidateArguments(match, 1);
            HelperFunction.ValidateParameter(match, 0, "a", "\"'b c'\"");
        }
Example #8
0
        public void MatchSingleSwitch_03()
        {
            string commandline = HelperFunction.MakeCommandLine("/a");
            Match  match       = this.Regex.Match(commandline);

            HelperFunction.ValidateApplication(match);
            HelperFunction.ValidateArguments(match, 1);
            HelperFunction.ValidateParameter(match, 0, "a", String.Empty);
        }
Example #9
0
        public void MatchMixed_02()
        {
            string commandline = HelperFunction.MakeCommandLine("--a /b:\"'1 2'\"");
            Match  match       = this.Regex.Match(commandline);

            HelperFunction.ValidateApplication(match);
            HelperFunction.ValidateArguments(match, 2);
            HelperFunction.ValidateParameter(match, 0, "a", String.Empty);
            HelperFunction.ValidateParameter(match, 1, "b", "\"'1 2'\"");
        }
Example #10
0
        public void MatchSwitch_03()
        {
            string arguments = "/a";

            Regex argument = new Regex(this.ParameterRegex);
            Match match    = argument.Match(arguments);

            HelperFunction.ValidateArguments(match, 1);
            HelperFunction.ValidateParameter(match, 0, "a", String.Empty);
        }
Example #11
0
        public void MatchParameter_09()
        {
            string arguments = "/a=b";

            Regex argument = new Regex(this.ParameterRegex);
            Match match    = argument.Match(arguments);

            HelperFunction.ValidateArguments(match, 1);
            HelperFunction.ValidateParameter(match, 0, "a", "b");
        }
Example #12
0
        public void MatchMultiArgument_03()
        {
            string commandline = HelperFunction.MakeCommandLine("/a='1 2' -b:\"3 4\" --c test");
            Match  match       = this.Regex.Match(commandline);

            HelperFunction.ValidateApplication(match);
            HelperFunction.ValidateArguments(match, 3);
            HelperFunction.ValidateParameter(match, 0, "a", "'1 2'");
            HelperFunction.ValidateParameter(match, 1, "b", "\"3 4\"");
            HelperFunction.ValidateParameter(match, 2, "c", "test");
        }
Example #13
0
        public void MatchMultiSwitch_03()
        {
            string commandline = HelperFunction.MakeCommandLine("--a -b /c");
            Match  match       = this.Regex.Match(commandline);

            HelperFunction.ValidateApplication(match);
            HelperFunction.ValidateArguments(match, 3);
            HelperFunction.ValidateParameter(match, 0, "a", String.Empty);
            HelperFunction.ValidateParameter(match, 1, "b", String.Empty);
            HelperFunction.ValidateParameter(match, 2, "c", String.Empty);
        }
Example #14
0
        public void BooleanPropertyTest_04()
        {
            string      text = HelperFunction.MakeCommandLine("--Bp:'Yes'");
            CommandLine c    = new CommandLine(text);

            Assertion.Assert(
                "The command line text failed to parse",
                c.TextIsValid);

            c.Bind(this);
            c.Resolve();
            Assertion.Assert(this.BooleanProperty);
        }
Example #15
0
        public void BooleanFieldTest_03()
        {
            string      text = HelperFunction.MakeCommandLine("-booleanField='True'");
            CommandLine c    = new CommandLine(text);

            Assertion.Assert(
                "The command line text failed to parse",
                c.TextIsValid);

            c.Bind(this);
            c.Resolve();
            Assertion.Assert(this.BooleanField);
        }
Example #16
0
        public void DefaultBooleanPropertyTest()
        {
            string      text = HelperFunction.MakeCommandLine("--someName:'SomeValue'");
            CommandLine c    = new CommandLine(text);

            Assertion.Assert(
                "The command line text failed to parse",
                c.TextIsValid);

            c.Bind(this);
            c.Resolve();
            Assertion.Assert(this.DefaultBooleanProperty);
        }
Example #17
0
        public void ProgramNameText()
        {
            string text = HelperFunction.MakeCommandLine(String.Empty);

            CommandLine c = new CommandLine(text);

            Assertion.Assert(
                "The command line text failed to parse",
                c.TextIsValid);

            Assertion.Assert(
                "The program name is incorrect",
                c.ProgramName == HelperFunction.ApplicationName);
        }
Example #18
0
        public void DoubleQuotedValuePatternTest()
        {
            Regex regex = new Regex("^" + Pattern.DoubleQuotedValuePattern + "$");

            HelperFunction.ShouldMatch(regex, "\"roger\"");
            HelperFunction.ShouldMatch(regex, "\"_hello\"");
            HelperFunction.ShouldMatch(regex, "\" test test\"");
            HelperFunction.ShouldMatch(regex, "\" foo\\ bar\"");
            HelperFunction.ShouldMatch(regex, "\" foo' bar\"");
            HelperFunction.ShouldMatch(regex, "@\" foo\\ bar\"");
            HelperFunction.ShouldMatch(regex, "@\" foo' bar\"");
            HelperFunction.ShouldNotMatch(regex, "roger");
            HelperFunction.ShouldNotMatch(regex, "_hello");
            HelperFunction.ShouldNotMatch(regex, "' test test");
            HelperFunction.ShouldNotMatch(regex, "' foo\\ bar' '");
        }
Example #19
0
        public void SingleQuotedValuePatternTest()
        {
            Regex regex = new Regex("^" + Pattern.SingleQuotedValuePattern + "$");

            HelperFunction.ShouldMatch(regex, "'roger'");
            HelperFunction.ShouldMatch(regex, "'_hello'");
            HelperFunction.ShouldMatch(regex, "' test test'");
            HelperFunction.ShouldMatch(regex, "' foo\\ bar'");
            HelperFunction.ShouldMatch(regex, "' foo\" bar'");
            HelperFunction.ShouldMatch(regex, "@' foo\\ bar'");
            HelperFunction.ShouldMatch(regex, "@' foo\" bar'");
            HelperFunction.ShouldNotMatch(regex, "roger");
            HelperFunction.ShouldNotMatch(regex, "_hello");
            HelperFunction.ShouldNotMatch(regex, "' test test");
            HelperFunction.ShouldNotMatch(regex, "' foo\\ bar' '");
        }
Example #20
0
        /// <summary>
        /// Test the NamePattern
        /// </summary>
        public void NamePatternTest()
        {
            Regex regex = new Regex("^" + Pattern.NamePattern + "$");

            HelperFunction.ShouldMatch(regex, "roger123");
            HelperFunction.ShouldMatch(regex, "_hello");
            HelperFunction.ShouldMatch(regex, "funky_chicken");
            HelperFunction.ShouldMatch(regex, "_1_2_3");
            HelperFunction.ShouldMatch(regex, "Te.St.5_4");
            HelperFunction.ShouldNotMatch(regex, ".ab");
            HelperFunction.ShouldNotMatch(regex, ".ab");
            HelperFunction.ShouldNotMatch(regex, " ");
            HelperFunction.ShouldNotMatch(regex, "roger ");
            HelperFunction.ShouldNotMatch(regex, " roger");
            HelperFunction.ShouldNotMatch(regex, " roger ");
        }
Example #21
0
        public void EnumFieldTest_01()
        {
            string      text = HelperFunction.MakeCommandLine("--enumField:'value1'");
            CommandLine c    = new CommandLine(text);

            Assertion.Assert(
                "The command line text failed to parse",
                c.TextIsValid);

            c.Bind(this);
            c.Resolve();
            Assertion.AssertEquals(
                "Wrong enumeration value observed",
                Enumeration.Value1,
                this.enumField);
        }
Example #22
0
        public void EnumPropertyTest_02()
        {
            string      text = HelperFunction.MakeCommandLine("--ep:\"vALUe4\"");
            CommandLine c    = new CommandLine(text);

            Assertion.Assert(
                "The command line text failed to parse",
                c.TextIsValid);

            c.Bind(this);
            c.Resolve();
            Assertion.AssertEquals(
                "Wrong enumeration value observed",
                Enumeration.Value4,
                this.enumProperty);
        }
Example #23
0
        public void ValuePatternTest()
        {
            Regex regex = new Regex("^" + Pattern.ValuePattern + "$");

            // Not quotes
            HelperFunction.ShouldMatch(regex, "roger123");
            HelperFunction.ShouldMatch(regex, "_hello");
            HelperFunction.ShouldMatch(regex, "funky_chicken");
            HelperFunction.ShouldMatch(regex, "_1_2_3");
            HelperFunction.ShouldMatch(regex, "Te.St.5_4");
            HelperFunction.ShouldMatch(regex, "\\");
            HelperFunction.ShouldMatch(regex, "C:\\Test");
            HelperFunction.ShouldMatch(regex, "C:\\Test\\");
            HelperFunction.ShouldMatch(regex, "\\\\Domain\\host");
            HelperFunction.ShouldMatch(regex, "Test\\ Directory");

            // Single quotes
            HelperFunction.ShouldMatch(regex, "'roger'");
            HelperFunction.ShouldMatch(regex, "'_hello'");
            HelperFunction.ShouldMatch(regex, "' test test'");
            HelperFunction.ShouldMatch(regex, "' foo\\ bar'");
            HelperFunction.ShouldMatch(regex, "' foo\" bar'");
            HelperFunction.ShouldMatch(regex, "@' foo\\ bar'");
            HelperFunction.ShouldMatch(regex, "@' foo\" bar'");

            // Double quotes
            HelperFunction.ShouldMatch(regex, "\"roger\"");
            HelperFunction.ShouldMatch(regex, "\"_hello\"");
            HelperFunction.ShouldMatch(regex, "\" test test\"");
            HelperFunction.ShouldMatch(regex, "\" foo\\ bar\"");
            HelperFunction.ShouldMatch(regex, "\" foo' bar\"");
            HelperFunction.ShouldMatch(regex, "@\" foo\\ bar\"");
            HelperFunction.ShouldMatch(regex, "@\" foo' bar\"");

            // Mismatches
            HelperFunction.ShouldNotMatch(regex, "\\ .ab'");
        }
Example #24
0
 public void ComplainOnStrange_01()
 {
     Assertion.Assert(!this.Regex.IsMatch(
                          HelperFunction.MakeCommandLine("/a='1'extra")));
 }