Exemplo n.º 1
0
 public void TestAllSelector()
 {
     Assert.AreEqual(AllSelector.GetSelector(), AllSelector.GetSelector(), "All selector singleton not working");
     Assert.AreEqual("*", AllSelector.GetSelector().GetSelectorString(), "All selector doesn't return correct string");
     Assert.IsFalse(AllSelector.GetSelector().IsLimited(), "All selector doesn't return correct limited value");
     Assert.ThrowsException <InvalidOperationException>(() => AllSelector.GetSelector().LimitSelector(), "LimitSelector didn't throw an exception");
 }
Exemplo n.º 2
0
        public void TestTexts()
        {
            //text
            Assert.AreEqual("{\"text\":\"hel\\nlo\"}", new JsonText.Text("hel\nlo").GetJsonString(), "Text doesn't return correct string");
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Text(null !), "Text should throw exception when null");

            //translate
            Assert.AreEqual("{\"translate\":\"hel\\\"lo\",\"with\":[{\"text\":\"insert1\"},{\"text\":\"insert2\"}]}", new JsonText.Translate("hel\"lo", new BaseJsonText[] { new JsonText.Text("insert1"), new JsonText.Text("insert2") }).GetJsonString(), "Translate doesn't return correct string");
            Assert.AreEqual("{\"translate\":\"hello\"}", new JsonText.Translate("hello").GetJsonString(), "Translate doesn't return correct string when only translate is specified");
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Translate(null !), "Translate should throw exception if translate is null");

            //names
            Assert.AreEqual("{\"selector\":\"@a[name=\\\"Name\\\"]\"}", new JsonText.Names(new Selector(ID.Selector.a)
            {
                SingleName = "Name"
            }).GetJsonString(), "Names doesn't return correct string");
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Names(null !), "Names selector should throw exception if null");

            //keybind
            Assert.AreEqual("{\"keybind\":\"key.inventory\"}", new JsonText.KeyBind(ID.Key.inventory).GetJsonString(), "Keybind doesn't return correct string");

            //data
            Assert.AreEqual("{\"nbt\":\"test.t{a:\\\"hello\\\"}\",\"interpret\":true,\"entity\":\"@s[name=\\\"Name\\\"]\"}", new JsonText.Data(new EntityDataLocation(new Selector(ID.Selector.s)
            {
                SingleName = "Name"
            }, "test.t{a:\"hello\"}"), true).GetJsonString(), "Data entity doesn't return correct string");
            Assert.AreEqual("{\"nbt\":\"path\",\"interpret\":false,\"block\":\"~1 ~2 ~3\"}", new JsonText.Data(new BlockDataLocation(new Coords(1, 2, 3), "path"), false).GetJsonString(), "Data block doesn't return correct string");
            Assert.AreEqual("{\"nbt\":\"path\",\"interpret\":false,\"storage\":\"space:stor\"}", new JsonText.Data(new StorageDataLocation(new Storage(MockNamespace.GetNamespace("space"), "stor"), "path"), false).GetJsonString(), "Data storage doesn't return correct string");
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Data(null !, true), "Data should throw exception if location is null");

            //score
            Assert.AreEqual("{\"score\":{\"name\":\"@s[name=\\\"Name\\\"]\",\"objective\":\"test\"}}", new JsonText.Score(new Selector(ID.Selector.s)
            {
                SingleName = "Name"
            }, new Objective("test")).GetJsonString(), "Score doesn't return correct string");
            Assert.ThrowsException <ArgumentException>(() => new JsonText.Score(ID.Selector.e, new Objective("something")), "Score should throw exception is selector selects too many things");
            _ = new JsonText.Score(AllSelector.GetSelector(), new Objective("something"));
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Score(null !, new Objective("something")), "Score should throw exception if selector is null");
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Score(ID.Selector.s, null !), "Score should throw exception if objective is null");
        }