Ejemplo n.º 1
0
 public void TestQuotedStringDanglingEscape()
 {
     Assert.That(() =>
     {
         NbtJsonParser.Parse("\"hello \\ world\"");
     }, Throws.Exception);
 }
Ejemplo n.º 2
0
        public void TestUnquotedStringTag()
        {
            NbtString str = NbtJsonParser.Parse("hello_world") as NbtString;

            Assert.That(str, Is.Not.Null);
            Assert.That(str.Value, Is.EqualTo("hello_world"));
        }
Ejemplo n.º 3
0
        public void TestNbtListTag()
        {
            NbtList list = (NbtList)NbtJsonParser.Parse("[110f,40f]");

            Assert.That(list.Type, Is.Null, "Regular lists don't have types, only typed arrays");
            Assert.That(((NbtNumber <float>)list[0]).Value, Is.EqualTo(110f));
            Assert.That(((NbtNumber <float>)list[1]).Value, Is.EqualTo(40f));
        }
Ejemplo n.º 4
0
        public void TestNbtArrayTag()
        {
            NbtList array = (NbtList)NbtJsonParser.Parse("[L;32l,64l,128l]");

            Assert.That(array.Type, Is.EqualTo(typeof(long)));
            Assert.That(((NbtNumber <long>)array[0]).Value, Is.EqualTo((long)32));
            Assert.That(((NbtNumber <long>)array[1]).Value, Is.EqualTo((long)64));
            Assert.That(((NbtNumber <long>)array[2]).Value, Is.EqualTo((long)128));
        }
Ejemplo n.º 5
0
        public void TestNbtCompoundTag()
        {
            NbtCompoundTag nbt = (NbtCompoundTag)NbtJsonParser.Parse("{string1:test,string2:\"test\",byte:1b,int:2}");

            Assert.That(nbt.GetString("string1").Value, Is.EqualTo("test"));
            Assert.That(nbt.GetString("string2").Value, Is.EqualTo("test"));
            Assert.That(nbt.GetByte("byte").Value, Is.EqualTo((byte)1));
            Assert.That(nbt.GetInt("int").Value, Is.EqualTo(2));
        }
Ejemplo n.º 6
0
        public string Compile(BuildEnvironment env)
        {
            string path = env.GetPath(Id, "json");
            string file = File.ReadAllText(path);

            if (path.EndsWith(".nbt"))
            {
                // Treat as NBT JSON
                // Parse and recompile to put onto one line and ensure formatting is correct
                try
                {
                    object nbt         = NbtJsonParser.Parse(file);
                    string compiledNbt = nbt.ToString();

                    Logger.Debug($"Sucessfully parsed {Id} as NBT.");

                    return(compiledNbt);
                }
                catch (Exception e)
                {
                    Logger.Warning($"Resource {Id} isn't valid NBT! " + e.Message);
                }
            }
            else if (path.EndsWith(".json"))
            {
                // Treat as real JSON
                // Parse and recompile to put onto one line and ensure formatting is correct
                try
                {
                    object deserialized = JsonConvert.DeserializeObject(file);

                    string json = JsonConvert.SerializeObject(deserialized, Formatting.None);

                    Logger.Debug($"Sucessfully parsed {Id} as JSON.");

                    return(json);
                }
                catch (Exception e)
                {
                    Logger.Warning($"Resource {Id} isn't valid JSON! " + e.Message);
                }
            }

            return(file);
        }
Ejemplo n.º 7
0
        public void TestByteTag()
        {
            NbtNumber <byte> number = (NbtNumber <byte>)NbtJsonParser.Parse("1b");

            Assert.That(number.Value, Is.EqualTo((byte)1));
        }
Ejemplo n.º 8
0
        public void TestIntTag()
        {
            NbtNumber <int> number = (NbtNumber <int>)NbtJsonParser.Parse("10");

            Assert.That(number.Value, Is.EqualTo(10));
        }