126 lines
4.4 KiB
Dart
126 lines
4.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:libac_dart/nbt/NbtIo.dart';
|
|
import 'package:libac_dart/nbt/NbtUtils.dart';
|
|
import 'package:libac_dart/nbt/SnbtIo.dart';
|
|
import 'package:libac_dart/nbt/Stream.dart';
|
|
import 'package:libac_dart/nbt/Tag.dart';
|
|
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
|
import 'package:libac_dart/nbt/impl/StringTag.dart';
|
|
import 'package:libac_dart/utils/IOTools.dart';
|
|
import 'package:libac_dart/utils/uuid/NbtUUID.dart';
|
|
import 'package:libac_dart/utils/uuid/UUID.dart';
|
|
import 'package:test/expect.dart';
|
|
import 'package:test/scaffolding.dart';
|
|
|
|
void main() {
|
|
test('read non-compressed helloworld NBT', () async {
|
|
print("READING : ${Directory.current.path}/test/hello_world.nbt");
|
|
CompoundTag tag =
|
|
await NbtIo.read("${Directory.current.path}/test/hello_world.nbt");
|
|
expect(tag.getKey(), "hello world");
|
|
expect(tag.containsKey("name"), true);
|
|
|
|
expect(tag.get("name")!.asString(), "Bananrama");
|
|
});
|
|
|
|
test("write a hello-world NBT", () async {
|
|
CompoundTag tag = CompoundTag();
|
|
tag.setKey("hello world");
|
|
tag.put("name", StringTag.valueOf("Bananrama"));
|
|
|
|
var path = "${Directory.current.path}/build/hello_world.nbt";
|
|
await NbtIo.write(path, tag);
|
|
expect(File(path).existsSync(), true);
|
|
});
|
|
|
|
test('read non-compressed self-made helloworld NBT', () async {
|
|
print("READING : ${Directory.current.path}/build/hello_world.nbt");
|
|
CompoundTag tag =
|
|
await NbtIo.read("${Directory.current.path}/build/hello_world.nbt");
|
|
expect(tag.getKey(), "hello world");
|
|
expect(tag.containsKey("name"), true);
|
|
|
|
expect(tag.get("name")!.asString(), "Bananrama");
|
|
});
|
|
|
|
test('read compressed bigtest.nbt', () async {
|
|
var path = "${Directory.current.path}/test/bigtest.nbt";
|
|
CompoundTag tag = await NbtIo.read(path);
|
|
expect(tag.getKey(), "Level");
|
|
expect(tag.get("shortTest")!.asShort(), 32767);
|
|
expect(tag.get("doubleTest")!.asDouble(), 0.4931287132182315);
|
|
expect(tag.get("floatTest")!.asFloat(), 0.49823147);
|
|
});
|
|
|
|
test("Generate a UUID v4, save to NBT, and read it back again", () async {
|
|
var id = UUID.generate(4);
|
|
CompoundTag tag = CompoundTag();
|
|
NbtUtils.writeUUID(tag, "test", NbtUUID.fromUUID(id));
|
|
|
|
var newID = NbtUtils.readUUID(tag, "test");
|
|
expect(id.toString(), newID.toString());
|
|
});
|
|
|
|
test("Read HelloWorld, Output to SNBT", () async {
|
|
CompoundTag ct =
|
|
await NbtIo.read("${Directory.current.path}/test/hello_world.nbt");
|
|
StringBuilder sb = StringBuilder();
|
|
Tag.writeStringifiedNamedTag(ct, sb, 0);
|
|
print(sb.toString());
|
|
});
|
|
|
|
test("Read BigTest, Output to SNBT", () async {
|
|
CompoundTag ct =
|
|
await NbtIo.read("${Directory.current.path}/test/bigtest.nbt");
|
|
StringBuilder sb = StringBuilder();
|
|
Tag.writeStringifiedNamedTag(ct, sb, 0);
|
|
print(sb.toString());
|
|
});
|
|
|
|
test("Write BigTest to SNBT file", () async {
|
|
CompoundTag ct =
|
|
await NbtIo.read("${Directory.current.path}/test/bigtest.nbt");
|
|
String output = "${Directory.current.path}/build/bigtest.snbt";
|
|
File file = File(output);
|
|
SnbtIo.writeToFile(output, ct);
|
|
|
|
// Expect that the file exists
|
|
PathHelper ph = PathHelper.builder(Directory.current.path)
|
|
.resolve("build")
|
|
.resolve("bigtest.snbt");
|
|
expect(ph.exists(), true);
|
|
});
|
|
|
|
test("Read BigTest from SNBT file", () async {
|
|
CompoundTag tag = await SnbtIo.readFromFile(
|
|
"${Directory.current.path}/build/bigtest.snbt") as CompoundTag;
|
|
|
|
expect(tag.containsKey("stringTest"), true);
|
|
expect(tag.get("doubleTest")!.asDouble(), 0.4931287132182315);
|
|
});
|
|
|
|
test("Write NULL UUID to NBT", () async {
|
|
CompoundTag tag = CompoundTag();
|
|
NbtUtils.writeUUID(tag, "test", NbtUUID.fromUUID(UUID.ZERO));
|
|
NbtUUID ID = NbtUtils.readUUID(tag, "test");
|
|
|
|
expect(ID.MSB, 0);
|
|
expect(ID.LSB, 0);
|
|
});
|
|
|
|
test("Convert real-world NBT to SNBT and back to NBT", () async {
|
|
String OriginFile = "${Directory.current.path}/test/EL-ReducedList.dat";
|
|
String OutputSNBT = "${Directory.current.path}/build/el-test.snbt";
|
|
String OutputNBT = "${Directory.current.path}/build/el-test.nbt";
|
|
|
|
CompoundTag tag = await NbtIo.read(OriginFile);
|
|
await SnbtIo.writeToFile(OutputSNBT, tag);
|
|
|
|
expect(File(OutputSNBT).existsSync(), true);
|
|
tag = await SnbtIo.readFromFile(OutputSNBT) as CompoundTag;
|
|
|
|
await NbtIo.write(OutputNBT, tag);
|
|
expect(File(OutputNBT).existsSync(), true);
|
|
}, timeout: Timeout(Duration(hours: 90)));
|
|
}
|