Ejemplo n.º 1
0
        public void TestSave__NullInList()
        {
            List <DummyIConfigNode> list = new List <DummyIConfigNode>
            {
                new DummyIConfigNode {
                    value = "blah1"
                },
                null,
                new DummyIConfigNode {
                    value = "blah2"
                },
            };

            ConfigNode node = new ConfigNode();

            Assert.True(mapper.Save(list, node, Exemplars.SaveContext));

            ConfigNode expected = new TestConfigNode
            {
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "blah1" },
                },
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "blah2" },
                }
            };

            AssertUtil.ConfigNodesEqual(expected, node);
        }
Ejemplo n.º 2
0
        public void TestLoad__Null()
        {
            object dummy = null;

            ConfigNode innerNode = new TestConfigNode("SOME_NODE")
            {
                { "value", "something" },
            };

            ConfigNode outerNode = new TestConfigNode
            {
                innerNode,
                new TestConfigNode("SOME_OTHER_NODE")
                {
                    { "value", "something else" },
                },
            };

            OperationContext context  = Exemplars.LoadPrefabContext;
            object           newDummy = new object();

            wrapper.When(x => x.Load(ref dummy, innerNode, context)).Do(x => x[0] = newDummy);
            Assert.True(mapper.Load(ref dummy, outerNode, context));

            Assert.Same(dummy, newDummy);
        }
        public void TestPrettyPrint__NullIndent()
        {
            ConfigNode node = new TestConfigNode("SOME_NODE")
            {
                { "abc", "def" },
                { "ghi", "jkl" },
                new TestConfigNode("INNER_NODE")
                {
                    { "mno", "pqr" },
                },
            };

            string expected = @"
SOME_NODE
{
  abc = def
  ghi = jkl
  INNER_NODE
  {
    mno = pqr
  }
}
".TrimStart().Replace("\r", null);

            StringBuilder sb = new StringBuilder();

            node.PrettyPrint(ref sb, null);
            Assert.Equal(expected, sb.ToString());
        }
Ejemplo n.º 4
0
        public void TestModifyNode__EditNode__SpecialCharacters()
        {
            ConfigNode c1 = new TestConfigNode("NODE")
            {
                new TestConfigNode("INNER_NODE")
                {
                    { "weird_values", "some\r\n\tstuff" },
                },
            };

            UrlDir.UrlConfig c2u = UrlBuilder.CreateConfig("abc/def", new TestConfigNode("@NODE")
            {
                new TestConfigNode("@INNER_NODE")
                {
                    { "another_weird_value", "some\r\nmore\tstuff" },
                },
            });

            PatchContext context = new PatchContext(c2u, Enumerable.Empty <IProtoUrlConfig>(), logger, progress);

            ConfigNode c3 = MMPatchLoader.ModifyNode(new NodeStack(c1), c2u.config, context);

            EnsureNoErrors();

            AssertConfigNodesEqual(new TestConfigNode("NODE")
            {
                new TestConfigNode("INNER_NODE")
                {
                    { "weird_values", "some\r\n\tstuff" },
                    { "another_weird_value", "some\r\nmore\tstuff" },
                },
            }, c3);
        }
        public void TestModifyNode__MultiplyValue()
        {
            ConfigNode c1 = new TestConfigNode("NODE")
            {
                { "foo", "3" },
                { "foo", "5" },
            };

            UrlDir.UrlConfig c2u = UrlBuilder.CreateConfig("abc/def", new TestConfigNode("@NODE")
            {
                { "@foo *", "2" },
            }, root);

            PatchContext context = new PatchContext(c2u, root, logger, progress);

            ConfigNode c3 = MMPatchLoader.ModifyNode(new NodeStack(c1), c2u.config, context);

            EnsureNoErrors();

            AssertConfigNodesEqual(new TestConfigNode("NODE")
            {
                { "foo", "6" },
                { "foo", "5" },
            }, c3);
        }
Ejemplo n.º 6
0
        public void TestLoad__IContextualNode()
        {
            NodeListMapper mapper2           = new NodeListMapper("SOME_NODE", typeof(DummyIContextualNode));
            List <DummyIContextualNode> list = new List <DummyIContextualNode>();
            object value = list;

            ConfigNode node = new TestConfigNode
            {
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "thing1" },
                },
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "thing2" },
                },
                new TestConfigNode("SOME_OTHER_NODE")
                {
                    { "value", "thing2" },
                },
            };

            OperationContext context = Exemplars.LoadContext;

            Assert.True(mapper2.Load(ref value, node, context));
            Assert.Same(list, value);
            Assert.Equal(2, list.Count);

            Assert.Equal("thing1", list[0].value);
            Assert.Equal("thing2", list[1].value);

            Assert.Same(context, list[0].lastContext);
            Assert.Same(context, list[1].lastContext);
        }
Ejemplo n.º 7
0
        public void TestLoad__IContextualNode()
        {
            NodeScalarMapper     mapper2 = new NodeScalarMapper("SOME_NODE", typeof(DummyIContextualNode));
            DummyIContextualNode dummy   = new DummyIContextualNode();
            object dummyRef = dummy;

            ConfigNode node = new TestConfigNode
            {
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "something" },
                },
                new TestConfigNode("SOME_OTHER_NODE")
                {
                    { "value", "something else" },
                },
            };

            OperationContext context = Exemplars.LoadContext;

            Assert.True(mapper2.Load(ref dummyRef, node, context));
            Assert.Same(dummyRef, dummy);
            Assert.Equal("something", dummy.value);
            Assert.Same(context, dummy.lastContext);
        }
        public void TestPrettyPrint()
        {
            ConfigNode node = new TestConfigNode("SOME_NODE")
            {
                { "abc", "def" },
                { "ghi", "jkl" },
                new TestConfigNode("INNER_NODE_1")
                {
                    { "mno", "pqr" },
                },
            };

            UrlDir.UrlConfig url = UrlBuilder.CreateConfig("abc/def.cfg", node);

            string expected = @"
abc/def/SOME_NODE
  SOME_NODE
  {
    abc = def
    ghi = jkl
    INNER_NODE_1
    {
      mno = pqr
    }
  }
".TrimStart().Replace("\r", null);

            Assert.Equal(expected, url.PrettyPrint());
        }
Ejemplo n.º 9
0
        public void TestLoad__NoNodes()
        {
            List <DummyIConfigNode> list = new List <DummyIConfigNode>
            {
                new DummyIConfigNode {
                    value = "thing0"
                },
            };

            object value = list;

            ConfigNode node = new TestConfigNode
            {
                new TestConfigNode("SOME_OTHER_NODE")
                {
                    { "value", "thing2" },
                },
            };

            Assert.False(mapper.Load(ref value, node, Exemplars.LoadContext));
            Assert.Same(list, value);
            Assert.Equal(1, list.Count);

            AssertDummyIConfigNode(list[0], "thing0");
        }
Ejemplo n.º 10
0
        public void TestSave__IContextualNode()
        {
            NodeListMapper mapper2           = new NodeListMapper("SOME_NODE", typeof(DummyIContextualNode));
            List <DummyIContextualNode> list = new List <DummyIContextualNode>
            {
                new DummyIContextualNode {
                    value = "blah1"
                },
                new DummyIContextualNode {
                    value = "blah2"
                },
            };

            ConfigNode       node    = new ConfigNode();
            OperationContext context = Exemplars.SaveContext;

            Assert.True(mapper2.Save(list, node, Exemplars.SaveContext));

            ConfigNode expected = new TestConfigNode
            {
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "blah1" },
                },
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "blah2" },
                }
            };

            AssertUtil.ConfigNodesEqual(expected, node);

            Assert.Same(context, list[0].lastContext);
            Assert.Same(context, list[1].lastContext);
        }
Ejemplo n.º 11
0
        public void TestLoad__NoNodes()
        {
            object obj0 = new object();

            List <object> list = new List <object>
            {
                obj0,
            };

            object value = list;

            ConfigNode node = new TestConfigNode
            {
                new TestConfigNode("SOME_OTHER_NODE")
                {
                    { "value", "thing2" },
                },
            };

            Assert.False(mapper.Load(ref value, node, Exemplars.LoadPrefabContext));
            Assert.Same(list, value);
            Assert.Single(list);

            Assert.Same(obj0, list[0]);

            wrapper.DidNotReceiveWithAnyArgs().Load(ref obj0, null, null);
        }
Ejemplo n.º 12
0
        public void TestLoad__Null()
        {
            object value = null;

            ConfigNode node = new TestConfigNode
            {
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "thing1" },
                },
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "thing2" },
                },
                new TestConfigNode("SOME_OTHER_NODE")
                {
                    { "value", "thing2" },
                },
            };

            Assert.True(mapper.Load(ref value, node, Exemplars.LoadContext));
            Assert.IsType <List <DummyIConfigNode> >(value);

            List <DummyIConfigNode> list = (List <DummyIConfigNode>)value;

            Assert.Equal(2, list.Count);

            AssertDummyIConfigNode(list[0], "thing1");
            AssertDummyIConfigNode(list[1], "thing2");
        }
Ejemplo n.º 13
0
        public void TestLoad()
        {
            object dummy    = new object();
            object dummyRef = dummy;

            ConfigNode innerNode = new TestConfigNode("SOME_NODE")
            {
                { "value", "something" },
            };

            ConfigNode outerNode = new TestConfigNode
            {
                innerNode,
                new TestConfigNode("SOME_OTHER_NODE")
                {
                    { "value", "something else" },
                },
            };

            OperationContext context = Exemplars.LoadPrefabContext;

            Assert.True(mapper.Load(ref dummyRef, outerNode, context));
            Assert.Same(dummyRef, dummy);

            wrapper.Received().Load(ref dummyRef, innerNode, context);
        }
Ejemplo n.º 14
0
        public void TestModifyNode__IndexAllWithAssign()
        {
            ConfigNode c1 = new TestConfigNode("NODE")
            {
                { "foo", "bar1" },
                { "foo", "bar2" },
            };

            UrlDir.UrlConfig c2u = UrlBuilder.CreateConfig("abc/def", new TestConfigNode("@NODE")
            {
                { "@foo,*", "bar3" },
            });

            PatchContext context = new PatchContext(c2u, Enumerable.Empty <IProtoUrlConfig>(), logger, progress);

            ConfigNode c3 = MMPatchLoader.ModifyNode(new NodeStack(c1), c2u.config, context);

            EnsureNoErrors();

            AssertConfigNodesEqual(new TestConfigNode("NODE")
            {
                { "foo", "bar3" },
                { "foo", "bar3" },
            }, c3);
        }
        public void TestPrettyPrint__NullName()
        {
            ConfigNode node = new TestConfigNode()
            {
                { "abc", "def" },
                { "ghi", "jkl" },
                new TestConfigNode("INNER_NODE")
                {
                    { "mno", "pqr" },
                },
            };

            node.name = null;

            string expected = @"
XX<null>
XX{
XX  abc = def
XX  ghi = jkl
XX  INNER_NODE
XX  {
XX    mno = pqr
XX  }
XX}
".TrimStart().Replace("\r", null);

            StringBuilder sb = new StringBuilder();

            node.PrettyPrint(ref sb, "XX");
            Assert.Equal(expected, sb.ToString());
        }
Ejemplo n.º 16
0
        public void TestLoad()
        {
            List <DummyIConfigNode> list = new List <DummyIConfigNode>();
            object value = list;

            ConfigNode node = new TestConfigNode
            {
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "thing1" },
                },
                new TestConfigNode("SOME_NODE")
                {
                    { "value", "thing2" },
                },
                new TestConfigNode("SOME_OTHER_NODE")
                {
                    { "value", "thing2" },
                },
            };

            Assert.True(mapper.Load(ref value, node, Exemplars.LoadContext));
            Assert.Same(list, value);
            Assert.Equal(2, list.Count);

            AssertDummyIConfigNode(list[0], "thing1");
            AssertDummyIConfigNode(list[1], "thing2");
        }
Ejemplo n.º 17
0
        public void TestCompilePatch__Copy()
        {
            ProtoPatch protoPatch = new ProtoPatch(
                UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("+NODE")
            {
                { "@name", "boo" },
                { "@bar", "bleh" },
            }),
                Command.Copy,
                "NODE",
                "foo",
                null,
                "#bar",
                Substitute.For <IPassSpecifier>()
                );

            CopyPatch patch = Assert.IsType <CopyPatch>(patchCompiler.CompilePatch(protoPatch));

            Assert.Same(protoPatch.urlConfig, patch.UrlConfig);
            AssertNodeMatcher(patch.NodeMatcher);

            ConfigNode config = new TestConfigNode("NODE")
            {
                { "name", "foo" },
                { "bar", "baz" },
            };

            IProtoUrlConfig urlConfig = Substitute.For <IProtoUrlConfig>();

            urlConfig.Node.Returns(config);
            urlConfig.UrlFile.Returns(file);

            LinkedList <IProtoUrlConfig> configs = new LinkedList <IProtoUrlConfig>();

            configs.AddLast(urlConfig);

            patch.Apply(configs, progress, logger);

            AssertNoErrors();

            progress.Received().ApplyingCopy(urlConfig, protoPatch.urlConfig);

            IProtoUrlConfig[] newConfigs = configs.ToArray();

            Assert.Equal(2, newConfigs.Length);
            Assert.Same(config, newConfigs[0].Node);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "foo" },
                { "bar", "baz" },
            }, newConfigs[0].Node);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "boo" },
                { "bar", "bleh" },
            }, newConfigs[1].Node);
            Assert.Same(file, newConfigs[1].UrlFile);
        }
Ejemplo n.º 18
0
        public void TestTestConfigNode()
        {
            ConfigNode node = new TestConfigNode("NODE")
            {
                { "value1", "something" },
                { "value2", "something else" },
                { "multiple", "first" },
                { "multiple", "second" },
                new ConfigNode.Value("foo", "bar"),
                { "weird_values", "some\r\n\tstuff" },
                { "NODE_1", new TestConfigNode
                  {
                      { "name", "something" },
                      { "stuff", "something else" },
                  } },
                new TestConfigNode("MULTIPLE")
                {
                    { "value3", "blah" },
                    { "value4", "bleh" },
                },
                new TestConfigNode("MULTIPLE")
                {
                    { "value3", "blih" },
                    { "value4", "bloh" },
                },
            };

            Assert.Equal(6, node.values.Count);
            AssertValue("value1", "something", node.values[0]);
            AssertValue("value2", "something else", node.values[1]);
            AssertValue("multiple", "first", node.values[2]);
            AssertValue("multiple", "second", node.values[3]);
            AssertValue("foo", "bar", node.values[4]);
            AssertValue("weird_values", "some\r\n\tstuff", node.values[5]);

            Assert.Equal(3, node.nodes.Count);
            ConfigNode innerNode1 = node.GetNode("NODE_1");

            Assert.NotNull(innerNode1);

            Assert.Equal("NODE_1", node.nodes[0].name);
            Assert.Equal(2, node.nodes[0].values.Count);
            AssertValue("name", "something", node.nodes[0].values[0]);
            AssertValue("stuff", "something else", node.nodes[0].values[1]);
            Assert.Empty(node.nodes[0].nodes);

            Assert.Equal("MULTIPLE", node.nodes[1].name);
            Assert.Equal(2, node.nodes[1].values.Count);
            AssertValue("value3", "blah", node.nodes[1].values[0]);
            AssertValue("value4", "bleh", node.nodes[1].values[1]);
            Assert.Empty(node.nodes[1].nodes);

            Assert.Equal("MULTIPLE", node.nodes[2].name);
            Assert.Equal(2, node.nodes[2].values.Count);
            AssertValue("value3", "blih", node.nodes[2].values[0]);
            AssertValue("value4", "bloh", node.nodes[2].values[1]);
            Assert.Empty(node.nodes[2].nodes);
        }
        public void TestSafeUrl__BlankName()
        {
            ConfigNode node = new TestConfigNode(" ")
            {
                { "name", "this shouldn't show up" },
            };

            UrlDir.UrlConfig url = UrlBuilder.CreateConfig("abc/def", node);
            Assert.Equal("abc/def/<blank>", url.SafeUrl());
        }
Ejemplo n.º 20
0
        public void TestTestConfigNode()
        {
            ConfigNode node = new TestConfigNode("NODE")
            {
                { "value1", "something" },
                { "value2", "something else" },
                { "multiple", "first" },
                { "multiple", "second" },
                new ConfigNode.Value("foo", "bar"),
                { "NODE_1", new TestConfigNode
                  {
                      { "name", "something" },
                      { "stuff", "something else" },
                  } },
                new TestConfigNode("MULTIPLE")
                {
                    { "value3", "blah" },
                    { "value4", "bleh" },
                },
                new TestConfigNode("MULTIPLE")
                {
                    { "value3", "blih" },
                    { "value4", "bloh" },
                },
            };

            Assert.Equal("something", node.GetValue("value1"));
            Assert.Equal("something else", node.GetValue("value2"));
            Assert.Equal(new[] { "first", "second" }, node.GetValues("multiple"));
            Assert.Equal("bar", node.GetValue("foo"));

            ConfigNode innerNode1 = node.GetNode("NODE_1");

            Assert.NotNull(innerNode1);

            Assert.Equal("NODE_1", innerNode1.name);
            Assert.Equal("something", innerNode1.GetValue("name"));
            Assert.Equal("something else", innerNode1.GetValue("stuff"));

            ConfigNode[] innerNodes2 = node.GetNodes("MULTIPLE");
            Assert.NotNull(innerNodes2);
            Assert.Equal(2, innerNodes2.Length);

            ConfigNode innerNode2a = innerNodes2[0];

            Assert.NotNull(innerNode2a);
            Assert.Equal("blah", innerNode2a.GetValue("value3"));
            Assert.Equal("bleh", innerNode2a.GetValue("value4"));

            ConfigNode innerNode2b = innerNodes2[1];

            Assert.NotNull(innerNode2b);
            Assert.Equal("blih", innerNode2b.GetValue("value3"));
            Assert.Equal("bloh", innerNode2b.GetValue("value4"));
        }
Ejemplo n.º 21
0
        public void TestFullUrl__NameValue()
        {
            ConfigNode node = new TestConfigNode("SOME_NODE")
            {
                { "name", "some_value" },
            };

            ProtoUrlConfig protoUrlConfig = new ProtoUrlConfig(UrlBuilder.CreateFile("abc/def.cfg"), node);

            Assert.Equal("abc/def.cfg/SOME_NODE[some_value]", protoUrlConfig.FullUrl);
        }
Ejemplo n.º 22
0
        public void TestSave__Empty()
        {
            List <string> value = new List <string>();
            ConfigNode    node  = new TestConfigNode
            {
                { "someValue", "blah0" },
            };

            Assert.False(mapper.Save(value, node, Exemplars.SaveContext));
            Assert.Equal(new[] { "blah0" }, node.GetValues("someValue"));
            Assert.Empty(value);
        }
Ejemplo n.º 23
0
        public void TestLoad__WrongType()
        {
            object dummy = "why are you passing a string?";

            ConfigNode node = new TestConfigNode
            {
                { "someValue", "something" },
            };

            Assert.Throws <ArgumentException>(() => mapper.Load(ref dummy, new ConfigNode(), Exemplars.LoadPrefabContext));
            Assert.Throws <ArgumentException>(() => mapper.Load(ref dummy, node, Exemplars.LoadPrefabContext));
        }
Ejemplo n.º 24
0
        public void TestSave__WrongType()
        {
            string dummy = "why are you passing a string?";

            ConfigNode node = new TestConfigNode
            {
                { "someValue", "something" },
            };

            Assert.Throws <ArgumentException>(() => mapper.Save(dummy, new ConfigNode(), Exemplars.SaveContext));
            Assert.Throws <ArgumentException>(() => mapper.Save(dummy, node, Exemplars.SaveContext));
        }
Ejemplo n.º 25
0
        public void TestRunTestCases__AllPassing()
        {
            UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/blah1.cfg", databaseRoot);
            UrlDir.UrlFile file2 = UrlBuilder.CreateFile("abc/blah2.cfg", databaseRoot);

            ConfigNode testNode1 = new TestConfigNode("NODE1")
            {
                { "key1", "value1" },
                { "key2", "value2" },
                new TestConfigNode("NODE2")
                {
                    { "key3", "value3" },
                },
            };

            ConfigNode testNode2 = new TestConfigNode("NODE3")
            {
                { "key4", "value4" },
            };

            ConfigNode testNode3 = new TestConfigNode("NODE4")
            {
                { "key5", "value5" },
            };

            UrlBuilder.CreateConfig(testNode1, file1);
            UrlBuilder.CreateConfig(testNode2, file1);
            UrlBuilder.CreateConfig(new TestConfigNode("MMTEST_EXPECT")
            {
                testNode1.CreateCopy(),
                testNode2.CreateCopy(),
            }, file1);

            UrlBuilder.CreateConfig(testNode3, file2);
            UrlBuilder.CreateConfig(new TestConfigNode("MMTEST_EXPECT")
            {
                testNode3.CreateCopy(),
            }, file2);

            testRunner.RunTestCases(databaseRoot);

            Received.InOrder(delegate
            {
                logger.AssertInfo("Running tests...");
                logger.AssertInfo("tests complete.");
            });

            logger.AssertNoError();

            Assert.Empty(file1.configs);
            Assert.Empty(file2.configs);
        }
Ejemplo n.º 26
0
        public void TestLoad()
        {
            DummyIConfigNode dummy = new DummyIConfigNode();

            ConfigNode node = new TestConfigNode
            {
                { "value", "blah1234" },
                { "otherValue", "blah6789" },
            };

            dummy.Load(node);
            Assert.Equal("blah1234", dummy.value);
        }
Ejemplo n.º 27
0
        public void TestLoad()
        {
            TestConfigNode node = new TestConfigNode
            {
                { "foo", "bar" },
                { "omg", "bbq" }
            };

            object value = null;

            Assert.True(mapper.Load(ref value, node, Exemplars.LoadPrefabContext));
            Assert.Equal("!!bar!!", value);
        }
Ejemplo n.º 28
0
        public void TestLoad__NoValue()
        {
            TestConfigNode node = new TestConfigNode
            {
                { "boo", "bar" },
                { "omg", "bbq" }
            };

            object value = "abc";

            Assert.False(mapper.Load(ref value, node, Exemplars.LoadPrefabContext));
            Assert.Equal("abc", value);
        }
Ejemplo n.º 29
0
        public void TestAddValueSafe()
        {
            ConfigNode node = new TestConfigNode
            {
                { "key1", "value1" },
            };

            node.AddValueSafe("weird_values", "some\r\n\tstuff");

            Assert.Equal(2, node.values.Count);
            AssertValue("key1", "value1", node.values[0]);
            AssertValue("weird_values", "some\r\n\tstuff", node.values[1]);
        }
Ejemplo n.º 30
0
        private UrlDir.UrlConfig CreateConfig(string name)
        {
            ConfigNode node = new TestConfigNode(name)
            {
                { "name", "test" },
                { "foo", "bar" },
                new ConfigNode("INNER_NODE"),
            };

            node.id = "who_uses_this";

            return(UrlBuilder.CreateConfig(node, file));
        }