Example #1
0
 public void FirstMilleniumParty()
 {
     string input = "date=999.1.1";
     DateTime expected = new DateTime(999, 1, 1);
     DateTime actual = DateTime.MaxValue;
     Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
     {
         {"date", x => actual = x.ReadDateTime()}
     };
     ParadoxParser.Parse(input.ToStream(), dictionary.ParserAdapter());
     Assert.AreEqual(expected, actual);
 }
Example #2
0
        public void ExtraNewLinesDontMatter()
        {
            var data = "\n\n\n\n ID=100 \n\n\n\n\n\n".ToStream();

            int id = 0;
            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                {"ID", x => id = x.ReadInt32()}
            };
            ParadoxParser.Parse(data, dictionary.ParserAdapter());
            Assert.AreEqual(100, id);
        }
Example #3
0
        public void NegativeInt32()
        {
            var data = "ID=-130".ToStream();
            int actual = 0;
            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                { "ID", x => actual = x.ReadInt32() }
            };

            ParadoxParser.Parse(data, dictionary.ParserAdapter());

            Assert.AreEqual(-130, actual);
        }
Example #4
0
 public void WhenChristWasBorn()
 {
     string input = "date=1.1.1";
     DateTime expected = new DateTime(1, 1, 1);
     DateTime actual = DateTime.MaxValue;
     Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
     {
         {"date", x => actual = x.ReadDateTime()}
     };
     ParadoxParser.Parse(input.ToStream(), dictionary.ParserAdapter());
     Assert.AreEqual(expected, actual);
 }
Example #5
0
        public void TrickyNewLineWithQuotes()
        {
            var data = "name=\"namer1\"\ncolor=\"Gray\"".ToStream();

            string name = string.Empty;
            string color = string.Empty;
            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                {"name", x => name = x.ReadString()},
                {"color", x => color = x.ReadString()}
            };
            ParadoxParser.Parse(data, dictionary.ParserAdapter());

            Assert.AreEqual("namer1", name);
            Assert.AreEqual("Gray", color);
        }
Example #6
0
        public void TrickyNewLine()
        {
            var data = "tag=tagger\ntype=typer".ToStream();
            string tag = string.Empty;
            string type = String.Empty;

            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                { "tag", x => tag = x.ReadString() },
                { "type", x => type = x.ReadString() }
            };

            ParadoxParser.Parse(data, dictionary.ParserAdapter());

            Assert.AreEqual("tagger", tag);
            Assert.AreEqual("typer", type);
        }
Example #7
0
        public void SimpleWithSpace()
        {
            var data = "culture = michigan".ToStream();

            string actual = String.Empty;
            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                { "culture", x => actual = x.ReadString() }
            };
            ParadoxParser.Parse(data, dictionary.ParserAdapter());

            Assert.AreEqual("michigan", actual);
        }
Example #8
0
        public void SimpleName()
        {
            string toParse = "name=\"Nick\"";
            var data = toParse.ToStream();

            string actual = String.Empty;
            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                { "name", x => actual = x.ReadString() }
            };
            ParadoxParser.Parse(data, dictionary.ParserAdapter());

            Assert.AreEqual("Nick", actual);
        }
Example #9
0
        public void SimpleMultiLine()
        {
            string toParse = "date=\"1770.12.5\"" + Environment.NewLine +
                             "player=\"JAP\"" + Environment.NewLine +
                             "monarch=12209";

            var data = toParse.ToStream();
            DateTime? actualDate = null;
            string actualPlayer = null;
            int? actualMonarch = null;

            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                { "date", x => actualDate = x.ReadDateTime() },
                { "player", x => actualPlayer = x.ReadString() },
                { "monarch", x => actualMonarch = x.ReadInt32() }
            };

            ParadoxParser.Parse(data, dictionary.ParserAdapter());

            Assert.That(actualDate.HasValue);
            Assert.That(!String.IsNullOrEmpty(actualPlayer));
            Assert.That(actualMonarch.HasValue);

            Assert.AreEqual(new DateTime(1770, 12, 5), actualDate);
            Assert.AreEqual("JAP", actualPlayer);
            Assert.AreEqual(12209, actualMonarch);
        }
Example #10
0
        public void SimpleInt32()
        {
            string toParse = "ID=130";
            var data = toParse.ToStream();

            int actual = 0;
            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                { "ID", x => actual = x.ReadInt32() }
            };
            ParadoxParser.Parse(data, dictionary.ParserAdapter());

            Assert.AreEqual(130, actual);
        }
Example #11
0
        public void SimpleDate()
        {
            string toParse = "date=\"1770.12.5\"";
            var data = toParse.ToStream();

            DateTime actual = DateTime.MinValue;
            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                { "date", x => actual = x.ReadDateTime() }
            };
            ParadoxParser.Parse(data, dictionary.ParserAdapter());

            DateTime expected = new DateTime(1770, 12, 5);
            Assert.AreEqual(expected, actual);
        }
Example #12
0
        public void SimpleComment()
        {
            string toParse = "#culture=michigan";
            var data = toParse.ToStream();

            string actual = String.Empty;
            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                { "culture", x => actual = x.ReadString() }
            };

            ParadoxParser.Parse(data, dictionary.ParserAdapter());
            Assert.AreEqual(String.Empty, actual);
        }
Example #13
0
        public void FollowingCommentWithSpace()
        {
            string toParse = "tag = data #culture=michigan\n" +
                             "tag2 = data2";
            var data = toParse.ToStream();

            string actual = String.Empty;
            string tag2 = String.Empty;
            Dictionary<string, Action<ParadoxParser>> dictionary = new Dictionary<string, Action<ParadoxParser>>
            {
                { "culture", x => actual = x.ReadString() },
                { "tag2", x => tag2 = x.ReadString() }
            };

            ParadoxParser.Parse(data, dictionary.ParserAdapter());
            Assert.AreEqual(String.Empty, actual);
            Assert.AreEqual("data2", tag2);
        }