Example #1
0
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            var table = new Table {key = key, hasAfterStep = hasAfterStep, hasBeforeStep = hasBeforeStep};

            var over = grammar as Table;
            if (over == null)
            {
                table.title = title;
                table.collection = collection;
                table.cells = cells?.Select(c => c.ApplyOverrides(null)).ToArray();

                return table;
            }

            table.title = over.title.IsNotEmpty() ? over.title : title;
            table.collection = over.collection.IsNotEmpty() ? over.collection : collection;

            var matchedCells = cells?.Select(c =>
            {
                var match = over.cells.FirstOrDefault(x => x.Key == c.Key);
                return c.ApplyOverrides(match);
            }).ToList() ?? new List<Cell>();

            var keys = cells.Select(x => x.Key).ToList();

            var missingCells = over.cells.Where(x => !keys.Contains(x.Key)).Select(x => x.ApplyOverrides(null));
            table.cells = matchedCells.Concat(missingCells).ToArray();

            return table;
        }
Example #2
0
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            var sentence = new Sentence {key = key};

            var over = grammar as Sentence;
            if (over == null)
            {
                sentence.format = format;
                sentence.cells = cells.Select(c => c.ApplyOverrides(null)).ToArray();
                return sentence;
            }

            sentence.format = over.format.IsNotEmpty() ? over.format : format;
            sentence.cells = cells?.Select(c =>
            {
                var match = sentence.cells.FirstOrDefault(x => x.Key == c.Key);
                return c.ApplyOverrides(match);
            }).ToArray();

            var keys = sentence.cells.Select(x => x.Key).ToList();
            var missing = over.cells.Where(x => !keys.Contains(x.Key));
            missing.Each(c =>
            {
                sentence.AddCell(c.ApplyOverrides(null));
            });

            return sentence;
        }
Example #3
0
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            var sentence = new Sentence();

            sentence.key = key;

            var over = grammar as Sentence;

            if (over == null)
            {
                sentence.format = format;
                sentence.cells  = cells.Select(c => c.ApplyOverrides(null)).ToArray();
                return(sentence);
            }

            sentence.format = over.format.IsNotEmpty() ? over.format : format;
            sentence.cells  = cells?.Select(c =>
            {
                var match = sentence.cells.FirstOrDefault(x => x.Key == c.Key);
                return(c.ApplyOverrides(match));
            }).ToArray();

            var keys    = sentence.cells.Select(x => x.Key).ToList();
            var missing = over.cells.Where(x => !keys.Contains(x.Key));

            missing.Each(c =>
            {
                sentence.AddCell(c.ApplyOverrides(null));
            });

            return(sentence);
        }
Example #4
0
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            var model = new FixtureModel(key);

            model.implementation = implementation;

            var over = grammar as FixtureModel;

            if (over == null)
            {
                model.title    = title;
                model.grammars = grammars.Select(x => x.ApplyOverrides(null)).ToArray();
                return(model);
            }

            model.title    = over.title.IsNotEmpty() ? over.title : title;
            model.grammars = grammars.Select(g =>
            {
                var match = over.grammars.FirstOrDefault(x => x.key == g.key);
                return(g.ApplyOverrides(match));
            }).ToArray();

            var keys    = model.grammars.Select(x => x.key).ToList();
            var missing = over.grammars.Where(x => !keys.Contains(x.key));

            missing.Each(x =>
            {
                model.AddGrammar(x.ApplyOverrides(null));
            });

            return(model);
        }
Example #5
0
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            var @override = grammar as EmbeddedSection;

            if (@override == null)
            {
                return(this);
            }

            var section = new EmbeddedSection
            {
                key           = key,
                title         = title,
                collection    = collection,
                fixture       = (FixtureModel)fixture.ApplyOverrides(@override.fixture),
                hasBeforeStep = hasBeforeStep,
                hasAfterStep  = hasAfterStep
            };

            if (@override.title.IsNotEmpty())
            {
                section.title = @override.title;
            }

            return(section);
        }
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            if (!(grammar is FixtureModel))
            {
                return(this);
            }

            var model = new FixtureModel(key)
            {
                implementation = implementation
            };
            var over = grammar.As <FixtureModel>();

            model.title = over.title.IsNotEmpty() ? over.title : title;

            foreach (var existing in _grammars)
            {
                var overridden = over.FindGrammar(existing.key);
                var combined   = overridden == null ? existing : existing.ApplyOverrides(overridden);
                combined.errors =
                    (existing.errors ?? new GrammarError[0]).Concat((overridden?.errors ?? new GrammarError[0]))
                    .ToArray();

                model.AddGrammar(combined);
            }

            foreach (var specified in over.grammars.Where(x => !grammars.Any(_ => _.key == x.key)))
            {
                specified.IsMissing = true;
                model.AddGrammar(specified);
            }

            return(model);
        }
Example #7
0
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            // IT'S IMPORTANT IN THIS CASE THAT THE CODE WINS IN THE COLLECTION NAME
            var table = new Table {
                key = key, hasAfterStep = hasAfterStep, hasBeforeStep = hasBeforeStep, collection = collection
            };

            var over = grammar as Table;

            if (over == null)
            {
                table.title      = title;
                table.collection = collection;
                table.cells      = cells?.Select(c => c.ApplyOverrides(null)).ToArray();

                return(table);
            }

            table.title = over.title.IsNotEmpty() ? over.title : title;

            var matchedCells = cells?.Select(c =>
            {
                var match = over.cells.FirstOrDefault(x => x.Key == c.Key);
                return(c.ApplyOverrides(match));
            }).ToList() ?? new List <Cell>();

            var keys = cells.Select(x => x.Key).ToList();

            var missingCells = over.cells.Where(x => !keys.Contains(x.Key)).Select(x => x.ApplyOverrides(null));

            table.cells = matchedCells.Concat(missingCells).ToArray();

            return(table);
        }
Example #8
0
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            var table = new Table();

            table.key = key;

            var over = grammar as Table;

            if (over == null)
            {
                table.title      = title;
                table.collection = collection;
                table.cells      = cells?.Select(c => c.ApplyOverrides(null)).ToArray();
                return(table);
            }

            table.title      = over.title.IsNotEmpty() ? over.title : title;
            table.collection = over.collection.IsNotEmpty() ? over.collection : collection;

            var matchedCells = cells?.Select(c =>
            {
                var match = over.cells.FirstOrDefault(x => x.Key == c.Key);
                return(c.ApplyOverrides(match));
            }).ToList() ?? new List <Cell>();

            var keys         = table.cells.Select(x => x.Key).ToList();
            var missingCells = over.cells.Where(x => !keys.Contains(x.Key)).Select(x => x.ApplyOverrides(null));

            table.cells = matchedCells.Concat(missingCells).ToArray();

            return(table);
        }
Example #9
0
 public void AddChild(GrammarModel grammar)
 {
     var newGrammars = new[] {grammar};
     if (children == null || children.Length == 0)
         children = newGrammars;
     else
         children = children.Concat(newGrammars).ToArray();
 }
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            var @override = grammar as Paragraph;

            if (@override == null)
            {
                return(this);
            }


            var newParagraph = new Paragraph
            {
                key = key
            };

            if (@override.title.IsNotEmpty() && @override.title != key)
            {
                newParagraph.title = @override.title;
            }


            if (@override.children == null || @override.children.Length == 0)
            {
                newParagraph.children = children;
            }
            else
            {
                var nonSilentIndex = 0;

                foreach (var child in children)
                {
                    if (child is Silent)
                    {
                        newParagraph.AddChild(child);
                    }
                    else
                    {
                        if (@override.children.Length > nonSilentIndex)
                        {
                            var overridenChild = @override.children[nonSilentIndex++];
                            newParagraph.AddChild(child.ApplyOverrides(overridenChild));
                        }
                        else
                        {
                            newParagraph.AddChild(child);
                        }
                    }
                }
            }

            return(newParagraph);
        }
        public void AddChild(GrammarModel grammar)
        {
            var newGrammars = new[] { grammar };

            if (children == null || children.Length == 0)
            {
                children = newGrammars;
            }
            else
            {
                children = children.Concat(newGrammars).ToArray();
            }
        }
Example #12
0
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            var @override = grammar as Paragraph;
            if (@override == null) return this;


            var newParagraph = new Paragraph
            {
                key = key
            };

            if (@override.title.IsNotEmpty() && @override.title != key)
                newParagraph.title = @override.title;


            if (@override.children == null || @override.children.Length == 0)
            {
                newParagraph.children = children;
            }
            else
            {
                var nonSilentIndex = 0;

                foreach (var child in children)
                    if (child is Silent)
                    {
                        newParagraph.AddChild(child);
                    }
                    else
                    {
                        if (@override.children.Length > nonSilentIndex)
                        {
                            var overridenChild = @override.children[nonSilentIndex++];
                            newParagraph.AddChild(child.ApplyOverrides(overridenChild));
                        }
                        else
                        {
                            newParagraph.AddChild(child);
                        }
                    }
            }

            return newParagraph;
        }
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            var @override = grammar as EmbeddedSection;
            if (@override == null) return this;

            var section = new EmbeddedSection
            {
                key = key,
                title = title,
                collection = collection,
                fixture = (FixtureModel) fixture.ApplyOverrides(@override.fixture),
                hasBeforeStep = hasBeforeStep,
                hasAfterStep = hasAfterStep
                
            };

            if (@override.title.IsNotEmpty())
            {
                section.title = @override.title;
            }

            return section;
        }
Example #14
0
 public virtual GrammarModel ApplyOverrides(GrammarModel grammar)
 {
     return this;
 }
Example #15
0
 public void AddGrammar(GrammarModel grammar)
 {
     _grammars.Add(grammar);
 }
Example #16
0
        public override GrammarModel ApplyOverrides(GrammarModel grammar)
        {
            if (!(grammar is FixtureModel)) return this;

            var model = new FixtureModel(key) {implementation = implementation};
            var over = grammar.As<FixtureModel>();

            model.title = over.title.IsNotEmpty() ? over.title : title;

            foreach (var existing in _grammars)
            {
                var overridden = over.FindGrammar(existing.key);
                var combined = overridden == null ? existing : existing.ApplyOverrides(overridden);
                combined.errors =
                    (existing.errors ?? new GrammarError[0]).Concat((overridden?.errors ?? new GrammarError[0]))
                        .ToArray();

                model.AddGrammar(combined);
            }

            foreach (var specified in over.grammars.Where(x => !grammars.Any(_ => _.key == x.key)))
            {
                specified.IsMissing = true;
                model.AddGrammar(specified);
            }

            return model;
        }
Example #17
0
 public void RemoveGrammar(GrammarModel grammar)
 {
     _grammars.Remove(grammar);
 }
Example #18
0
 public void AddGrammar(GrammarModel grammar)
 {
     _grammars.Add(grammar);
 }
Example #19
0
 public virtual GrammarModel ApplyOverrides(GrammarModel grammar)
 {
     throw new NotImplementedException();
 }
 public virtual GrammarModel ApplyOverrides(GrammarModel grammar)
 {
     return(this);
 }