-
Notifications
You must be signed in to change notification settings - Fork 2
Add support for newline separated SNBTs #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Taskeren
wants to merge
8
commits into
HMCL-dev:main
Choose a base branch
from
Taskeren:newline-snbt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
366fe1a
Add support for newline separated SNBTs
Taskeren 9cb6248
Add license notice in new files
Taskeren 7ac2176
Replace the test case
Taskeren 3482a9f
Fix incorrect peeked value stored in lookahead
Taskeren da2dba0
Remove delegate constructor
Taskeren 898724d
Fix hashCode and equals for new-added allowNewLineAsSeparator
Taskeren 9c3ca71
Fix the peeking again, all test passed
Taskeren 03fd05b
More tests
Taskeren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ enum SimpleToken implements Token { | |
| COMMA, // , | ||
| COLON, // : | ||
| DOT, // . | ||
| NEW_LINE, // \n | ||
| EOF | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright 2026 Taskeren | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.glavo.nbt.io; | ||
|
|
||
| import org.glavo.nbt.TestResources; | ||
| import org.glavo.nbt.tag.CompoundTag; | ||
| import org.glavo.nbt.tag.IntTag; | ||
| import org.glavo.nbt.tag.ListTag; | ||
| import org.glavo.nbt.tag.TagType; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
|
|
||
| public final class SNBTCodecTest { | ||
|
|
||
| @Test | ||
| void testNewLineSeparatedSNBT() throws IOException { | ||
| Path resource = TestResources.getResource("/assets/nbt/newline_separated.snbt"); | ||
| // expected failure | ||
| // the vanilla-flavored SNBT should not split compounds and lists with '\n'. | ||
| Assertions.assertThrows( | ||
| IOException.class, () -> { | ||
| try (var reader = Files.newBufferedReader(resource, StandardCharsets.UTF_8)) { | ||
| SNBTCodec.of().readTag(reader); | ||
| } | ||
| }); | ||
|
|
||
| try (var reader = Files.newBufferedReader(resource, StandardCharsets.UTF_8)) { | ||
| var tag = SNBTCodec.of().withAllowNewLineAsSeparator(true).readTag(reader); | ||
| var compound = assertInstanceOf(CompoundTag.class, tag); | ||
| assertEquals("Foo", compound.getString("name")); | ||
| // check list | ||
| var list = assertInstanceOf(ListTag.class, compound.get("list")); | ||
| assert list != null : "ensured by assertInstanceOf"; | ||
| assertEquals(TagType.INT, list.getElementType()); | ||
| assertEquals(new ListTag<>(TagType.INT).setName("list") | ||
| .addTag(new IntTag(1)) | ||
| .addTag(new IntTag(2)) | ||
| .addTag(new IntTag(3)) | ||
| .addTag(new IntTag(4)), list); | ||
| // check compound | ||
| var strDict = assertInstanceOf(CompoundTag.class, compound.get("str_dict")); | ||
| assertEquals(new CompoundTag() | ||
| .setName("str_dict") | ||
| .setString("a", "foo") | ||
| .setString("b", "bar") | ||
| .setString("c", "baz") | ||
| .setString("d", "Hello\nWorld") | ||
| .setIntArray("e", new int[] {-886784530, 1488270925, -1459824571, -372109282}) | ||
| .setBoolean("f", true), strDict); | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| name: "Foo" | ||
| list: [ | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| ] | ||
| str_dict: { | ||
| a: foo | ||
| b: bar | ||
| c: baz | ||
| d: "Hello | ||
| World" | ||
| e: uuid(cb24bdee-58b5-364d-a8fc-d845e9d2101e) | ||
| f: bool(1) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.