Beispiel #1
0
        private void Generate(StringBuilder builder, State state)
        {
            var transitions = state.GetSortedTransitions(true);

            if (transitions.Count == 0)
            {
                if (!state.Accept)
                {
                    throw new InvalidOperationException("state");
                }

                return;
            }

            int nroptions = state.Accept ? transitions.Count : transitions.Count - 1;
            int option    = Xeger.GetRandomInt(0, nroptions, random);

            if (state.Accept && option == 0)
            {
                // 0 is considered stop.
                return;
            }

            // Moving on to next transition.
            Transition transition = transitions[option - (state.Accept ? 1 : 0)];

            this.AppendChoice(builder, transition);
            Generate(builder, transition.To);
        }
Beispiel #2
0
        public void XegerIssue1()
        {
            var x = new Fare.Xeger(".*");

            // loops
            //x = new Fare.Xeger(".*.*");
            //var x = new Fare.Xeger(".*:.*");
        }
Beispiel #3
0
 private static void Produce(string regex)
 {
     var xeger = new Xeger(regex);
     while (true)
     {
         var sb = new StringBuilder();
         for (int i = 0; i < 1000; ++i)
             sb.AppendLine(xeger.Generate());
         Console.Write(sb.ToString());
     }
 }
        public void Test_Tokenization()
        {
            // see: https://github.com/moodmosaic/Fare
            // and: http://stackoverflow.com/questions/33931059/generate-a-random-string-with-regex
            var xeger = new Xeger(@"((a|t){1,5}\[(t|rt)(,(t|rt)){0,10}\](a|t){1,5}){10,20}");

            for (int i = 0; i < 1000; i++)
            {
                // .... build a string of the form: aa[rt,t,rt]ata[t]aa[rt]aaa[t,t]aaa[rt,rt]ataa...
                var generatedString = xeger.Generate();
                Test_aartt(generatedString);
            }
        }
Beispiel #5
0
        private void AppendChoice(StringBuilder builder, Transition transition)
        {
            var c = (char)Xeger.GetRandomInt(transition.Min, transition.Max, random);

            builder.Append(c);
        }
Beispiel #6
0
 static IEnumerable<string> Xegers(string pattern, System.Random rnd)
 {
     var xeger = new Xeger(pattern, rnd);
     var result = Enumerable.Range(0, 10).Select(x => xeger.Generate());
     result.ToList().ForEach(Console.WriteLine);
     return result;
 }
Beispiel #7
0
        public void XegerIssue1()
        {
            var x = new Fare.Xeger(".*");

            // loops
            //x = new Fare.Xeger(".*.*");
            //var x = new Fare.Xeger(".*:.*");
        }
        private static string GenerateSingleValuedStringTests(BindingDescription bindingDescription)
        {
            var nonMatchTest = "";
            var val = "A string";
            if (!string.IsNullOrEmpty(bindingDescription.StringRegex))
            {
                var xeger = new Xeger(bindingDescription.StringRegex);
                val = xeger.Generate();

                var nonMatch = @"flkj3332@!!!$

            fd333
            ";
                nonMatchTest = string.Format(Templates.NonMatchTest,
                    GetValidCSharpIdentifier(bindingDescription.BoundAttributeType.Name),
                    nonMatch);
            }

            string tests = string.Format(Templates.SingleValuedStringFormatTests,
                GetValidCSharpIdentifier(bindingDescription.BoundAttributeType.Name),
                val,
                nonMatchTest);
            return tests;
        }
        public void It_generates_the_correct_property_and_tests_for_a_binding_thats_not_required()
        {
            // Arrange
            var regExString = "8";
            var bindingDescription = new BindingDescription
            {
                DisplayName = "First Choice for Summary Part I",
                Description = "First Choice for Summary Part II",
                Required = false,
                StringRegex = regExString,
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType = "String",
                    DisplayName = "Second Choice for Summary Part I",
                    Description = "Second Choice for Summary Part II",
                    Name = "PropertyName"
                },
            };
            var xeger = new Xeger(regExString);
            var match = xeger.Generate();
            var nonMatch = @"flkj3332@!!!$

            fd333
            ";
            var expectedTests = string.Format(TestData.BindingNotRequiredTests, match, nonMatch);

            var it = new IdmCodeGenerator(null);

            // Act
            Tuple<string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.BindingNotRequired, result.Item1);
            ExAssert.AreEqual(expectedTests, result.Item2);
        }