Пример #1
0
 private void OnWriteObjectProperties(IndentedTextWriter writer, IALObject target)
 {
     foreach (ALProperty aLProperty in target.Properties)
     {
         writer.WriteLine(aLProperty.Name + " = " + aLProperty.Value + ";");
     }
 }
Пример #2
0
        public static void Write <T>(IALObject Target, string Path)
            where T : ALObjectWriterBase, new()
        {
            var writer = new T();

            writer.Write(Target, Path);
        }
Пример #3
0
        /// <summary>
        /// Basic object information, such as Type, ID, Name
        /// </summary>
        /// <param name="Lines">Array of textlines</param>
        /// <param name="Target">Current ALObject instance</param>
        public void GetObjectInfo(string line, out IALObject Target)
        {
            Target = new ALObject();

            if (!string.IsNullOrEmpty(line))
            {
                var items = Regex.Match(line, ObjectHeaderPattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
                var type  = items.Groups[1].Value.ToEnum <ALObjectType>();
                var idTxt = items.Groups[2].Value;

                Target    = ALObjectTypeMap.CreateInstance(type);
                Target.Id = 0;
                if (!String.IsNullOrEmpty(idTxt))
                {
                    Target.Id = int.Parse(items.Groups[2].Value);
                }
                var nameParts = items.Groups[3].Value.Split(" extends ");
                if (nameParts.Length < 2)
                {
                    nameParts = items.Groups[3].Value.Split(" implements ");
                }
                Target.Name = nameParts[0].Replace("\"", "").Trim();
                Target.Type = type;
            }

            OnGetObjectInfo(line, Target);
        }
Пример #4
0
        public static string Write <T>(IALObject Target)
            where T : ALObjectWriterBase, new()
        {
            var writer = new T();

            return(writer.Write(Target));
        }
Пример #5
0
        public T Read <T>(string Path)
            where T : ALObject
        {
            var       Lines  = File.ReadAllLines(Path);
            IALObject result = Read(Lines);

            return(result as T);
        }
Пример #6
0
        public virtual void OnWriteObjectMethods(IndentedTextWriter writer, IALObject Target)
        {
            var methods   = Target.Methods.Select(method => OnWriteObjectMethod(Target, method));
            var methodTxt = String.Join("\r\n\r\n    ", methods);

            writer.Indent++;
            writer.WriteLine(methodTxt);
            writer.Indent--;
        }
Пример #7
0
        /// <summary>
        /// Basic object information, such as Type, ID, Name
        /// </summary>
        /// <param name="Lines">Array of textlines</param>
        /// <param name="Target">Current ALObject instance</param>
        public void GetObjectInfo(IEnumerable <string> Lines, out IALObject Target)
        {
            Target = new ALObject();
            var line = Lines
                       .Where(w => Regex.IsMatch(w.ToLower(), ObjectHeaderPattern, RegexOptions.IgnoreCase | RegexOptions.Multiline))
                       .FirstOrDefault();

            GetObjectInfo(line, out Target);
        }
        //#region Write to Object

        public override void OnWriteObjectHeader(IndentedTextWriter writer, IALObject Target)
        {
            base.OnWriteObjectHeader(writer, Target);
            TestALCodeunit testALCodeunit = (TestALCodeunit)Target;
            ALMethod       aLMethod       = new ALMethod {
                MethodKind = ALMethodKind.Trigger, Name = "OnRun"
            };

            List <string> contentLines = new List <string>();

            foreach (ITestFeature feature in testALCodeunit.Features)
            {
                contentLines.Add(string.Format("[Feature] {0}", feature.Name));
            }
            aLMethod.Content = String.Join("\r\n        ", contentLines);

            writer.Write(OnWriteObjectMethod(Target, aLMethod));
        }
Пример #9
0
        public void GetGlobalVariables(IEnumerable <string> Lines, IALObject Target)
        {
            var result       = new List <ALVariable>();
            var patternVar   = @"var";
            var selectedLine = 0;
            var c            = Lines.Count();

            for (int i = 0; i < c; i++)
            {
                var line = Lines.ElementAt(i);
                if (line.Trim() == patternVar)
                {
                    if (!Lines.ElementAt(i - 1).Contains("procedure"))
                    {
                        selectedLine = i;
                        break;
                    }
                }
            }

            selectedLine += 1;
            for (int i = selectedLine; i < c; i++)
            {
                var line  = Lines.ElementAt(i);
                var parts = line.Split(":");
                if (parts.Count() < 2)
                {
                    break;
                }

                var variable = new ALVariable
                {
                    Name           = parts[0].Trim(),
                    TypeDefinition = new ALTypeDefinition {
                        Name = parts[1].Trim()
                    }
                };

                result.Add(variable);
            }

            Target.GlobalVariables = result;
        }
Пример #10
0
        /// <summary>
        /// Extensible function
        /// </summary>
        /// <param name="Target">Current ALObject instance</param>
        /// <returns></returns>
        public virtual string OnWrite(IALObject Target)
        {
            var result = "";

            using (var stringWriter = new StringWriter())
            {
                using (var writer = new IndentedTextWriter(stringWriter))
                {
                    OnWriteObjectHeader(writer, Target);
                    OnWriteObjectProperties(writer, Target);
                    Target.Write(writer);
                    OnWriteObjectMethods(writer, Target);
                    OnWriteObjectFooter(writer, Target);
                }

                result = stringWriter.ToString();
            }

            return(result);
        }
Пример #11
0
        public void GetRange(IEnumerable <string> Lines, IALObject Target)
        {
            string contents = String.Join("__", Lines);

            foreach (ALMethod method in Target.Methods)
            {
                Match match = Regex.Match(contents, $"(.*)(local)? (procedure|trigger) {method.Name}\\(", RegexOptions.IgnoreCase);
                if (!match.Success)
                {
                    continue;
                }
                string textBeforeProcedure = contents.Substring(0, match.Groups[1].Length);
                int    startLineNo         = (textBeforeProcedure.Length - textBeforeProcedure.Replace("__", "").Length) / 2;
                string pattern             = ".{" + textBeforeProcedure.Length + "}.+?__    end;";
                match = Regex.Match(contents, pattern, RegexOptions.IgnoreCase);
                if (!match.Success)
                {
                    continue;
                }
                string textUntilEndOfProcedure = contents.Substring(0, match.Groups[0].Length);
                int    endLineNo = (textUntilEndOfProcedure.Length - textUntilEndOfProcedure.Replace("__", "").Length) / 2;
                method.MethodRange = new Range(startLineNo, endLineNo);
            }
        }
Пример #12
0
        /// <summary>
        /// Generate a new filecontent from IALObject
        /// </summary>
        /// <param name="Target"></param>
        /// <param name="Path"></param>
        public void Write(IALObject Target, string Path)
        {
            var objectTxt = Write(Target);

            File.WriteAllText(Path, objectTxt);
        }
Пример #13
0
 /// <summary>
 /// Method to implement custom  for extended classes
 /// </summary>
 /// <param name="Line">Top line of object definition</param>
 /// <param name="Target">Current ALObject instance</param>
 public virtual void OnGetObjectInfo(string Line, IALObject Target)
 {
 }
Пример #14
0
 public static string Write(IALObject Target)
 {
     return(ALParser.Write <ALObjectWriterBase>(Target));
 }
Пример #15
0
 public static void Write(IALObject Target, string Path)
 {
     ALParser.Write <ALObjectWriterBase>(Target, Path);
 }
Пример #16
0
 public virtual void OnWriteObjectHeader(IndentedTextWriter writer, IALObject Target)
 {
     writer.WriteLine($"{Target.Type} {Target.Id} {(Target.Name.Contains(' ') ? $"\"{Target.Name}\"" : Target.Name)}");
     writer.WriteLine("{");
 }
Пример #17
0
 public virtual void OnWriteObjectFooter(IndentedTextWriter writer, IALObject Target)
 {
     writer.WriteLine("}");
 }
        public override void OnRead(IEnumerable <string> Lines, IALObject Target, out IALObject NewTarget)
        {
            base.OnRead(Lines, Target, out NewTarget);
            var str = JsonConvert.SerializeObject(Target);

            var TestTarget = new TestALCodeunit
            {
                Id      = Target.Id,
                Name    = Target.Name,
                Methods = Target.Methods.Select(s => new TestALMethod
                {
                    Attributes           = s.Attributes,
                    Comments             = s.Comments,
                    Content              = s.Content,
                    IsLocal              = s.IsLocal,
                    MethodBody           = s.MethodBody,
                    MethodKind           = s.MethodKind,
                    Name                 = s.Name,
                    Parameters           = s.Parameters,
                    ReturnTypeDefinition = s.ReturnTypeDefinition,
                    TestMethod           = s.TestMethod,
                    MethodRange          = s.MethodRange
                }).ToList(),
                GlobalVariables = Target.GlobalVariables,
                Properties      = Target.Properties,
                Type            = Target.Type,
                Comments        = Target.Comments,
                Sections        = Target.Sections
            };

            if (TestTarget.Methods == null)
            {
                return;
            }

            if (TestTarget.Methods.Count == 0)
            {
                return;
            }

            var testMethods     = TestTarget.Methods.Where(w => w.TestMethod == true).ToList();
            var enumNames       = Enum.GetNames(typeof(ScenarioElementType));
            var enumNamesJoined = String.Join('|', enumNames);
            var pattern         = @".*\[(" + enumNamesJoined + @")(.*?)\]\s+(.*)";
            var features        = new List <ITestFeature>();

            foreach (var method in testMethods)
            {
                var matches = Regex.Matches(method.Content, pattern, RegexOptions.IgnoreCase);
                if (matches.Count > 0)
                {
                    var matchList     = matches.ToList();
                    var scenarioElems = matchList
                                        .Select(m => new
                    {
                        Type     = m.Groups[1].Value.ToEnum <ScenarioElementType>(),
                        Id       = m.Groups[2].Value.Trim().Replace("#", ""),
                        Name     = m.Groups[3].Value.Trim(),
                        LineText = m.Groups[0].Value.Trim()
                    });

                    ITestFeature feature  = new TestFeature();
                    var          scenario = new TestScenario();

                    foreach (var elem in scenarioElems)
                    {
                        switch (elem.Type)
                        {
                        case ScenarioElementType.FEATURE:
                            feature = features.FirstOrDefault(a => a.Name == elem.Name);
                            if (feature == null)
                            {
                                feature = new TestFeature
                                {
                                    Name      = elem.Name,
                                    Scenarios = new List <ITestScenario>()
                                };
                                features.Add(feature);
                            }
                            break;

                        case ScenarioElementType.SCENARIO:
                            scenario            = new TestScenario();
                            scenario.ID         = int.Parse(elem.Id);
                            scenario.Name       = elem.Name;
                            scenario.MethodName = method.Name;
                            scenario.Feature    = feature;
                            feature.Scenarios.Add(scenario);
                            break;

                        case ScenarioElementType.GIVEN:
                            var given = new TestScenarioElement();
                            given.Type     = elem.Type;
                            given.Value    = elem.Name;
                            given.LineText = elem.LineText;
                            scenario.Elements.Add(given);
                            break;

                        case ScenarioElementType.WHEN:
                            var when = new TestScenarioElement();
                            when.Type     = elem.Type;
                            when.Value    = elem.Name;
                            when.LineText = elem.LineText;
                            scenario.Elements.Add(when);
                            break;

                        case ScenarioElementType.THEN:
                            var then = new TestScenarioElement();
                            then.Type     = elem.Type;
                            then.Value    = elem.Name;
                            then.LineText = elem.LineText;
                            scenario.Elements.Add(then);
                            break;

                        default:
                            break;
                        }
                    }

                    method.Scenario = scenario;
                }
            }

            TestTarget.Features = features;
            NewTarget           = TestTarget;
        }
Пример #19
0
 public virtual string OnWriteObjectMethod(IALObject Target, ALMethod method)
 {
     return(method.Write());
 }
Пример #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Target">Current ALObject instance</param>
 /// <param name="Features">TestFeature set to be merged with AL Methods</param>
 /// <returns></returns>
 public string Write(IALObject Target)
 {
     return(OnWrite(Target));
 }
Пример #21
0
 /// <summary>
 /// Method to implement custom processing during parsing
 /// </summary>
 /// <param name="Lines"></param>
 /// <param name="Target"></param>
 public virtual void OnRead(IEnumerable <string> Lines, IALObject Target, out IALObject NewTarget)
 {
     NewTarget = Target;
 }