// get the next int array, prefixed by array length (signed int, 4 bytes) public static NbtIntArray ParseNbtIntArray(NbtByteReader reader, bool parseName = true) { NbtIntArray intArray = new NbtIntArray(parseName ? ParseString(reader) : ""); int arrayLength = reader.ReadInt(); for (int i = 0; i < arrayLength; i++) { intArray.Value.Add(reader.ReadInt()); } return(intArray); }
public static int[] getIntArray(this NbtCompound tag, string name) { NbtIntArray tag1 = tag.Get <NbtIntArray>(name); if (tag1 == null) { return(new int[0]); } else { return(tag1.Value); } }
public void IntArrayIndexerTest() { // test getting/settings values of int array tag via indexer var byteArray = new NbtIntArray("Test"); CollectionAssert.AreEqual(byteArray.Value, new int[0]); byteArray.Value = new int[] { 1, 2000, -3000000 }; Assert.AreEqual(byteArray[0], 1); Assert.AreEqual(byteArray[1], 2000); Assert.AreEqual(byteArray[2], -3000000); byteArray[0] = 4; Assert.AreEqual(byteArray[0], 4); }
public void IntArrayIndexerTest() { // test getting/settings values of int array tag via indexer var intArray = new NbtIntArray("Test"); CollectionAssert.AreEqual(new int[0], intArray.Value); intArray.Value = new[] { 1, 2000, -3000000 }; Assert.AreEqual(1, intArray[0]); Assert.AreEqual(2000, intArray[1]); Assert.AreEqual(-3000000, intArray[2]); intArray[0] = 4; Assert.AreEqual(4, intArray[0]); }
public void NbtIntArrayTest() { object dummy; int[] ints = { 1111, 2222, 3333, 4444, 5555 }; NbtTag test = new NbtIntArray(ints); Assert.Throws <InvalidCastException>(() => dummy = test.ByteArrayValue); Assert.Throws <InvalidCastException>(() => dummy = test.ByteValue); Assert.Throws <InvalidCastException>(() => dummy = test.DoubleValue); Assert.Throws <InvalidCastException>(() => dummy = test.FloatValue); CollectionAssert.AreEqual(ints, test.IntArrayValue); Assert.Throws <InvalidCastException>(() => dummy = test.IntValue); Assert.Throws <InvalidCastException>(() => dummy = test.LongValue); Assert.Throws <InvalidCastException>(() => dummy = test.ShortValue); Assert.Throws <InvalidCastException>(() => dummy = test.StringValue); }
public static void EditArray(Rect buttonRect, NbtIntArray intArray) { NbtMassArrayEdit win = ScriptableObject.CreateInstance <NbtMassArrayEdit>(); win.titleContent = new GUIContent("Int Array"); win.intTag = intArray; StringBuilder sb = new StringBuilder(); for (int i = 0; i < intArray.Value.Length; i++) { if (i != 0) { sb.Append(" "); } sb.Append(intArray.Value[i]); } win.text = sb.ToString(); win.ShowAsDropDown(buttonRect, new Vector2(256, 128)); }
private void InputForm_FormClosing(object sender, FormClosingEventArgs e) { if (this.DialogResult == DialogResult.OK) { string[] text = this.textBox1.Lines; if (!ValidateInput(text)) { textBox1.ForeColor = Color.Tomato;//TODO find a better color button1.Enabled = false; e.Cancel = true; (new AlertForm("The input is invalid!") { Icon = SystemIcons.Error, Text = "Invalid input!" }).ShowDialog(); } else { NBTTag = new NbtIntArray(NBTTag.Name, MainClass.StringToIntArray(text)); } return; } }
public IntArrayByteProvider(NbtIntArray tag) : base(tag) { }
public void CopyConstructorTest() { NbtByte byteTag = new NbtByte("byteTag", 1); NbtByte byteTagClone = (NbtByte)byteTag.Clone(); Assert.AreNotSame(byteTag, byteTagClone); Assert.AreEqual(byteTag.Name, byteTagClone.Name); Assert.AreEqual(byteTag.Value, byteTagClone.Value); Assert.Throws <ArgumentNullException>(() => new NbtByte((NbtByte)null)); NbtByteArray byteArrTag = new NbtByteArray("byteArrTag", new byte[] { 1, 2, 3, 4 }); NbtByteArray byteArrTagClone = (NbtByteArray)byteArrTag.Clone(); Assert.AreNotSame(byteArrTag, byteArrTagClone); Assert.AreEqual(byteArrTag.Name, byteArrTagClone.Name); Assert.AreNotSame(byteArrTag.Value, byteArrTagClone.Value); CollectionAssert.AreEqual(byteArrTag.Value, byteArrTagClone.Value); Assert.Throws <ArgumentNullException>(() => new NbtByteArray((NbtByteArray)null)); NbtCompound compTag = new NbtCompound("compTag", new NbtTag[] { new NbtByte("innerTag", 1) }); NbtCompound compTagClone = (NbtCompound)compTag.Clone(); Assert.AreNotSame(compTag, compTagClone); Assert.AreEqual(compTag.Name, compTagClone.Name); Assert.AreNotSame(compTag["innerTag"], compTagClone["innerTag"]); Assert.AreEqual(compTag["innerTag"].Name, compTagClone["innerTag"].Name); Assert.AreEqual(compTag["innerTag"].ByteValue, compTagClone["innerTag"].ByteValue); Assert.Throws <ArgumentNullException>(() => new NbtCompound((NbtCompound)null)); NbtDouble doubleTag = new NbtDouble("doubleTag", 1); NbtDouble doubleTagClone = (NbtDouble)doubleTag.Clone(); Assert.AreNotSame(doubleTag, doubleTagClone); Assert.AreEqual(doubleTag.Name, doubleTagClone.Name); Assert.AreEqual(doubleTag.Value, doubleTagClone.Value); Assert.Throws <ArgumentNullException>(() => new NbtDouble((NbtDouble)null)); NbtFloat floatTag = new NbtFloat("floatTag", 1); NbtFloat floatTagClone = (NbtFloat)floatTag.Clone(); Assert.AreNotSame(floatTag, floatTagClone); Assert.AreEqual(floatTag.Name, floatTagClone.Name); Assert.AreEqual(floatTag.Value, floatTagClone.Value); Assert.Throws <ArgumentNullException>(() => new NbtFloat((NbtFloat)null)); NbtInt intTag = new NbtInt("intTag", 1); NbtInt intTagClone = (NbtInt)intTag.Clone(); Assert.AreNotSame(intTag, intTagClone); Assert.AreEqual(intTag.Name, intTagClone.Name); Assert.AreEqual(intTag.Value, intTagClone.Value); Assert.Throws <ArgumentNullException>(() => new NbtInt((NbtInt)null)); NbtIntArray intArrTag = new NbtIntArray("intArrTag", new[] { 1, 2, 3, 4 }); NbtIntArray intArrTagClone = (NbtIntArray)intArrTag.Clone(); Assert.AreNotSame(intArrTag, intArrTagClone); Assert.AreEqual(intArrTag.Name, intArrTagClone.Name); Assert.AreNotSame(intArrTag.Value, intArrTagClone.Value); CollectionAssert.AreEqual(intArrTag.Value, intArrTagClone.Value); Assert.Throws <ArgumentNullException>(() => new NbtIntArray((NbtIntArray)null)); NbtList listTag = new NbtList("listTag", new NbtTag[] { new NbtByte(1) }); NbtList listTagClone = (NbtList)listTag.Clone(); Assert.AreNotSame(listTag, listTagClone); Assert.AreEqual(listTag.Name, listTagClone.Name); Assert.AreNotSame(listTag[0], listTagClone[0]); Assert.AreEqual(listTag[0].ByteValue, listTagClone[0].ByteValue); Assert.Throws <ArgumentNullException>(() => new NbtList((NbtList)null)); NbtLong longTag = new NbtLong("longTag", 1); NbtLong longTagClone = (NbtLong)longTag.Clone(); Assert.AreNotSame(longTag, longTagClone); Assert.AreEqual(longTag.Name, longTagClone.Name); Assert.AreEqual(longTag.Value, longTagClone.Value); Assert.Throws <ArgumentNullException>(() => new NbtLong((NbtLong)null)); NbtShort shortTag = new NbtShort("shortTag", 1); NbtShort shortTagClone = (NbtShort)shortTag.Clone(); Assert.AreNotSame(shortTag, shortTagClone); Assert.AreEqual(shortTag.Name, shortTagClone.Name); Assert.AreEqual(shortTag.Value, shortTagClone.Value); Assert.Throws <ArgumentNullException>(() => new NbtShort((NbtShort)null)); NbtString stringTag = new NbtString("stringTag", "foo"); NbtString stringTagClone = (NbtString)stringTag.Clone(); Assert.AreNotSame(stringTag, stringTagClone); Assert.AreEqual(stringTag.Name, stringTagClone.Name); Assert.AreEqual(stringTag.Value, stringTagClone.Value); Assert.Throws <ArgumentNullException>(() => new NbtString((NbtString)null)); }
/// <summary> /// Writes out the specified tag. /// </summary> /// <param name="tag">The tag.</param> /// <exception cref="System.ArgumentNullException"><paramref name="tag"/> is <c>null</c>.</exception> /// <exception cref="System.ObjectDisposedException">The stream is closed.</exception> /// <exception cref="System.IO.IOException">An I/O error occured.</exception> public void Write(NbtIntArray tag) { if (tag == null) throw new ArgumentNullException("tag", "tag is null."); Write(tag, true); }
public static NbtTag TreeToNBT(TreeNodeCollection tree) { NbtTag NBTTag = null; if (tree != null) { foreach (TreeNode node in tree) { string value = node.Text.Replace($"{node.Name}: ", string.Empty).Replace(".", ",");//TODO , or . by language try { switch (node.ImageKey) { case "buttonstring.png": { NBTTag = new NbtString(node.Name, value); break; } case "buttonint.png": { NBTTag = new NbtInt(node.Name, int.Parse(value)); break; } case "buttonbyte.png": { NBTTag = new NbtByte(node.Name, byte.Parse(value)); break; } case "buttonlong.png": { NBTTag = new NbtLong(node.Name, long.Parse(value)); break; } case "buttonshort.png": { NBTTag = new NbtShort(node.Name, short.Parse(value)); break; } case "buttonfloat.png": { NBTTag = new NbtFloat(node.Name, float.Parse(value)); break; } case "buttondouble.png": { NBTTag = new NbtDouble(node.Name, double.Parse(value)); break; } case "buttoncompound.png": { NBTTag = new NbtCompound(node.Name); foreach (object c in node.Nodes) { (new AlertForm(c.ToString())).ShowDialog(); if (c is TreeNode && ((TreeNode)c).Nodes.Count > 0) { ((NbtCompound)NBTTag).Add(TreeToNBT(((TreeNode)c).Nodes)); } else { (new AlertForm(c.GetType().ToString())).ShowDialog(); } } break; } case "buttonlist.png": { NBTTag = new NbtList(node.Name); foreach (object c in node.Nodes) { (new AlertForm(c.ToString())).ShowDialog(); if (c is TreeNode && ((TreeNode)c).Nodes.Count > 0) { ((NbtList)NBTTag).Add(TreeToNBT(((TreeNode)c).Nodes)); } else { (new AlertForm(c.GetType().ToString())).ShowDialog(); } } break; } case "buttonbytearray.png": { NBTTag = new NbtByteArray(node.Name, NodesToByteArray(node.Nodes)); (new AlertForm(NBTTag.ToString())).ShowDialog(); break; } case "buttonintarray.png": { NBTTag = new NbtIntArray(node.Name, NodesToIntArray(node.Nodes)); (new AlertForm(NBTTag.ToString())).ShowDialog(); break; } default: { throw new WarningException($"Warning: unhandeled node {node.ImageKey} can not be edited"); } } } catch (Exception exception) { if (exception is InvalidOperationException || exception is WarningException) { new AlertForm(exception.ToString()) { Text = "Warning!", Icon = System.Drawing.SystemIcons.Warning }.ShowDialog(); } else { new AlertForm(exception.ToString()) { Text = exception.GetType().ToString(), Icon = System.Drawing.SystemIcons.Error }.ShowDialog(); } } } } return(NBTTag); }
public InputIntArrayTagForm(NbtIntArray tag) { InitializeComponent(); NBTTag = tag; }
internal void Write(NbtIntArray tag, bool writeHeader) { Write(tag.Name, tag.Value, writeHeader); }
public void NbtIntArrayTest() { object dummy; int[] ints = new[] { 1111, 2222, 3333, 4444, 5555 }; NbtTag test = new NbtIntArray( ints ); Assert.Throws<InvalidCastException>( () => dummy = test.ByteArrayValue ); Assert.Throws<InvalidCastException>( () => dummy = test.ByteValue ); Assert.Throws<InvalidCastException>( () => dummy = test.DoubleValue ); Assert.Throws<InvalidCastException>( () => dummy = test.FloatValue ); CollectionAssert.AreEqual( ints, test.IntArrayValue ); Assert.Throws<InvalidCastException>( () => dummy = test.IntValue ); Assert.Throws<InvalidCastException>( () => dummy = test.LongValue ); Assert.Throws<InvalidCastException>( () => dummy = test.ShortValue ); Assert.Throws<InvalidCastException>( () => dummy = test.StringValue ); }
void AssertNbtBigFile(NbtFile file) { // See TestFiles/bigtest.nbt.txt to see the expected format Assert.IsInstanceOf <NbtCompound>(file.RootTag); NbtCompound root = file.RootTag; Assert.AreEqual("Level", root.Name); Assert.AreEqual(12, root.Count); Assert.IsInstanceOf <NbtLong>(root["longTest"]); NbtTag node = root["longTest"]; Assert.AreEqual("longTest", node.Name); Assert.AreEqual(9223372036854775807, ((NbtLong)node).Value); Assert.IsInstanceOf <NbtShort>(root["shortTest"]); node = root["shortTest"]; Assert.AreEqual("shortTest", node.Name); Assert.AreEqual(32767, ((NbtShort)node).Value); Assert.IsInstanceOf <NbtString>(root["stringTest"]); node = root["stringTest"]; Assert.AreEqual("stringTest", node.Name); Assert.AreEqual("HELLO WORLD THIS IS A TEST STRING ÅÄÖ!", ((NbtString)node).Value); Assert.IsInstanceOf <NbtFloat>(root["floatTest"]); node = root["floatTest"]; Assert.AreEqual("floatTest", node.Name); Assert.AreEqual(0.49823147f, ((NbtFloat)node).Value); Assert.IsInstanceOf <NbtInt>(root["intTest"]); node = root["intTest"]; Assert.AreEqual("intTest", node.Name); Assert.AreEqual(2147483647, ((NbtInt)node).Value); Assert.IsInstanceOf <NbtCompound>(root["nested compound test"]); node = root["nested compound test"]; Assert.AreEqual("nested compound test", node.Name); Assert.AreEqual(2, ((NbtCompound)node).Count); // First nested test Assert.IsInstanceOf <NbtCompound>(node["ham"]); NbtCompound subNode = (NbtCompound)node["ham"]; Assert.AreEqual("ham", subNode.Name); Assert.AreEqual(2, subNode.Count); // Checking sub node values Assert.IsInstanceOf <NbtString>(subNode["name"]); Assert.AreEqual("name", subNode["name"].Name); Assert.AreEqual("Hampus", ((NbtString)subNode["name"]).Value); Assert.IsInstanceOf <NbtFloat>(subNode["value"]); Assert.AreEqual("value", subNode["value"].Name); Assert.AreEqual(0.75, ((NbtFloat)subNode["value"]).Value); // End sub node // Second nested test Assert.IsInstanceOf <NbtCompound>(node["egg"]); subNode = (NbtCompound)node["egg"]; Assert.AreEqual("egg", subNode.Name); Assert.AreEqual(2, subNode.Count); // Checking sub node values Assert.IsInstanceOf <NbtString>(subNode["name"]); Assert.AreEqual("name", subNode["name"].Name); Assert.AreEqual("Eggbert", ((NbtString)subNode["name"]).Value); Assert.IsInstanceOf <NbtFloat>(subNode["value"]); Assert.AreEqual("value", subNode["value"].Name); Assert.AreEqual(0.5, ((NbtFloat)subNode["value"]).Value); // End sub node Assert.IsInstanceOf <NbtList>(root["listTest (long)"]); node = root["listTest (long)"]; Assert.AreEqual("listTest (long)", node.Name); Assert.AreEqual(5, ((NbtList)node).Count); // The values should be: 11, 12, 13, 14, 15 for (int nodeIndex = 0; nodeIndex < ((NbtList)node).Count; nodeIndex++) { Assert.IsInstanceOf <NbtLong>(node[nodeIndex]); Assert.AreEqual(null, node[nodeIndex].Name); Assert.AreEqual(nodeIndex + 11, ((NbtLong)node[nodeIndex]).Value); } Assert.IsInstanceOf <NbtList>(root["listTest (compound)"]); node = root["listTest (compound)"]; Assert.AreEqual("listTest (compound)", node.Name); Assert.AreEqual(2, ((NbtList)node).Count); // First Sub Node Assert.IsInstanceOf <NbtCompound>(node[0]); subNode = (NbtCompound)node[0]; // First node in sub node Assert.IsInstanceOf <NbtString>(subNode["name"]); Assert.AreEqual("name", subNode["name"].Name); Assert.AreEqual("Compound tag #0", ((NbtString)subNode["name"]).Value); // Second node in sub node Assert.IsInstanceOf <NbtLong>(subNode["created-on"]); Assert.AreEqual("created-on", subNode["created-on"].Name); Assert.AreEqual(1264099775885, ((NbtLong)subNode["created-on"]).Value); // Second Sub Node Assert.IsInstanceOf <NbtCompound>(node[1]); subNode = (NbtCompound)node[1]; // First node in sub node Assert.IsInstanceOf <NbtString>(subNode["name"]); Assert.AreEqual("name", subNode["name"].Name); Assert.AreEqual("Compound tag #1", ((NbtString)subNode["name"]).Value); // Second node in sub node Assert.IsInstanceOf <NbtLong>(subNode["created-on"]); Assert.AreEqual("created-on", subNode["created-on"].Name); Assert.AreEqual(1264099775885, ((NbtLong)subNode["created-on"]).Value); Assert.IsInstanceOf <NbtByte>(root["byteTest"]); node = root["byteTest"]; Assert.AreEqual("byteTest", node.Name); Assert.AreEqual(127, ((NbtByte)node).Value); const string byteArrayName = "byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))"; Assert.IsInstanceOf <NbtByteArray>(root[byteArrayName]); node = root[byteArrayName]; Assert.AreEqual(byteArrayName, node.Name); Assert.AreEqual(1000, ((NbtByteArray)node).Value.Length); // Values are: the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...) for (int n = 0; n < 1000; n++) { Assert.AreEqual((n * n * 255 + n * 7) % 100, ((NbtByteArray)node)[n]); } Assert.IsInstanceOf <NbtDouble>(root["doubleTest"]); node = root["doubleTest"]; Assert.AreEqual("doubleTest", node.Name); Assert.AreEqual(0.4931287132182315, ((NbtDouble)node).Value); Assert.IsInstanceOf <NbtIntArray>(root["intArrayTest"]); NbtIntArray intArrayTag = root.Get <NbtIntArray>("intArrayTest"); Assert.IsNotNull(intArrayTag); Random rand = new Random(0); for (int i = 0; i < 10; i++) { Assert.AreEqual(intArrayTag.Value[i], rand.Next()); } }
public static string ToSnbt(this NbtIntArray tag, SnbtOptions options) { return(ListToString("" + INT_ARRAY_PREFIX + ARRAY_DELIMITER, x => x.ToString(), tag.Value, options)); }
public void Write_IntArrayTag() { // Arrange MemoryStream stream = new MemoryStream(); NbtWriter writer = new NbtWriter(stream); NbtIntArray tag = new NbtIntArray("asdf", new int[] { 12345, 1337, 123456789, 55555555 }); byte[] expected = new byte[] { 0x0B, 0x00, 0x04, 0x61, 0x73, 0x64, 0x66, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x30, 0x39, 0x00, 0x00, 0x05, 0x39, 0x07, 0x5B, 0xCD, 0x15, 0x03, 0x4F, 0xB5, 0xE3 }; // Act writer.Write(tag); byte[] result = stream.ToArray(); // Assert CollectionAssert.AreEqual(expected, result); }
public void CopyConstructorTest() { NbtByte byteTag = new NbtByte("byteTag", 1); NbtByte byteTagClone = (NbtByte)byteTag.Clone(); Assert.AreNotSame(byteTag, byteTagClone); Assert.AreEqual(byteTag.Name, byteTagClone.Name); Assert.AreEqual(byteTag.Value, byteTagClone.Value); Assert.Throws<ArgumentNullException>(() => new NbtByte((NbtByte)null)); NbtByteArray byteArrTag = new NbtByteArray("byteArrTag", new byte[] { 1, 2, 3, 4 }); NbtByteArray byteArrTagClone = (NbtByteArray)byteArrTag.Clone(); Assert.AreNotSame(byteArrTag, byteArrTagClone); Assert.AreEqual(byteArrTag.Name, byteArrTagClone.Name); Assert.AreNotSame(byteArrTag.Value, byteArrTagClone.Value); CollectionAssert.AreEqual(byteArrTag.Value, byteArrTagClone.Value); Assert.Throws<ArgumentNullException>(() => new NbtByteArray((NbtByteArray)null)); NbtCompound compTag = new NbtCompound("compTag", new NbtTag[] { new NbtByte("innerTag", 1) }); NbtCompound compTagClone = (NbtCompound)compTag.Clone(); Assert.AreNotSame(compTag, compTagClone); Assert.AreEqual(compTag.Name, compTagClone.Name); Assert.AreNotSame(compTag["innerTag"], compTagClone["innerTag"]); Assert.AreEqual(compTag["innerTag"].Name, compTagClone["innerTag"].Name); Assert.AreEqual(compTag["innerTag"].ByteValue, compTagClone["innerTag"].ByteValue); Assert.Throws<ArgumentNullException>(() => new NbtCompound((NbtCompound)null)); NbtDouble doubleTag = new NbtDouble("doubleTag", 1); NbtDouble doubleTagClone = (NbtDouble)doubleTag.Clone(); Assert.AreNotSame(doubleTag, doubleTagClone); Assert.AreEqual(doubleTag.Name, doubleTagClone.Name); Assert.AreEqual(doubleTag.Value, doubleTagClone.Value); Assert.Throws<ArgumentNullException>(() => new NbtDouble((NbtDouble)null)); NbtFloat floatTag = new NbtFloat("floatTag", 1); NbtFloat floatTagClone = (NbtFloat)floatTag.Clone(); Assert.AreNotSame(floatTag, floatTagClone); Assert.AreEqual(floatTag.Name, floatTagClone.Name); Assert.AreEqual(floatTag.Value, floatTagClone.Value); Assert.Throws<ArgumentNullException>(() => new NbtFloat((NbtFloat)null)); NbtInt intTag = new NbtInt("intTag", 1); NbtInt intTagClone = (NbtInt)intTag.Clone(); Assert.AreNotSame(intTag, intTagClone); Assert.AreEqual(intTag.Name, intTagClone.Name); Assert.AreEqual(intTag.Value, intTagClone.Value); Assert.Throws<ArgumentNullException>(() => new NbtInt((NbtInt)null)); NbtIntArray intArrTag = new NbtIntArray("intArrTag", new[] { 1, 2, 3, 4 }); NbtIntArray intArrTagClone = (NbtIntArray)intArrTag.Clone(); Assert.AreNotSame(intArrTag, intArrTagClone); Assert.AreEqual(intArrTag.Name, intArrTagClone.Name); Assert.AreNotSame(intArrTag.Value, intArrTagClone.Value); CollectionAssert.AreEqual(intArrTag.Value, intArrTagClone.Value); Assert.Throws<ArgumentNullException>(() => new NbtIntArray((NbtIntArray)null)); NbtList listTag = new NbtList("listTag", new NbtTag[] { new NbtByte(1) }); NbtList listTagClone = (NbtList)listTag.Clone(); Assert.AreNotSame(listTag, listTagClone); Assert.AreEqual(listTag.Name, listTagClone.Name); Assert.AreNotSame(listTag[0], listTagClone[0]); Assert.AreEqual(listTag[0].ByteValue, listTagClone[0].ByteValue); Assert.Throws<ArgumentNullException>(() => new NbtList((NbtList)null)); NbtLong longTag = new NbtLong("longTag", 1); NbtLong longTagClone = (NbtLong)longTag.Clone(); Assert.AreNotSame(longTag, longTagClone); Assert.AreEqual(longTag.Name, longTagClone.Name); Assert.AreEqual(longTag.Value, longTagClone.Value); Assert.Throws<ArgumentNullException>(() => new NbtLong((NbtLong)null)); NbtShort shortTag = new NbtShort("shortTag", 1); NbtShort shortTagClone = (NbtShort)shortTag.Clone(); Assert.AreNotSame(shortTag, shortTagClone); Assert.AreEqual(shortTag.Name, shortTagClone.Name); Assert.AreEqual(shortTag.Value, shortTagClone.Value); Assert.Throws<ArgumentNullException>(() => new NbtShort((NbtShort)null)); NbtString stringTag = new NbtString("stringTag", "foo"); NbtString stringTagClone = (NbtString)stringTag.Clone(); Assert.AreNotSame(stringTag, stringTagClone); Assert.AreEqual(stringTag.Name, stringTagClone.Name); Assert.AreEqual(stringTag.Value, stringTagClone.Value); Assert.Throws<ArgumentNullException>(() => new NbtString((NbtString)null)); }
public void IntArrayIndexerTest() { // test getting/settings values of int array tag via indexer var intArray = new NbtIntArray("Test"); CollectionAssert.AreEqual(new int[0], intArray.Value); intArray.Value = new[] { 1, 2000, -3000000 }; Assert.AreEqual(1, intArray[0]); Assert.AreEqual(2000, intArray[1]); Assert.AreEqual(-3000000, intArray[2]); intArray[0] = 4; Assert.AreEqual(4, intArray[0]); }