public void WriteHeader(ConfigIniSection section, string expectedText)
            {
                var writer = new StringWriter();

                section.WriteHeader(writer);
                Assert.That(writer.ToString(), Is.EqualTo(expectedText));
            }
Esempio n. 2
0
            public void When_Has2DistinctSections()
            {
                var sectionA1 = new ConfigIniSection("A");
                var tokenA1_1 = new TextToken();
                var tokenA1_2 = new TextToken();
                var tokenA1_3 = new TextToken();

                sectionA1.Tokens.Add(tokenA1_1);
                sectionA1.Tokens.Add(tokenA1_2);
                sectionA1.Tokens.Add(tokenA1_3);

                var sectionB1 = new ConfigIniSection("B");
                var tokenB1_1 = new TextToken();
                var tokenB1_2 = new TextToken();
                var tokenB1_3 = new TextToken();

                sectionB1.Tokens.Add(tokenB1_1);
                sectionB1.Tokens.Add(tokenB1_2);
                sectionB1.Tokens.Add(tokenB1_3);

                var config = new ConfigIni();

                config.Sections.Add(sectionA1);
                config.Sections.Add(sectionB1);

                config.MergeDuplicateSections();

                Assert.That(config.Sections, Is.EquivalentTo(new[] { sectionA1, sectionB1 }));
                Assert.That(sectionA1.Tokens, Is.EquivalentTo(new[] { tokenA1_1, tokenA1_2, tokenA1_3 }));
                Assert.That(sectionB1.Tokens, Is.EquivalentTo(new[] { tokenB1_1, tokenB1_2, tokenB1_3 }));
            }
Esempio n. 3
0
            TToken AssertNAddedTokenToSection <TToken>(ConfigIni configIni, ConfigIniSection expectedSection, int expectedTokens)
                where TToken : IniToken
            {
                var token = AssertNAddedTokenToSection(configIni, expectedSection, expectedTokens);

                Assert.That(token, Is.TypeOf <TToken>());
                return(token as TToken);
            }
        public void When_ConstructedDefault()
        {
            ConfigIniSection section = null;

            Assert.That(() => { section = new ConfigIniSection(); }, Throws.Nothing);
            Assert.That(section.Name, Is.Null);
            Assert.That(section.Tokens, Is.Empty);
        }
        public void When_ConstructedWithNullTokens()
        {
            ConfigIniSection section = null;

            Assert.That(() => { section = new ConfigIniSection((IEnumerable <IniToken>)null); }, Throws.Nothing);
            Assert.That(section.Name, Is.Null);
            Assert.That(section.Tokens, Is.Empty);
        }
        public void When_ConstructedWithNameAndNullTokens()
        {
            string           name    = "/Script/Engine.PlayerInput";
            ConfigIniSection section = null;

            Assert.That(() => { section = new ConfigIniSection(name, null); }, Throws.Nothing);
            Assert.That(section.Name, Is.EqualTo(name));
            Assert.That(section.Tokens, Is.Empty);
        }
Esempio n. 7
0
        public void When_ConstructedWithSections()
        {
            ConfigIni config   = null;
            var       sectionA = new ConfigIniSection("A");
            var       sectionB = new ConfigIniSection("A");

            Assert.That(() => { config = new ConfigIni(new[] { sectionA, sectionB }); }, Throws.Nothing);
            Assert.That(config.Name, Is.Null);
            Assert.That(config.Sections, Is.EquivalentTo(new[] { sectionA, sectionB }));
        }
        public void When_ConstructedWithTokens()
        {
            ConfigIniSection section = null;
            var token1 = new TextToken();
            var token2 = new TextToken();

            Assert.That(() => { section = new ConfigIniSection(new[] { token1, token2 }); }, Throws.Nothing);
            Assert.That(section.Name, Is.Null);
            Assert.That(section.Tokens, Is.EquivalentTo(new[] { token1, token2 }));
        }
Esempio n. 9
0
        public void When_ConstructedWithNameAndSections()
        {
            string    name     = "Engine/Config/Base.ini";
            ConfigIni config   = null;
            var       sectionA = new ConfigIniSection("A");
            var       sectionB = new ConfigIniSection("B");

            Assert.That(() => { config = new ConfigIni(name, new[] { sectionA, sectionB }); }, Throws.Nothing);
            Assert.That(config.Name, Is.EqualTo(name));
            Assert.That(config.Sections, Is.EquivalentTo(new[] { sectionA, sectionB }));
        }
Esempio n. 10
0
 IniToken AssertNAddedTokenToSection(ConfigIni configIni, ConfigIniSection expectedSection, int expectedTokens)
 {
     Assert.That(configIni.Sections, Has.Count.EqualTo(1));
     Assert.That(configIni.Sections[0], Is.SameAs(expectedSection));
     Assert.That(configIni.Sections[0].Tokens, Has.Count.EqualTo(expectedTokens));
     for (int tokenI = 0; tokenI < expectedTokens; tokenI++)
     {
         Assert.That(configIni.Sections[0].Tokens[tokenI], Is.Not.Null);
     }
     return(configIni.Sections[0].Tokens[expectedTokens - 1]);
 }
Esempio n. 11
0
        public void When_ConstructedWithNameAndTokens()
        {
            string           name    = "/Script/Engine.PlayerInput";
            ConfigIniSection section = null;
            var token1 = new TextToken();
            var token2 = new TextToken();

            Assert.That(() => { section = new ConfigIniSection(name, new[] { token1, token2 }); }, Throws.Nothing);
            Assert.That(section.Name, Is.EqualTo(name));
            Assert.That(section.Tokens, Is.EquivalentTo(new[] { token1, token2 }));
        }
Esempio n. 12
0
            public void When_HasSingleCommentToken()
            {
                var section = new ConfigIniSection();
                var token1  = new CommentToken(new[] { "; Hey", ";Whats", " ;Up?" }, LineEnding.None);

                section.Tokens.Add(token1);
                section.MergeConsecutiveTokens();

                Assert.That(section.Tokens, Has.Count.EqualTo(1));
                Assert.That(section.Tokens[0], Is.SameAs(token1));
                Assert.That(token1.GetStringLines(), Is.EquivalentTo(new[] { "; Hey", ";Whats", " ;Up?" }));
            }
Esempio n. 13
0
            public void When_LineIsInvalid_TreatsAsText(string line)
            {
                var configIni      = new ConfigIni();
                var currentSection = new ConfigIniSection();

                configIni.Sections.Add(currentSection);

                Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);

                var tokenT = AssertSingleAddedTokenToSection <TextToken>(configIni, currentSection);

                Assert.That(tokenT.Text, Is.EqualTo(line));
            }
Esempio n. 14
0
            public void When_LineIsNull_DoesNothing(string line)
            {
                var configIni      = new ConfigIni();
                var currentSection = new ConfigIniSection();

                configIni.Sections.Add(currentSection);

                Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);

                Assert.That(configIni.Sections, Has.Count.EqualTo(1));
                Assert.That(configIni.Sections[0], Is.SameAs(currentSection));
                Assert.That(configIni.Sections[0].Tokens, Is.Empty);
            }
Esempio n. 15
0
            public void When_Has2ConsecutiveWhitespaceTokens()
            {
                var section = new ConfigIniSection();
                var token1  = new WhitespaceToken(new[] { "", "\t", "  " }, LineEnding.None);
                var token2  = new WhitespaceToken(new[] { " ", "\t", "" }, LineEnding.None);

                section.Tokens.Add(token1);
                section.Tokens.Add(token2);
                section.MergeConsecutiveTokens();

                Assert.That(section.Tokens, Has.Count.EqualTo(1));
                Assert.That(section.Tokens[0], Is.SameAs(token1));
                Assert.That(token1.GetStringLines(), Is.EquivalentTo(new[] { "", "\t", "  ", " ", "\t", "" }));
            }
Esempio n. 16
0
            public void When_LineIsComment(string line)
            {
                var configIni      = new ConfigIni();
                var currentSection = new ConfigIniSection();

                configIni.Sections.Add(currentSection);

                Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);

                var tokenT = AssertSingleAddedTokenToSection <CommentToken>(configIni, currentSection);

                Assert.That(tokenT.Lines, Has.Count.EqualTo(1));
                Assert.That(tokenT.Lines[0].ToString(), Is.EqualTo(line));
            }
Esempio n. 17
0
            public void When_LineIsRemoveAll(string line, string expectedKey)
            {
                var configIni      = new ConfigIni();
                var currentSection = new ConfigIniSection();

                configIni.Sections.Add(currentSection);

                Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);

                var tokenT = AssertSingleAddedTokenToSection <InstructionToken>(configIni, currentSection);

                Assert.That(tokenT.InstructionType, Is.EqualTo(InstructionType.RemoveAll));
                Assert.That(tokenT.Key, Is.EqualTo(expectedKey));
                Assert.That(tokenT.Value, Is.Null);
            }
Esempio n. 18
0
            public void When_LineIsRepeatedComment(string[] lines)
            {
                var configIni      = new ConfigIni();
                var currentSection = new ConfigIniSection();

                configIni.Sections.Add(currentSection);

                foreach (var line in lines)
                {
                    Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);
                }

                var tokenT = AssertSingleAddedTokenToSection <CommentToken>(configIni, currentSection);

                Assert.That(tokenT.Lines, Has.Count.EqualTo(lines.Length));
                Assert.That(tokenT.GetStringLines(), Is.EquivalentTo(lines));
            }
Esempio n. 19
0
            public void When_LineIsSectionHeader(string line, string expectedName, string expectedWastePrefix = null, string expectedWasteSuffix = null)
            {
                var configIni      = new ConfigIni();
                var initialSection = new ConfigIniSection();

                configIni.Sections.Add(initialSection);
                var currentSection = initialSection;

                Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);

                Assert.That(initialSection, Is.Not.SameAs(currentSection));
                Assert.That(currentSection, Is.Not.Null);
                Assert.That(configIni.Sections, Has.Count.EqualTo(2));
                Assert.That(configIni.Sections[0], Is.SameAs(initialSection));
                Assert.That(configIni.Sections[1], Is.SameAs(currentSection));
                Assert.That(currentSection.Name, Is.EqualTo(expectedName));
                Assert.That(currentSection.LineWastePrefix, Is.EqualTo(expectedWastePrefix));
                Assert.That(currentSection.LineWasteSuffix, Is.EqualTo(expectedWasteSuffix));
            }
Esempio n. 20
0
            public void When_HasTokens()
            {
                List <IniToken> callLog    = new List <IniToken>();
                var             spySection = new ConfigIniSection();
                var             spyToken1  = new SpyIniToken()
                {
                    Write_CallLog = callLog
                };
                var spyToken2 = new SpyIniToken()
                {
                    Write_CallLog = callLog
                };

                spySection.Tokens.Add(spyToken1);
                spySection.Tokens.Add(spyToken2);
                var writer = new StringWriter();

                spySection.WriteTokens(writer);
                Assert.That(callLog, Is.EquivalentTo(new[] { spyToken1, spyToken2 }));
            }
Esempio n. 21
0
            public void When_Has3NonConsecutiveTokens()
            {
                var section = new ConfigIniSection();
                var token1  = new CommentToken(new[] { "; Hey", ";Whats", " ;Up?" }, LineEnding.None);
                var token2  = new WhitespaceToken(new[] { " ", "\t", "" }, LineEnding.None);
                var token3  = new CommentToken(new[] { ";Baz" }, LineEnding.None);

                section.Tokens.Add(token1);
                section.Tokens.Add(token2);
                section.Tokens.Add(token3);
                section.MergeConsecutiveTokens();

                Assert.That(section.Tokens, Has.Count.EqualTo(3));
                Assert.That(section.Tokens[0], Is.SameAs(token1));
                Assert.That(section.Tokens[1], Is.SameAs(token2));
                Assert.That(section.Tokens[2], Is.SameAs(token3));
                Assert.That(token1.GetStringLines(), Is.EquivalentTo(new[] { "; Hey", ";Whats", " ;Up?" }));
                Assert.That(token2.GetStringLines(), Is.EquivalentTo(new[] { " ", "\t", "" }));
                Assert.That(token3.GetStringLines(), Is.EquivalentTo(new[] { ";Baz" }));
            }
Esempio n. 22
0
            public void When_Has3DuplicateSections()
            {
                var sectionA1 = new ConfigIniSection("A");
                var tokenA1_1 = new TextToken();
                var tokenA1_2 = new TextToken();
                var tokenA1_3 = new TextToken();

                sectionA1.Tokens.Add(tokenA1_1);
                sectionA1.Tokens.Add(tokenA1_2);
                sectionA1.Tokens.Add(tokenA1_3);

                var sectionA2 = new ConfigIniSection("A");
                var tokenA2_1 = new TextToken();
                var tokenA2_2 = new TextToken();
                var tokenA2_3 = new TextToken();

                sectionA2.Tokens.Add(tokenA2_1);
                sectionA2.Tokens.Add(tokenA2_2);
                sectionA2.Tokens.Add(tokenA2_3);

                var sectionA3 = new ConfigIniSection("A");
                var tokenA3_1 = new TextToken();
                var tokenA3_2 = new TextToken();
                var tokenA3_3 = new TextToken();

                sectionA3.Tokens.Add(tokenA3_1);
                sectionA3.Tokens.Add(tokenA3_2);
                sectionA3.Tokens.Add(tokenA3_3);

                var config = new ConfigIni();

                config.Sections.Add(sectionA1);
                config.Sections.Add(sectionA2);
                config.Sections.Add(sectionA3);

                config.MergeDuplicateSections();

                Assert.That(config.Sections, Is.EquivalentTo(new[] { sectionA1 }));
                Assert.That(sectionA1.Tokens, Is.EquivalentTo(new[] { tokenA1_1, tokenA1_2, tokenA1_3, tokenA2_1, tokenA2_2, tokenA2_3, tokenA3_1, tokenA3_2, tokenA3_3 }));
            }
Esempio n. 23
0
 IniToken AssertSingleAddedTokenToSection(ConfigIni configIni, ConfigIniSection expectedSection)
 {
     return(AssertNAddedTokenToSection(configIni, expectedSection, 1));
 }
Esempio n. 24
0
 TToken AssertSingleAddedTokenToSection <TToken>(ConfigIni configIni, ConfigIniSection expectedSection)
     where TToken : IniToken
 {
     return(AssertNAddedTokenToSection <TToken>(configIni, expectedSection, 1));
 }