58 lines
2 KiB
Dart
58 lines
2 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:libac_flutter/nbt/NbtIo.dart';
|
|
import 'package:libac_flutter/nbt/NbtUtils.dart';
|
|
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
|
import 'package:libac_flutter/nbt/impl/StringTag.dart';
|
|
import 'package:libac_flutter/utils/uuid/UUID.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.contains("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.contains("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", id);
|
|
|
|
var newID = NbtUtils.readUUID(tag, "test");
|
|
expect(id.toString(), newID.toString());
|
|
});
|
|
}
|