예제 #1
0
        //[TestMethod]
        public void VivadoCommandRecordTest()
        {
            var log = new VivadoCommandLog();

            var paramTypes = new List <string>()
            {
                "[-optional_flag]",
                "[<optional_name> <arg>]",
                "<required_value>",
                "[<patterns>...]",
                "<required_name> <arg>",
                "[<optional_value>]",
            };

            var fixes = new VivadoTCLFixes();

            foreach (var p in paramTypes)
            {
                var lines = new List <string>()
                {
                    "test_command",
                    "Syntax",
                    $"test_command {p}"
                };

                var record = new VivadoCommandRecord(log, fixes, "test_command", new VivdoCommandTextLines()
                {
                    Lines = lines
                });
            }
        }
        public VivadoCommandRecord(VivadoCommandLog log, VivadoTCLFixes fixes, string name, VivdoCommandTextLines commandData)
        {
            _log   = log;
            _fixes = fixes;

            CommandData = commandData;
            Name        = name;
            var lines = commandData.Lines;

            var orderedSections = new VivadoCommandRecordSection[]
            {
                new VivadoCommandRecordSection(name, OnCommand),
                new VivadoCommandRecordSection("Syntax", OnSyntax),
                new VivadoCommandRecordSection("Returns", OnReturns),
                new VivadoCommandRecordSection("Usage", OnUsage),
                new VivadoCommandRecordSection("Categories", OnCategories),
                new VivadoCommandRecordSection("Description", OnDescription),
                new VivadoCommandRecordSection("Arguments", OnArguments),
                new VivadoCommandRecordSection("Examples", OnExamples),
                new VivadoCommandRecordSection("See Also", OnSeeAlso),
            };

            // make sure that sections are in expected order
            var indexes = orderedSections
                          .Select(s => new { name = s.SectionName, index = lines.IndexOf(s.SectionName) })
                          .Where(s => s.index != -1)
                          .ToList();

            for (var idx = 0; idx < indexes.Count - 1; idx++)
            {
                var thisSection = indexes[idx];
                var nextSection = indexes[idx + 1];
                if (thisSection.index > nextSection.index)
                {
                    throw new Exception($"Command {name}: Section {thisSection.name} is expected to be before {nextSection.name}");
                }
            }

            // process sections
            var existingSections = orderedSections.Where(s => indexes.Any(i => i.name == s.SectionName)).ToList();

            for (var idx = 0; idx < existingSections.Count; idx++)
            {
                var thisSection = existingSections[idx];
                var nextSection = existingSections.Skip(idx + 1).FirstOrDefault();

                var text = BaseGenerator.between(lines, thisSection.SectionName, nextSection?.SectionName);
                thisSection.Handler(text);
            }
        }