コード例 #1
0
        public void TestNextString()
        {
            string path = Path.GetTempFileName();

            File.WriteAllText(path, File.ReadAllText("TestNextString.txt"));
            LocalisationParser parser = new LocalisationParser(path);

            parser.Prefix = "p";

            Assert.IsTrue(parser.NextString());
            Assert.AreEqual("some string yay", parser.String);
            Assert.AreEqual("foo", parser.Variable);
            Assert.AreEqual("P_SomeStringYay", parser.FullKey);
            parser.Key = "actually foo";
            Assert.AreEqual("P_ActuallyFoo", parser.FullKey);
            parser.ReplaceStringWithKey();

            Assert.IsTrue(parser.NextString());
            parser.Prefix = "no go";
            Assert.IsTrue(parser.String.Length > 50);
            Assert.AreEqual("foo_bar", parser.Variable);
            Assert.AreEqual("No_go_FooBar", parser.FullKey);
            parser.ReplaceStringWithKey();

            Assert.IsTrue(parser.NextString());
            parser.Prefix = "p!!";
            Assert.AreEqual("good", parser.String);
            Assert.AreEqual("Foo.bar", parser.Variable);
            Assert.AreEqual("P_Good", parser.FullKey);
            parser.ReplaceStringWithConstant();

            Assert.IsTrue(parser.NextString());
            Assert.AreEqual("bad", parser.String);
            Assert.AreEqual("Foo.bar", parser.Variable);
            Assert.AreEqual("P_Bad", parser.FullKey);

            Assert.IsTrue(parser.NextString());
            Assert.AreEqual("escapable", parser.Variable);
            parser.ReplaceStringWithConstant();

            Assert.IsTrue(parser.NextString());
            Assert.AreEqual("unescapable", parser.Variable);
            parser.ReplaceStringWithConstant();

            Assert.IsFalse(parser.NextToken());

            string[] expected = File.ReadAllLines("TestNextStringExpected.txt");
            string[] actual   = File.ReadAllLines(path);
            Assert.AreEqual(expected.Length, actual.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }
コード例 #2
0
        public void TestNextStringUpdateFile()
        {
            string[] lines = File.ReadAllLines("TestNextStringUpdateFile.txt");
            string   path  = Path.GetTempFileName();

            File.WriteAllText(path, lines[0]);
            LocalisationParser parser = new LocalisationParser(path);

            parser.Prefix = "p";

            Assert.IsTrue(parser.NextString());
            Assert.AreEqual("foo", parser.String);
            Assert.AreEqual("P_Foo", parser.FullKey);
            parser.ReplaceStringWithKey();

            Assert.IsTrue(parser.NextString());
            Assert.AreEqual(lines[1], File.ReadAllText(path));
            Assert.AreEqual("bar", parser.String);
            parser.ReplaceStringWithConstant();

            Assert.IsTrue(parser.NextString());
            Assert.AreEqual(lines[2], File.ReadAllText(path));
            Assert.AreEqual("end", parser.String);

            Assert.IsFalse(parser.NextString());
            Assert.AreEqual(lines[3], File.ReadAllText(path));
        }