public IReaderMode Read(int indention, string line)
        {
            if (line.IsEmpty())
            {
                return(this);
            }

            if (line.IsHeaderOne())
            {
                _fixture.title = line.Trim().TrimStart('#', ' ');
                return(this);
            }

            if (line.IsHeaderTwo())
            {
                var grammar = new GrammarMode(_fixture, g => _fixture.AddGrammar(g));
                grammar.Read(indention, line);

                return(grammar);
            }

            var mode = new CommentMode(_fixture);

            mode.Read(indention, line);

            return(mode);
        }
Exemple #2
0
        public void copies_grammars()
        {
            const string fixtureKey = "a key";

            var lib      = new FixtureLibrary();
            var original = new FixtureModel(fixtureKey);

            lib.Models[fixtureKey] = original;

            original.AddGrammar(new Sentence {
                key = "sentence", format = "a format"
            });

            var overrides = new FixtureLibrary();
            var overriden = new FixtureModel(fixtureKey);

            overrides.Models[fixtureKey] = overriden;

            var result = lib.ApplyOverrides(overrides);

            result.Models.Count.ShouldBe(1);

            var fixture = result.Models[fixtureKey];

            ReferenceEquals(fixture, overrides.Models[fixtureKey]).ShouldBeFalse();
            fixture.key.ShouldBe(fixtureKey);

            fixture.grammars.Length.ShouldBe(1);

            var sentence = fixture.grammars[0] as Sentence;

            sentence.key.ShouldBe("sentence");
            sentence.format.ShouldBe("a format");
        }
Exemple #3
0
 public TableMode(string key, string title, FixtureModel fixture)
 {
     _table       = new Table();
     _table.key   = key;
     _table.title = title;
     fixture.AddGrammar(_table);
 }
        public void can_mark_the_missing_grammars()
        {
            var system = new FixtureModel("something");

            system.AddGrammar(new Sentence {
                key = "Go1", format = "Go One"
            });

            var overrides = new FixtureModel("something");

            overrides.AddGrammar(new Sentence {
                key = "Go2", format = "Go Two"
            });

            var combined = system.ApplyOverrides(overrides).As <FixtureModel>();

            combined.FindGrammar("Go1").IsMissing.ShouldBeFalse();
            combined.FindGrammar("Go2").IsMissing.ShouldBeTrue();
        }
Exemple #5
0
 public GrammarMode(FixtureModel fixture)
 {
     _fixture  = fixture;
     _sentence = new Sentence();
     _fixture.AddGrammar(_sentence);
 }