yini-parser 1.0.0-alpha.1 → 1.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -10
- package/dist/YINI.d.ts +21 -0
- package/dist/{src/YINI.js → YINI.js} +7 -7
- package/dist/config/env.d.ts +34 -0
- package/dist/config/env.js +62 -0
- package/dist/core/ErrorDataHandler.d.ts +60 -0
- package/dist/core/YINIVisitor.d.ts +149 -0
- package/dist/core/objectBuilder.d.ts +6 -0
- package/dist/core/types.d.ts +59 -0
- package/dist/grammar/YiniLexer.d.ts +68 -0
- package/dist/grammar/YiniParser.d.ts +284 -0
- package/dist/grammar/YiniParserVisitor.d.ts +143 -0
- package/dist/index.d.ts +1 -0
- package/dist/{src/index.js → index.js} +17 -9
- package/dist/parseEntry.d.ts +2 -0
- package/dist/{src/parseEntry.js → parseEntry.js} +10 -0
- package/dist/parsers/extractHeaderParts.d.ts +31 -0
- package/dist/parsers/extractSignificantYiniLine.d.ts +9 -0
- package/dist/parsers/parseBoolean.d.ts +5 -0
- package/dist/parsers/parseNull.d.ts +2 -0
- package/dist/parsers/parseNumber.d.ts +6 -0
- package/dist/parsers/parseSectionHeader.d.ts +13 -0
- package/dist/parsers/parseString.d.ts +2 -0
- package/dist/utils/pathAndFileName.d.ts +5 -0
- package/dist/utils/string.d.ts +42 -0
- package/dist/utils/system.d.ts +7 -0
- package/dist/{src/utils → utils}/system.js +2 -2
- package/dist/yiniHelpers.d.ts +44 -0
- package/package.json +25 -26
- package/dist/src/config/env.js +0 -15
- package/dist/tests/integration/1-core-parsing/parse-bigger-section-nesting-as-object.test.js +0 -83
- package/dist/tests/integration/1-core-parsing/parse-section-nesting-w-classic-markers.test.js +0 -170
- package/dist/tests/integration/1-core-parsing/parse-section-nesting-w-nsh-markers.test.js +0 -27
- package/dist/tests/integration/1-core-parsing/read some values from level 1 and 2.test.js +0 -77
- package/dist/tests/integration/1-core-parsing/throw on bad section heads.test.js +0 -162
- package/dist/tests/integration/10-special-validation-modes/validation-modes.test.js +0 -38
- package/dist/tests/integration/2-file-structure-and-error/able to parse mixed case filenames.test.js +0 -72
- package/dist/tests/integration/2-file-structure-and-error/throw error on bad file extensions.test.js +0 -36
- package/dist/tests/integration/2-file-structure-and-error/throw error parsing bad content.test.js +0 -80
- package/dist/tests/smoke/A-general-smoke.test.js +0 -259
- package/dist/tests/smoke/B-parse-inline-smoke.test.js +0 -270
- package/dist/tests/smoke/C-traverse-file-smoke.test.js +0 -141
- package/dist/tests/smoke/D-parse-file-smoke.test.js +0 -134
- package/dist/tests/unit/parsers/extractHeaderParts.unit.test.js +0 -490
- package/dist/tests/unit/parsers/parseSectionHeader-classic.unit.test.js +0 -421
- package/dist/tests/unit/parsers/parseSectionHeader-nsh.unit.test.js +0 -436
- package/dist/tests/unit/parsers/parseSectionHeader-throw-on-invalid.unit.test.js +0 -168
- package/dist/tests/unit/utils/utils-pathAndFileName.unit.test.js +0 -80
- package/dist/tests/unit/utils/utils-string.unit.test.js +0 -185
- package/dist/tests/unit/yiniHelpers.unit.test.js +0 -306
- /package/dist/{src/core → core}/ErrorDataHandler.js +0 -0
- /package/dist/{src/core → core}/YINIVisitor.js +0 -0
- /package/dist/{src/core → core}/objectBuilder.js +0 -0
- /package/dist/{src/core → core}/types.js +0 -0
- /package/dist/{src/grammar → grammar}/YiniLexer.js +0 -0
- /package/dist/{src/grammar → grammar}/YiniParser.js +0 -0
- /package/dist/{src/grammar → grammar}/YiniParserVisitor.js +0 -0
- /package/dist/{src/parsers → parsers}/extractHeaderParts.js +0 -0
- /package/dist/{src/parsers → parsers}/extractSignificantYiniLine.js +0 -0
- /package/dist/{src/parsers → parsers}/parseBoolean.js +0 -0
- /package/dist/{src/parsers → parsers}/parseNull.js +0 -0
- /package/dist/{src/parsers → parsers}/parseNumber.js +0 -0
- /package/dist/{src/parsers → parsers}/parseSectionHeader.js +0 -0
- /package/dist/{src/parsers → parsers}/parseString.js +0 -0
- /package/dist/{src/utils → utils}/pathAndFileName.js +0 -0
- /package/dist/{src/utils → utils}/string.js +0 -0
- /package/dist/{src/yiniHelpers.js → yiniHelpers.js} +0 -0
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const src_1 = __importDefault(require("../../../src"));
|
|
7
|
-
const system_1 = require("../../../src/utils/system");
|
|
8
|
-
/**
|
|
9
|
-
* Validation modes tests.
|
|
10
|
-
*/
|
|
11
|
-
describe('Validation modes tests:', () => {
|
|
12
|
-
test('1. Empty/missing value in non-strict mode gets null.', () => {
|
|
13
|
-
// Arrange.
|
|
14
|
-
const validYini = `^ Title
|
|
15
|
-
nullVal = null
|
|
16
|
-
empty_val = # ← Implicit null (lenient mode)
|
|
17
|
-
`;
|
|
18
|
-
// Act.
|
|
19
|
-
const result = src_1.default.parse(validYini);
|
|
20
|
-
(0, system_1.debugPrint)(result);
|
|
21
|
-
// Assert.
|
|
22
|
-
expect(!!result).toEqual(true);
|
|
23
|
-
expect(result.Title.nullVal).toEqual(null);
|
|
24
|
-
expect(result.Title.empty_val).toEqual(null);
|
|
25
|
-
});
|
|
26
|
-
test('2. Should throw on empty (missing) value in strict mode.', () => {
|
|
27
|
-
// Arrange.
|
|
28
|
-
const isStrict = true;
|
|
29
|
-
const invalidInStrict = `^ Title
|
|
30
|
-
nullVal = null
|
|
31
|
-
empty_val = # ← ERROR: Requires explicit null (strict mode)
|
|
32
|
-
`;
|
|
33
|
-
// Act & Assert.
|
|
34
|
-
expect(() => {
|
|
35
|
-
src_1.default.parse(invalidInStrict, isStrict);
|
|
36
|
-
}).toThrow();
|
|
37
|
-
});
|
|
38
|
-
});
|
package/dist/tests/integration/2-file-structure-and-error/able to parse mixed case filenames.test.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = __importDefault(require("path"));
|
|
7
|
-
const src_1 = __importDefault(require("../../../src"));
|
|
8
|
-
const system_1 = require("../../../src/utils/system");
|
|
9
|
-
const DIR_OF_FIXTURES = '../../fixtures/valid/single-section-member-w-mixed-casing';
|
|
10
|
-
/**
|
|
11
|
-
* Able to parse filename (+ext.) with mixed case tests.
|
|
12
|
-
*/
|
|
13
|
-
describe('Able to parse filename (+ext.) with mixed case tests:', () => {
|
|
14
|
-
const baseDir = path_1.default.join(__dirname, DIR_OF_FIXTURES);
|
|
15
|
-
beforeAll(() => { });
|
|
16
|
-
test('1. Parse a value from file "single-section-member-1.yini".', () => {
|
|
17
|
-
// Arrange.
|
|
18
|
-
const fileName = 'single-section-member-1.yini';
|
|
19
|
-
const fullPath = path_1.default.join(baseDir, fileName);
|
|
20
|
-
// Act.
|
|
21
|
-
const result = src_1.default.parseFile(fullPath);
|
|
22
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
23
|
-
(0, system_1.debugPrint)(result);
|
|
24
|
-
// Assert.
|
|
25
|
-
// NOTE: Dry run parsing - enough that something is successfully returned.
|
|
26
|
-
expect(!!result).toEqual(true);
|
|
27
|
-
expect(result.unknownKey).toEqual(undefined);
|
|
28
|
-
expect(result.general.name).toEqual('Kim');
|
|
29
|
-
});
|
|
30
|
-
test('2. Parse a value from file "SINGLE-SECTION-MEMBER-2.YINI".', () => {
|
|
31
|
-
// Arrange.
|
|
32
|
-
const fileName = 'SINGLE-SECTION-MEMBER-2.YINI';
|
|
33
|
-
const fullPath = path_1.default.join(baseDir, fileName);
|
|
34
|
-
// Act.
|
|
35
|
-
const result = src_1.default.parseFile(fullPath);
|
|
36
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
37
|
-
(0, system_1.debugPrint)(result);
|
|
38
|
-
// Assert.
|
|
39
|
-
// NOTE: Dry run parsing - enough that something is successfully returned.
|
|
40
|
-
expect(!!result).toEqual(true);
|
|
41
|
-
expect(result.APP.IS_DARK_THEME).toEqual(true);
|
|
42
|
-
});
|
|
43
|
-
test('3. Parse a value from file "Single-Section-Member-3.Yini".', () => {
|
|
44
|
-
// Arrange.
|
|
45
|
-
const fileName = 'Single-Section-Member-3.Yini';
|
|
46
|
-
const fullPath = path_1.default.join(baseDir, fileName);
|
|
47
|
-
// Act.
|
|
48
|
-
const result = src_1.default.parseFile(fullPath);
|
|
49
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
50
|
-
(0, system_1.debugPrint)(result);
|
|
51
|
-
// Assert.
|
|
52
|
-
// NOTE: Dry run parsing - enough that something is successfully returned.
|
|
53
|
-
expect(!!result).toEqual(true);
|
|
54
|
-
expect(result.Title.Id).toEqual(46568);
|
|
55
|
-
});
|
|
56
|
-
test('4. Parse a value from file "singleSectionMember-4.yINI".', () => {
|
|
57
|
-
// Arrange.
|
|
58
|
-
const fileName = 'singleSectionMember-4.yINI';
|
|
59
|
-
const fullPath = path_1.default.join(baseDir, fileName);
|
|
60
|
-
// Act.
|
|
61
|
-
const result = src_1.default.parseFile(fullPath);
|
|
62
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
63
|
-
(0, system_1.debugPrint)(result);
|
|
64
|
-
// Assert.
|
|
65
|
-
// NOTE: Dry run parsing - enough that something is successfully returned.
|
|
66
|
-
expect(!!result).toEqual(true);
|
|
67
|
-
expect(result.appConfig.ratio).not.toEqual(0);
|
|
68
|
-
expect(result.appConfig.ratio).not.toEqual(1);
|
|
69
|
-
expect(result.appConfig.ratio).not.toEqual(0.255);
|
|
70
|
-
expect(result.appConfig.ratio).toEqual(0.25);
|
|
71
|
-
});
|
|
72
|
-
});
|
package/dist/tests/integration/2-file-structure-and-error/throw error on bad file extensions.test.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = __importDefault(require("path"));
|
|
7
|
-
const src_1 = __importDefault(require("../../../src"));
|
|
8
|
-
const system_1 = require("../../../src/utils/system");
|
|
9
|
-
const DIR_OF_FIXTURES = '../../fixtures/valid/single-section-member-w-mixed-casing';
|
|
10
|
-
/**
|
|
11
|
-
* Throw error on invalid file extensions tests.
|
|
12
|
-
*/
|
|
13
|
-
describe('Throw error on invalid file extensions tests:', () => {
|
|
14
|
-
const DIR_OF_FIXTURES = './fixtures/invalid';
|
|
15
|
-
const baseDir = path_1.default.join(__dirname, DIR_OF_FIXTURES);
|
|
16
|
-
test('Should throw error if invalid file extension-1.', () => {
|
|
17
|
-
// Arrange.
|
|
18
|
-
const fileName = 'invalid-file-extension-1.abcd';
|
|
19
|
-
const fullPath = path_1.default.join(baseDir, fileName);
|
|
20
|
-
// Act & Assert.
|
|
21
|
-
expect(() => {
|
|
22
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
23
|
-
src_1.default.parseFile(fullPath);
|
|
24
|
-
}).toThrow();
|
|
25
|
-
});
|
|
26
|
-
test('Should throw error if invalid file extension-2.', () => {
|
|
27
|
-
// Arrange.
|
|
28
|
-
const fileName = 'invalid-file-extension-2.txt';
|
|
29
|
-
const fullPath = path_1.default.join(baseDir, fileName);
|
|
30
|
-
// Act & Assert.
|
|
31
|
-
expect(() => {
|
|
32
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
33
|
-
src_1.default.parseFile(fullPath);
|
|
34
|
-
}).toThrow();
|
|
35
|
-
});
|
|
36
|
-
});
|
package/dist/tests/integration/2-file-structure-and-error/throw error parsing bad content.test.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const src_1 = __importDefault(require("../../../src"));
|
|
7
|
-
const system_1 = require("../../../src/utils/system");
|
|
8
|
-
const DIR_OF_FIXTURES = '../../fixtures/valid/single-section-member-w-mixed-casing';
|
|
9
|
-
/**
|
|
10
|
-
* Throw error when parsing bad file/inline content tests.
|
|
11
|
-
*/
|
|
12
|
-
describe('Throw error when parsing bad file/inline content tests:', () => {
|
|
13
|
-
beforeAll(() => { });
|
|
14
|
-
beforeAll(() => {
|
|
15
|
-
(0, system_1.debugPrint)('beforeAll');
|
|
16
|
-
// const isDebug = !!process.env.IS_DEBUG
|
|
17
|
-
// if (!isDebug) {
|
|
18
|
-
// console.log('process.env.IS_DEBUG is false, OK')
|
|
19
|
-
// } else {
|
|
20
|
-
// console.error('process.env.IS_DEBUG is true, FAIL')
|
|
21
|
-
// console.error(
|
|
22
|
-
// 'Detected that IS_DEBUG is true, is should be false when testing',
|
|
23
|
-
// )
|
|
24
|
-
// console.error('process.env.IS_DEBUG:')
|
|
25
|
-
// console.error(process.env.IS_DEBUG)
|
|
26
|
-
// throw Error('ERROR: A variable in ENV has wrong state')
|
|
27
|
-
// }
|
|
28
|
-
});
|
|
29
|
-
test('1. Should throw error if parsing some garbage.', () => {
|
|
30
|
-
// Arrange.
|
|
31
|
-
const fixture = `someGarbage`;
|
|
32
|
-
// Act & Assert.
|
|
33
|
-
expect(() => {
|
|
34
|
-
src_1.default.parse(fixture);
|
|
35
|
-
}).toThrow();
|
|
36
|
-
});
|
|
37
|
-
test('2. Should throw error if parsing nothing ("").', () => {
|
|
38
|
-
// Arrange.
|
|
39
|
-
const fixture = ''; // (!) Blank!
|
|
40
|
-
// Act & Assert.
|
|
41
|
-
expect(() => {
|
|
42
|
-
src_1.default.parse(fixture);
|
|
43
|
-
}).toThrow();
|
|
44
|
-
});
|
|
45
|
-
test('3. Should throw error if parsing only whitespaces.', () => {
|
|
46
|
-
// Arrange.
|
|
47
|
-
const fixture = ' \t \n '; // (!) Only whitepaces!
|
|
48
|
-
// Act & Assert.
|
|
49
|
-
expect(() => {
|
|
50
|
-
src_1.default.parse(fixture);
|
|
51
|
-
}).toThrow();
|
|
52
|
-
});
|
|
53
|
-
test('4. Should throw error if parsing invalid characters (£ÆŁ).', () => {
|
|
54
|
-
// Arrange.
|
|
55
|
-
const fixture = `^ sectionTitle
|
|
56
|
-
key £ÆŁ 321 // Double = is an error!`;
|
|
57
|
-
// Act & Assert.
|
|
58
|
-
expect(() => {
|
|
59
|
-
src_1.default.parse(fixture);
|
|
60
|
-
}).toThrow();
|
|
61
|
-
});
|
|
62
|
-
test('5. Should throw error if parsing unknown file name.', () => {
|
|
63
|
-
// Arrange.
|
|
64
|
-
const fullPath = './gibberish-file-name';
|
|
65
|
-
// Act & Assert.
|
|
66
|
-
expect(() => {
|
|
67
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
68
|
-
src_1.default.parseFile(fullPath);
|
|
69
|
-
}).toThrow();
|
|
70
|
-
});
|
|
71
|
-
test('6. Should throw error if parsing blank file name ("").', () => {
|
|
72
|
-
// Arrange.
|
|
73
|
-
const fullPath = ''; // (!) Blank!
|
|
74
|
-
// Act & Assert.
|
|
75
|
-
expect(() => {
|
|
76
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
77
|
-
src_1.default.parseFile(fullPath);
|
|
78
|
-
}).toThrow();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = __importDefault(require("path"));
|
|
7
|
-
const src_1 = __importDefault(require("../../src"));
|
|
8
|
-
const env_1 = require("../../src/config/env");
|
|
9
|
-
const system_1 = require("../../src/utils/system");
|
|
10
|
-
/**
|
|
11
|
-
* General Smoke Tests.
|
|
12
|
-
*/
|
|
13
|
-
describe('General Smoke Tests:', () => {
|
|
14
|
-
const DIR_OF_FIXTURES = '../fixtures/smoke-fixtures/strings-with-paths';
|
|
15
|
-
const baseDir = path_1.default.join(__dirname, DIR_OF_FIXTURES);
|
|
16
|
-
beforeAll(() => { });
|
|
17
|
-
beforeAll(() => {
|
|
18
|
-
(0, system_1.debugPrint)('beforeAll');
|
|
19
|
-
// const isDebug = !!process.env.IS_DEBUG
|
|
20
|
-
// if (!isDebug) {
|
|
21
|
-
// console.log('process.env.IS_DEBUG is false, OK')
|
|
22
|
-
// } else {
|
|
23
|
-
// console.error('process.env.IS_DEBUG is true, FAIL')
|
|
24
|
-
// console.error(
|
|
25
|
-
// 'Detected that IS_DEBUG is true, is should be false when testing',
|
|
26
|
-
// )
|
|
27
|
-
// console.error('process.env.IS_DEBUG:')
|
|
28
|
-
// console.error(process.env.IS_DEBUG)
|
|
29
|
-
// throw Error('ERROR: A variable in ENV has wrong state')
|
|
30
|
-
// }
|
|
31
|
-
});
|
|
32
|
-
// Trivial test to see if everything is okey before moving on to "real" tests.
|
|
33
|
-
test('1. Trivial test case.', () => {
|
|
34
|
-
// Arrange.
|
|
35
|
-
const a = 3;
|
|
36
|
-
const b = 5;
|
|
37
|
-
// Act.
|
|
38
|
-
const result = a + b;
|
|
39
|
-
// Assert.
|
|
40
|
-
expect(result).toEqual(8);
|
|
41
|
-
});
|
|
42
|
-
test('2. Correctly parse a short YINI Example.', () => {
|
|
43
|
-
// Arrange.
|
|
44
|
-
const validYini = `^ sectionTitle
|
|
45
|
-
strVar = "Hello World!"
|
|
46
|
-
intVar = 98.21`;
|
|
47
|
-
// Act.
|
|
48
|
-
const result = src_1.default.parse(validYini);
|
|
49
|
-
(0, system_1.debugPrint)(result);
|
|
50
|
-
// Assert.
|
|
51
|
-
expect(result.sectionTitle.strVar).toEqual('Hello World!');
|
|
52
|
-
expect(result.sectionTitle.intVar).toEqual(98.21);
|
|
53
|
-
});
|
|
54
|
-
test('3. Should throw error if parsing some "garbage".', () => {
|
|
55
|
-
// Arrange.
|
|
56
|
-
const fixture = `someGarbage`;
|
|
57
|
-
// Act & Assert.
|
|
58
|
-
expect(() => {
|
|
59
|
-
src_1.default.parse(fixture);
|
|
60
|
-
}).toThrow();
|
|
61
|
-
});
|
|
62
|
-
test('4. Should throw error if parsing lines of "invalid" content.', () => {
|
|
63
|
-
// Arrange.
|
|
64
|
-
const fixture = `
|
|
65
|
-
古池や蛙飛び込む水の音
|
|
66
|
-
ふるいけやかわずとびこむみずのおと
|
|
67
|
-
furu ike ya kawazu tobikomu mizu no oto
|
|
68
|
-
`;
|
|
69
|
-
// Act & Assert.
|
|
70
|
-
expect(() => {
|
|
71
|
-
src_1.default.parse(fixture);
|
|
72
|
-
}).toThrow();
|
|
73
|
-
});
|
|
74
|
-
test('5. Should throw error if parsing unknown file name.', () => {
|
|
75
|
-
// Arrange.
|
|
76
|
-
const fullPath = 'gibberish-path-and-file-name';
|
|
77
|
-
// Act & Assert.
|
|
78
|
-
expect(() => {
|
|
79
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
80
|
-
src_1.default.parseFile(fullPath);
|
|
81
|
-
}).toThrow();
|
|
82
|
-
});
|
|
83
|
-
test('6. Should throw error if parsing "blank" content.', () => {
|
|
84
|
-
// Arrange.
|
|
85
|
-
const fixture = ' '; // NOTE: Only a blank space!
|
|
86
|
-
// Act & Assert.
|
|
87
|
-
expect(() => {
|
|
88
|
-
src_1.default.parse(fixture);
|
|
89
|
-
}).toThrow();
|
|
90
|
-
});
|
|
91
|
-
test('7. Correctly parse paths with forward slash "/".', () => {
|
|
92
|
-
// Arrange.
|
|
93
|
-
const fixture = `^ PathsWithSlash
|
|
94
|
-
path1 = '/'
|
|
95
|
-
path2 = '/etc'
|
|
96
|
-
path3 = 'etc/'
|
|
97
|
-
path4 = 'folder/subfolder'
|
|
98
|
-
path5 = '/usr/local/bin/'
|
|
99
|
-
`;
|
|
100
|
-
// Act.
|
|
101
|
-
const result = src_1.default.parse(fixture);
|
|
102
|
-
(0, system_1.debugPrint)(result);
|
|
103
|
-
// Assert.
|
|
104
|
-
expect(result.PathsWithSlash.path1).toEqual('/');
|
|
105
|
-
expect(result.PathsWithSlash.path2).toEqual('/etc');
|
|
106
|
-
expect(result.PathsWithSlash.path3).toEqual('etc/');
|
|
107
|
-
expect(result.PathsWithSlash.path4).toEqual('folder/subfolder');
|
|
108
|
-
expect(result.PathsWithSlash.path5).toEqual('/usr/local/bin/');
|
|
109
|
-
expect(result.PathsWithSlash.path1).not.toEqual('*');
|
|
110
|
-
});
|
|
111
|
-
test('8. Correctly parse paths with backslash "\\".', () => {
|
|
112
|
-
// Arrange.
|
|
113
|
-
const fileName = 'PathsWithBackslash.yini';
|
|
114
|
-
const fullPath = path_1.default.join(baseDir, fileName);
|
|
115
|
-
// Act.
|
|
116
|
-
const result = src_1.default.parseFile(fullPath);
|
|
117
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
118
|
-
(0, system_1.debugPrint)(result);
|
|
119
|
-
// Assert.
|
|
120
|
-
expect(result.PathsWithBackslash.path1).toEqual('\\');
|
|
121
|
-
expect(result.PathsWithBackslash.path2).toEqual('\\Temp');
|
|
122
|
-
expect(result.PathsWithBackslash.path3).toEqual('Temp\\');
|
|
123
|
-
expect(result.PathsWithBackslash.path4).toEqual('Windows\\System32');
|
|
124
|
-
expect(result.PathsWithBackslash.path5).toEqual('\\Users\\Public\\Documents\\');
|
|
125
|
-
expect(result.PathsWithBackslash.path1).not.toEqual('*');
|
|
126
|
-
});
|
|
127
|
-
test('9. Correctly parse paths with quotes and forward slash "/".', () => {
|
|
128
|
-
// Arrange.
|
|
129
|
-
const fileName = 'paths-w-quotes-and-slash.yini';
|
|
130
|
-
const fullPath = path_1.default.join(baseDir, fileName);
|
|
131
|
-
// Act.
|
|
132
|
-
const result = src_1.default.parseFile(fullPath);
|
|
133
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
134
|
-
(0, system_1.debugPrint)(result);
|
|
135
|
-
// Assert.
|
|
136
|
-
expect(result.PathsWithQuotesSlash.path1).toEqual("/'My Folder'/Documents/file.txt");
|
|
137
|
-
expect(result.PathsWithQuotesSlash.path2).toEqual('/"data"/set.csv');
|
|
138
|
-
expect(result.PathsWithQuotesSlash.path3).toEqual('/`Projects`/Code/'); // NOTE: Has backticks!
|
|
139
|
-
expect(result.PathsWithQuotesSlash.path1).not.toEqual('*');
|
|
140
|
-
});
|
|
141
|
-
test('10. Correctly parse paths with quotes and backslash "\\".', () => {
|
|
142
|
-
const DIR_OF_FIXTURES = '../fixtures/smoke-fixtures/strings-with-paths';
|
|
143
|
-
const baseDir = path_1.default.join(__dirname, DIR_OF_FIXTURES);
|
|
144
|
-
// Arrange.
|
|
145
|
-
const fileName = 'paths-w-quotes-and-backslash.yini';
|
|
146
|
-
const fullPath = path_1.default.join(baseDir, fileName);
|
|
147
|
-
// Act.
|
|
148
|
-
const result = src_1.default.parseFile(fullPath);
|
|
149
|
-
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
150
|
-
(0, system_1.debugPrint)(result);
|
|
151
|
-
// Assert.
|
|
152
|
-
expect(result.PathsWithQuotesBackslash.path1).toEqual("\\'Program Files'\\App\\");
|
|
153
|
-
expect(result.PathsWithQuotesBackslash.path2).toEqual('\\"user name"\\Desktop\\');
|
|
154
|
-
expect(result.PathsWithQuotesBackslash.path3).toEqual('\\Projects\\\`2024\`\\"Quarter 2"\\'); // NOTE: Has backticks!
|
|
155
|
-
expect(result.PathsWithQuotesBackslash.path1).not.toEqual('*');
|
|
156
|
-
});
|
|
157
|
-
test('11. Throw error if using section repeating markers higher than supported.', () => {
|
|
158
|
-
// Arrange.
|
|
159
|
-
const fixture1 = `^ Section1
|
|
160
|
-
^^ Section2
|
|
161
|
-
^^^ Section3
|
|
162
|
-
^^^^ Section4
|
|
163
|
-
^^^^^ Section5
|
|
164
|
-
^^^^^^ Section6 // Section 6.
|
|
165
|
-
strVar = "These section headers are valid!"
|
|
166
|
-
`;
|
|
167
|
-
const fixture2 = `^ Section1
|
|
168
|
-
^^ Section2
|
|
169
|
-
^^^ Section3
|
|
170
|
-
^^^^ Section4
|
|
171
|
-
^^^^^ Section5
|
|
172
|
-
^^^^^^ Section6 // Section 6.
|
|
173
|
-
^^^^^^^ Section7 // INVALID HEADER MARKER!
|
|
174
|
-
strVar = "^^^^^^^ (7) is invalid"
|
|
175
|
-
`;
|
|
176
|
-
// Act.
|
|
177
|
-
const result1 = src_1.default.parse(fixture1);
|
|
178
|
-
(0, env_1.isDebug)() && (0, system_1.printObject)(result1);
|
|
179
|
-
// Assert.
|
|
180
|
-
expect(!!result1).toEqual(true);
|
|
181
|
-
expect(result1.Section1.Section2.Section3.Section4.Section5.Section6
|
|
182
|
-
.strVar).toBe('These section headers are valid!');
|
|
183
|
-
// Act & Assert.
|
|
184
|
-
expect(() => {
|
|
185
|
-
src_1.default.parse(fixture2);
|
|
186
|
-
}).toThrow();
|
|
187
|
-
});
|
|
188
|
-
test('12. Should throw error if parsing an incorrect hash comment.', () => {
|
|
189
|
-
// Arrange.
|
|
190
|
-
const invalidYini = `^ App
|
|
191
|
-
id = 32403 #This hash comment is invalid due to a missing space.
|
|
192
|
-
title = "My Program"
|
|
193
|
-
`;
|
|
194
|
-
// Act & Assert.
|
|
195
|
-
expect(() => {
|
|
196
|
-
src_1.default.parse(invalidYini);
|
|
197
|
-
}).toThrow();
|
|
198
|
-
});
|
|
199
|
-
test('13. Correctly parse a YINI with a hash comment.', () => {
|
|
200
|
-
// Arrange.
|
|
201
|
-
const validYini = `^ App
|
|
202
|
-
id = 32403 # The correct app id.
|
|
203
|
-
title = "My Program"
|
|
204
|
-
`;
|
|
205
|
-
// Act.
|
|
206
|
-
(0, env_1.isDebug)() && (0, system_1.printObject)(validYini);
|
|
207
|
-
const result = src_1.default.parse(validYini);
|
|
208
|
-
(0, system_1.debugPrint)(result);
|
|
209
|
-
// Assert.
|
|
210
|
-
expect(result.App.id).toEqual(32403);
|
|
211
|
-
expect(result.App.title).toEqual('My Program');
|
|
212
|
-
});
|
|
213
|
-
test('14. Correctly parse a YINI enclosed in comments.', () => {
|
|
214
|
-
// Arrange.
|
|
215
|
-
const validYini = `
|
|
216
|
-
// This whole line is a comment.
|
|
217
|
-
^SectionName# This part is a comment.
|
|
218
|
-
// This whole line is a comment.
|
|
219
|
-
`;
|
|
220
|
-
// Act.
|
|
221
|
-
(0, env_1.isDebug)() && (0, system_1.printObject)(validYini);
|
|
222
|
-
const result = src_1.default.parse(validYini);
|
|
223
|
-
(0, env_1.isDebug)() && (0, system_1.printObject)(result);
|
|
224
|
-
// Assert.
|
|
225
|
-
expect(result).toHaveProperty('SectionName');
|
|
226
|
-
//@todo Fix issue that the below value will correctly be {} and not undefined
|
|
227
|
-
//expect(result.SectionName).toEqual({})
|
|
228
|
-
});
|
|
229
|
-
test('15. Should throw error due to illegal section name.', () => {
|
|
230
|
-
// Arrange.
|
|
231
|
-
const invalidYini = `// Should detect illegal section name 2SubSub1!!
|
|
232
|
-
^ App
|
|
233
|
-
^^ SubSect
|
|
234
|
-
^^^ 2SubSub1 // NOT OK, illegal name!
|
|
235
|
-
valueSS1 = "Something."
|
|
236
|
-
valueSS2 = OFF
|
|
237
|
-
`;
|
|
238
|
-
// Act & Assert.
|
|
239
|
-
expect(() => {
|
|
240
|
-
src_1.default.parse(invalidYini);
|
|
241
|
-
(0, system_1.debugPrint)(invalidYini);
|
|
242
|
-
}).toThrow();
|
|
243
|
-
});
|
|
244
|
-
test('16. Should throw error due to illegal section name.', () => {
|
|
245
|
-
// Arrange.
|
|
246
|
-
const invalidYini = `// Should detect illegal section name 2SubSub1!!
|
|
247
|
-
^ App
|
|
248
|
-
^^ \` lsdfkj lj\`
|
|
249
|
-
^^^ 2SubSub1 // NOT OK, illegal name!
|
|
250
|
-
valueSS1 = "Something."
|
|
251
|
-
valueSS2 = OFF
|
|
252
|
-
`;
|
|
253
|
-
// Act & Assert.
|
|
254
|
-
expect(() => {
|
|
255
|
-
src_1.default.parse(invalidYini);
|
|
256
|
-
(0, system_1.debugPrint)(invalidYini);
|
|
257
|
-
}).toThrow();
|
|
258
|
-
});
|
|
259
|
-
});
|