Esempio n. 1
0
        public void ParseDepsSection(string input, DepsData expected)
        {
            var yaml = GetDepsSections(input);

            var parser = new DepsSectionParser(new DepSectionItemParser());
            var merger = new DepsSectionMerger();

            var parsed = parser.Parse(yaml);
            var merged = merger.Merge(parsed);

            merged.Should().BeEquivalentTo(expected);
        }
Esempio n. 2
0
        public DepsData Merge(DepsSection current, [CanBeNull] DepsSection defaults = null, [CanBeNull] DepsSection[] parents = null)
        {
            var sections = new List <DepsSection> {
                defaults ?? new DepsSection()
            }
            .Concat(parents ?? new DepsSection[0])
            .Concat(new[] { current })
            .ToArray();

            var resultingDeps = new List <Dep>();

            foreach (var section in sections)
            {
                foreach (var line in section.SectionItems)
                {
                    if (line.IsRemoved)
                    {
                        var removedCount = resultingDeps.RemoveAll(testedDep => DepMatch(line.Dependency, testedDep));
                        if (removedCount == 0)
                        {
                            throw new BadYamlException("deps", $"You cannot delete dependency '{line.Dependency}'. You have to add it first.");
                        }
                    }
                    else
                    {
                        // Two duplicate deps is normal
                        // Two deps with same name and different configuration/branch - is not
                        if (!resultingDeps.Contains(line.Dependency))
                        {
                            resultingDeps.Add(line.Dependency);
                        }
                    }
                }
            }

            EnsureNoDuplicates(resultingDeps);

            var result = new DepsData(current.Force, resultingDeps.ToList());

            return(result);
        }
Esempio n. 3
0
 public static bool HasForcedBranches(this DepsData deps)
 {
     return(deps.Force != null && deps.Force.Length > 0);
 }