This commit is contained in:
Ulf Gebhardt 2023-04-10 17:03:40 +02:00
parent eae920f21f
commit 34723fa167
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
16 changed files with 4267 additions and 73 deletions

35
jest.config.js Normal file
View File

@ -0,0 +1,35 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
// eslint-disable-next-line import/no-commonjs, import/unambiguous
module.exports = {
verbose: true,
preset: 'ts-jest',
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!build/**'],
coverageThreshold: {
global: {
lines: 100,
},
},
// setupFiles: ['<rootDir>/test/testSetup.ts'],
// setupFilesAfterEnv: ['<rootDir>/test/extensions.ts'],
modulePathIgnorePatterns: ['<rootDir>/build/'],
/*moduleNameMapper: {
'@/(.*)': '<rootDir>/src/$1',
'@arg/(.*)': '<rootDir>/src/graphql/arg/$1',
'@enum/(.*)': '<rootDir>/src/graphql/enum/$1',
'@model/(.*)': '<rootDir>/src/graphql/model/$1',
'@union/(.*)': '<rootDir>/src/graphql/union/$1',
'@repository/(.*)': '<rootDir>/src/typeorm/repository/$1',
'@test/(.*)': '<rootDir>/test/$1',
'@entity/(.*)':
// eslint-disable-next-line n/no-process-env
process.env.NODE_ENV === 'development'
? '<rootDir>/../database/entity/$1'
: '<rootDir>/../database/build/entity/$1',
'@dbTools/(.*)':
// eslint-disable-next-line n/no-process-env
process.env.NODE_ENV === 'development'
? '<rootDir>/../database/src/$1'
: '<rootDir>/../database/build/src/$1',
},*/
}

3712
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
"description": "World Of Warcraft addon toc file parser",
"main": "lib/index.js",
"scripts": {
"test": "node node_modules/mocha/bin/_mocha -R spec",
"test": "jest",
"build": "tsc"
},
"repository": {
@ -24,9 +24,12 @@
},
"homepage": "https://github.com/zekesonxx/wow-toc",
"devDependencies": {
"@types/jest": "^29.5.0",
"@types/node": "^18.15.11",
"jest": "^29.5.0",
"mocha": "^1.21.4",
"should": "^4.0.4",
"ts-jest": "^29.1.0",
"typescript": "^5.0.4"
}
}

439
src/index.test.ts Normal file
View File

@ -0,0 +1,439 @@
import { open } from 'fs/promises';
import { TOC, parse } from './'
describe('parse TOC', () => {
describe('empty file', () => {
it('returns empty TOC object', async () => {
const file = await open(__dirname + '/../test/fixtures/empty.toc', 'r');
const toc = await parse(file)
expect(toc).toEqual(new TOC())
})
})
describe('basic file', () => {
it('returns basic TOC object', async () => {
const file = await open(__dirname + '/../test/fixtures/basic.toc', 'r');
const toc = await parse(file)
expect(toc).toEqual({
AddonCompartmentFunc: null,
AddonCompartmentFuncOnEnter: null,
AddonCompartmentFuncOnLeave: null,
Author: null,
DefaultState: true,
Dependencies: [],
IconAtlas: null,
IconTexture: null,
Interface: 50400,
LoadManagers: [],
LoadOnDemand: false,
LoadWith: [],
Notes: "\"Just basic\"",
NotesLocalized: {},
OptionalDeps: [],
SavedVariables: [],
SavedVariablesPerCharacter: [],
Title: "Basic Toc File",
TitleLocalized: {},
Version: "4.2",
files: [
"Dornhoeschen.xml",
"Rapunzel.lua",
],
xTags: {},
})
})
})
describe('complete file', () => {
it('returns complete TOC object', async () => {
const file = await open(__dirname + '/../test/fixtures/complete.toc', 'r');
const toc = await parse(file)
expect(toc).toEqual({
"AddonCompartmentFunc": "Func1",
"AddonCompartmentFuncOnEnter": "Func2",
"AddonCompartmentFuncOnLeave": "Func3",
"Author": "ulfgebhardt",
"DefaultState": false,
"Dependencies": [
"Lib1",
"Lib2",
"Lib3",
],
"IconAtlas": "IconB",
"IconTexture": "IconA",
"Interface": 123,
"LoadManagers": [
"Addon1",
"Addon2",
"Addon3",
],
"LoadOnDemand": true,
"LoadWith": [
"AddonA",
"AddonB",
"AddonC",
],
"Notes": "Describes the full Toc API",
"NotesLocalized": {
"deDE": "Notes deDE",
"enGB": "Notes enGB",
"enUS": "Notes enUS",
"esES": "Notes esES",
"esMX": "Notes esMX",
"frFR": "Notes frFR",
"itIT": "Notes itIT",
"koKR": "Notes koKR",
"ptBR": "Notes ptBR",
"ruRU": "Notes ruRU",
"zhCN": "Notes zhCN",
"zhTW": "Notes zhTW",
},
"OptionalDeps": [
"LibA",
"LibB",
"LibC",
],
"SavedVariables": [
"Var1",
"Var2",
"Var3",
],
"SavedVariablesPerCharacter": [
"CVar1",
"CVar2",
"CVar3",
],
"Title": "Complete Toc File",
"TitleLocalized": {
"deDE": "Title deDE",
"enGB": "Title enGB",
"enUS": "Title enUS",
"esES": "Title esES",
"esMX": "Title esMX",
"frFR": "Title frFR",
"itIT": "Title itIT",
"koKR": "Title koKR",
"ptBR": "Title ptBR",
"ruRU": "Title ruRU",
"zhCN": "Title zhCN",
"zhTW": "Title zhTW",
},
"Version": "456",
"files": [
"Dornhoeschen.xml",
"Rapunzel.lua",
],
"xTags": {
"Tag": "XTag",
}
})
})
})
describe('Recount file', () => {
it('returns Recount TOC object', async () => {
const file = await open(__dirname + '/../test/fixtures/Recount.toc', 'r');
const toc = await parse(file)
expect(toc).toEqual({
AddonCompartmentFunc: null,
AddonCompartmentFuncOnEnter: null,
AddonCompartmentFuncOnLeave: null,
Author: "Cryect, ported to 2.4 by Elsia, maintained by Resike from 5.4",
DefaultState: true,
Dependencies: [],
IconAtlas: null,
IconTexture: null,
Interface: 50400,
LoadManagers: [],
LoadOnDemand: false,
LoadWith: [],
Notes: "Records Damage and Healing for Graph Based Display.",
NotesLocalized: {
"ruRU": "Записывает урон и исцеления и отоброжает различные графики.",
"zhCN": "基于 Graph 裤开发的伤害/治疗统计插件.",
"zhTW": "圖形化顯示的傷害/治療統計插件.",
},
OptionalDeps: [
"Ace3",
"LibDropdown-1.0",
"LibSharedMedia-3.0",
"LibBossIDs-1.0",
"LibGraph-2.0",
],
SavedVariables: ["RecountDB"],
SavedVariablesPerCharacter: ["RecountPerCharDB"],
Title: "Recount",
TitleLocalized: {},
Version: "r1269",
files: [
"embeds.xml",
"locales\\Recount-enUS.lua",
"locales\\Recount-deDE.lua",
"locales\\Recount-esES.lua",
"locales\\Recount-esMX.lua",
"locales\\Recount-frFR.lua",
"locales\\Recount-ptBR.lua",
"locales\\Recount-ruRU.lua",
"locales\\Recount-koKR.lua",
"locales\\Recount-zhTW.lua",
"locales\\Recount-zhCN.lua",
"Recount.lua",
"Fonts.lua",
"colors.lua",
"Widgets.lua",
"WindowOrder.lua",
"Fights.lua",
"Recount_Modes.lua",
"TrackerModules\\TrackerModule_Dispels.lua",
"TrackerModules\\TrackerModule_Interrupts.lua",
"TrackerModules\\TrackerModule_Resurrection.lua",
"TrackerModules\\TrackerModule_CCBreakers.lua",
"TrackerModules\\TrackerModule_PowerGains.lua",
"Tracker.lua",
"roster.lua",
"LazySync.lua",
"deletion.lua",
"zonefilters.lua",
"debug.lua",
"GUI_Main.lua",
"GUI_Detail.lua",
"GUI_DeathGraph.lua",
"GUI_Graph.lua",
"GUI_Reset.lua",
"GUI_Report.lua",
"GUI_Config.lua",
"GUI_Realtime.lua"
],
xTags: {
"Curse-Packaged-Version": "r1269",
"Curse-Project-ID": "recount",
"Curse-Project-Name": "Recount",
"Curse-Repository-ID": "wow/recount/mainline"
},
})
})
})
describe('strict checks', () => {
describe('for lines longer then 1024 characters', () => {
it('fails with strict = true', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.1024.toc', 'r');
expect(parse(file)).rejects.toThrowError('Line is longer than TOC_LINE_MAX_LENGTH characters, WoW will truncate!')
})
it('succeeds with strict = false', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.1024.toc', 'r');
const toc = await parse(file, false)
expect(toc).toEqual({
AddonCompartmentFunc: null,
AddonCompartmentFuncOnEnter: null,
AddonCompartmentFuncOnLeave: null,
Author: null,
DefaultState: true,
Dependencies: [],
IconAtlas: null,
IconTexture: null,
Interface: null,
LoadManagers: [],
LoadOnDemand: false,
LoadWith: [],
Notes: null,
NotesLocalized: {},
OptionalDeps: [],
SavedVariables: [],
SavedVariablesPerCharacter: [],
Title: "Strict Check - 1024",
TitleLocalized: {},
Version: null,
files: [
"somefile.lua",
],
xTags: {
"Long": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
},
})
})
})
describe('for double colon', () => {
it('fails with strict = true', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.doublecolon.toc', 'r');
expect(parse(file)).rejects.toThrowError('Tag could not be parsed: X-Invalid-Tag1,, Weird Tag1')
})
it('succeeds with strict = false', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.doublecolon.toc', 'r');
const toc = await parse(file, false)
expect(toc).toEqual({
AddonCompartmentFunc: null,
AddonCompartmentFuncOnEnter: null,
AddonCompartmentFuncOnLeave: null,
Author: null,
DefaultState: true,
Dependencies: [],
IconAtlas: null,
IconTexture: null,
Interface: null,
LoadManagers: [],
LoadOnDemand: false,
LoadWith: [],
Notes: null,
NotesLocalized: {},
OptionalDeps: [],
SavedVariables: [],
SavedVariablesPerCharacter: [],
Title: "Strict Check - Double Colon",
TitleLocalized: {},
Version: null,
files: [
"somefile.lua",
],
xTags: {
},
})
})
})
describe('for duplicate tag', () => {
it('fails with strict = true', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.duplicate.toc', 'r');
expect(parse(file)).rejects.toThrowError('Duplicate value: X-Duplicate-Tag')
})
it('succeeds with strict = false', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.duplicate.toc', 'r');
const toc = await parse(file, false)
expect(toc).toEqual({
AddonCompartmentFunc: null,
AddonCompartmentFuncOnEnter: null,
AddonCompartmentFuncOnLeave: null,
Author: null,
DefaultState: true,
Dependencies: [],
IconAtlas: null,
IconTexture: null,
Interface: null,
LoadManagers: [],
LoadOnDemand: false,
LoadWith: [],
Notes: null,
NotesLocalized: {},
OptionalDeps: [],
SavedVariables: [],
SavedVariablesPerCharacter: [],
Title: "Strict Check - Duplicate Tag",
TitleLocalized: {},
Version: null,
files: [
"somefile.lua",
],
xTags: {
"Duplicate-Tag": "Second"
},
})
})
})
describe('for unknown notes locale', () => {
it('fails with strict = true', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.locale.notes.toc', 'r');
expect(parse(file)).rejects.toThrowError('Locale not found: noNO')
})
it('succeeds with strict = false', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.locale.notes.toc', 'r');
const toc = await parse(file, false)
expect(toc).toEqual({
AddonCompartmentFunc: null,
AddonCompartmentFuncOnEnter: null,
AddonCompartmentFuncOnLeave: null,
Author: null,
DefaultState: true,
Dependencies: [],
IconAtlas: null,
IconTexture: null,
Interface: null,
LoadManagers: [],
LoadOnDemand: false,
LoadWith: [],
Notes: null,
NotesLocalized: {},
OptionalDeps: [],
SavedVariables: [],
SavedVariablesPerCharacter: [],
Title: "Strict Check - Unknown Notes Locale",
TitleLocalized: {},
Version: null,
files: [
"somefile.lua",
],
xTags: {
},
})
})
})
describe('for unknown title locale', () => {
it('fails with strict = true', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.locale.title.toc', 'r');
expect(parse(file)).rejects.toThrowError('Locale not found: noNO')
})
it('succeeds with strict = false', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.locale.title.toc', 'r');
const toc = await parse(file, false)
expect(toc).toEqual({
AddonCompartmentFunc: null,
AddonCompartmentFuncOnEnter: null,
AddonCompartmentFuncOnLeave: null,
Author: null,
DefaultState: true,
Dependencies: [],
IconAtlas: null,
IconTexture: null,
Interface: null,
LoadManagers: [],
LoadOnDemand: false,
LoadWith: [],
Notes: null,
NotesLocalized: {},
OptionalDeps: [],
SavedVariables: [],
SavedVariablesPerCharacter: [],
Title: "Strict Check - Unknown Title Locale",
TitleLocalized: {},
Version: null,
files: [
"somefile.lua",
],
xTags: {
},
})
})
})
describe('for unknown tag', () => {
it('fails with strict = true', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.unknowntag.toc', 'r');
expect(parse(file)).rejects.toThrowError('Unknown Tag name: SomeTag')
})
it('succeeds with strict = false', async () => {
const file = await open(__dirname + '/../test/fixtures/strict.unknowntag.toc', 'r');
const toc = await parse(file, false)
expect(toc).toEqual({
AddonCompartmentFunc: null,
AddonCompartmentFuncOnEnter: null,
AddonCompartmentFuncOnLeave: null,
Author: null,
DefaultState: true,
Dependencies: [],
IconAtlas: null,
IconTexture: null,
Interface: null,
LoadManagers: [],
LoadOnDemand: false,
LoadWith: [],
Notes: null,
NotesLocalized: {},
OptionalDeps: [],
SavedVariables: [],
SavedVariablesPerCharacter: [],
Title: "Strict Check - Unknown Tag",
TitleLocalized: {},
Version: null,
files: [
"somefile.lua",
],
xTags: {
},
})
})
})
})
})

View File

@ -1,58 +0,0 @@
{
"files" : [
"embeds.xml",
"locales\\Recount-enUS.lua",
"locales\\Recount-deDE.lua",
"locales\\Recount-esES.lua",
"locales\\Recount-esMX.lua",
"locales\\Recount-frFR.lua",
"locales\\Recount-ptBR.lua",
"locales\\Recount-ruRU.lua",
"locales\\Recount-koKR.lua",
"locales\\Recount-zhTW.lua",
"locales\\Recount-zhCN.lua",
"Recount.lua",
"Fonts.lua",
"colors.lua",
"Widgets.lua",
"WindowOrder.lua",
"Fights.lua",
"Recount_Modes.lua",
"TrackerModules\\TrackerModule_Dispels.lua",
"TrackerModules\\TrackerModule_Interrupts.lua",
"TrackerModules\\TrackerModule_Resurrection.lua",
"TrackerModules\\TrackerModule_CCBreakers.lua",
"TrackerModules\\TrackerModule_PowerGains.lua",
"Tracker.lua",
"roster.lua",
"LazySync.lua",
"deletion.lua",
"zonefilters.lua",
"debug.lua",
"GUI_Main.lua",
"GUI_Detail.lua",
"GUI_DeathGraph.lua",
"GUI_Graph.lua",
"GUI_Reset.lua",
"GUI_Report.lua",
"GUI_Config.lua",
"GUI_Realtime.lua"
],
"tags" : {
"Author" : "Cryect, ported to 2.4 by Elsia, maintained by Resike from 5.4",
"Interface" : "50400",
"Notes" : "Records Damage and Healing for Graph Based Display.",
"Notes-ruRU" : "Записывает урон и исцеления и отоброжает различные графики.",
"Notes-zhCN" : "基于 Graph 裤开发的伤害/治疗统计插件.",
"Notes-zhTW" : "圖形化顯示的傷害/治療統計插件.",
"OptionalDeps" : "Ace3, LibDropdown-1.0, LibSharedMedia-3.0, LibBossIDs-1.0, LibGraph-2.0",
"SavedVariables" : "RecountDB",
"SavedVariablesPerCharacter" : "RecountPerCharDB",
"Title" : "Recount",
"Version" : "r1269",
"X-Curse-Packaged-Version" : "r1269",
"X-Curse-Project-ID" : "recount",
"X-Curse-Project-Name" : "Recount",
"X-Curse-Repository-ID" : "wow/recount/mainline"
}
}

View File

@ -1,7 +0,0 @@
## Interface: 50400
## Title: Waiting for Godot
## Notes: "Nothing to be done."
## Version: 4.2
#Comment
Vladimir.xml
Estragon.lua

View File

@ -1,6 +0,0 @@
## Title: Bacon
## Interface: 50400
## Notes: I hate everyone
## Version: 4.3.2.1
load.xml
bacon.lua

9
test/fixtures/basic.toc vendored Normal file
View File

@ -0,0 +1,9 @@
## Interface: 50400
## Title: Basic Toc File
## Notes: "Just basic"
## Version: 4.2
#Comment
# Comment2
Dornhoeschen.xml
Rapunzel.lua

49
test/fixtures/complete.toc vendored Normal file
View File

@ -0,0 +1,49 @@
## Interface: 123
## Title: Complete Toc File
## Title-frFR: Title frFR
## Title-deDE: Title deDE
## Title-enGB: Title enGB
## Title-enUS: Title enUS
## Title-itIT: Title itIT
## Title-koKR: Title koKR
## Title-zhCN: Title zhCN
## Title-zhTW: Title zhTW
## Title-ruRU: Title ruRU
## Title-esES: Title esES
## Title-esMX: Title esMX
## Title-ptBR: Title ptBR
## Notes: Describes the full Toc API
## Notes-frFR: Notes frFR
## Notes-deDE: Notes deDE
## Notes-enGB: Notes enGB
## Notes-enUS: Notes enUS
## Notes-itIT: Notes itIT
## Notes-koKR: Notes koKR
## Notes-zhCN: Notes zhCN
## Notes-zhTW: Notes zhTW
## Notes-ruRU: Notes ruRU
## Notes-esES: Notes esES
## Notes-esMX: Notes esMX
## Notes-ptBR: Notes ptBR
## IconTexture: IconA
## IconAtlas: IconB
## AddonCompartmentFunc: Func1
## AddonCompartmentFuncOnEnter: Func2
## AddonCompartmentFuncOnLeave: Func3
## LoadOnDemand: 1
## Dependencies: Lib1, Lib2, Lib3
## OptionalDeps: LibA, LibB, LibC
## LoadWith: AddonA, AddonB, AddonC
## LoadManagers: Addon1, Addon2, Addon3
## DefaultState: disabled
## SavedVariables: Var1, Var2, Var3
## SavedVariablesPerCharacter: CVar1, CVar2, CVar3
## Author: ulfgebhardt
## Version: 456
## X-Tag: XTag
#Comment
# Comment2
Dornhoeschen.xml
Rapunzel.lua

0
test/fixtures/empty.toc vendored Normal file
View File

View File

@ -1,3 +1,3 @@
## Title: Trunicate Me
## Title: Strict Check - 1024
## X-Long: dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
somefile.lua

5
test/fixtures/strict.doublecolon.toc vendored Normal file
View File

@ -0,0 +1,5 @@
## Title: Strict Check - Double Colon
## X-Invalid-Tag1:: Weird Tag1
## X-Invalid-Tag2: : Weird Tag2
## X-Invalid-Tag3: Weird Tag3p1 : Weird Tag3p2
somefile.lua

4
test/fixtures/strict.duplicate.toc vendored Normal file
View File

@ -0,0 +1,4 @@
## Title: Strict Check - Duplicate Tag
## X-Duplicate-Tag: First
## X-Duplicate-Tag: Second
somefile.lua

3
test/fixtures/strict.locale.notes.toc vendored Normal file
View File

@ -0,0 +1,3 @@
## Title: Strict Check - Unknown Notes Locale
## Notes-noNO: Test
somefile.lua

3
test/fixtures/strict.locale.title.toc vendored Normal file
View File

@ -0,0 +1,3 @@
## Title: Strict Check - Unknown Title Locale
## Title-noNO: Test
somefile.lua

3
test/fixtures/strict.unknowntag.toc vendored Normal file
View File

@ -0,0 +1,3 @@
## Title: Strict Check - Unknown Tag
## SomeTag: test
somefile.lua