Skip to content

Commit

Permalink
Fix kv commnets
Browse files Browse the repository at this point in the history
  • Loading branch information
robincodex committed Dec 3, 2024
1 parent 23f8c88 commit 36534cc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
10 changes: 10 additions & 0 deletions __tests__/KeyValues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,14 @@ describe('KeyValues', () => {
expect(root.FindIDTraverse(d.ID) === d).toBe(true);
expect(root.FindIDTraverse(e.ID) === e).toBe(true);
});

test('Check comments', async () => {
const kv = await KeyValues.Load(join(__dirname, 'KeyValues_comment1.txt'));
expect(kv.IsRoot()).toBe(true);
expect(kv.GetChildCount()).toBe(0);

const kv2 = await KeyValues.Load(join(__dirname, 'KeyValues_comment2.txt'));
expect(kv2.IsRoot()).toBe(true);
expect(kv2.GetChildCount()).toBe(1);
});
});
10 changes: 10 additions & 0 deletions __tests__/KeyValues_comment1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// #base "npc/file01.txt" // file01
// #base "npc/file02.txt" // file02
// "DOTAAbilities"
// {
// "ability01"
// {
// "BaseClass" "ability_datadriven"
// "AbilityBehavior" "DOTA_ABILITY_BEHAVIOR_POINT"
// }
// }
9 changes: 9 additions & 0 deletions __tests__/KeyValues_comment2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"DOTAAbilities"
{
"ability01"
{
"BaseClass" "ability_datadriven"
"AbilityBehavior" "DOTA_ABILITY_BEHAVIOR_POINT"
}
}
// test comment
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easy-keyvalues",
"version": "1.2.6",
"version": "1.2.7",
"description": "Parse Valve KeyValues Format and easy to use in nodejs or browser.",
"main": "dist/node.js",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easy-keyvalues",
"version": "1.2.6",
"version": "1.2.7",
"description": "Parse Valve KeyValues Format and easy to use in nodejs or browser.",
"main": "node.js",
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions src/KeyValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ export default class KeyValues {
}
if (data.body[data.pos + 1] === '/') {
const endIndex = data.body.indexOf('\n', data.pos + 1);
if (endIndex < 0) {
break;
}
const comment = data.body.slice(data.pos + 2, endIndex).trim();
if (comment) {
if (isEndOfLineComment) {
Expand Down

0 comments on commit 36534cc

Please sign in to comment.