yini-parser 1.0.0-alpha.1
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/CHANGELOG.md +0 -0
- package/LICENSE +201 -0
- package/README.md +120 -0
- package/dist/src/YINI.js +122 -0
- package/dist/src/config/env.js +15 -0
- package/dist/src/core/ErrorDataHandler.js +207 -0
- package/dist/src/core/YINIVisitor.js +856 -0
- package/dist/src/core/objectBuilder.js +166 -0
- package/dist/src/core/types.js +36 -0
- package/dist/src/grammar/YiniLexer.js +370 -0
- package/dist/src/grammar/YiniParser.js +2106 -0
- package/dist/src/grammar/YiniParserVisitor.js +14 -0
- package/dist/src/index.js +189 -0
- package/dist/src/parseEntry.js +155 -0
- package/dist/src/parsers/extractHeaderParts.js +103 -0
- package/dist/src/parsers/extractSignificantYiniLine.js +68 -0
- package/dist/src/parsers/parseBoolean.js +12 -0
- package/dist/src/parsers/parseNull.js +11 -0
- package/dist/src/parsers/parseNumber.js +49 -0
- package/dist/src/parsers/parseSectionHeader.js +111 -0
- package/dist/src/parsers/parseString.js +40 -0
- package/dist/src/utils/pathAndFileName.js +15 -0
- package/dist/src/utils/string.js +97 -0
- package/dist/src/utils/system.js +23 -0
- package/dist/src/yiniHelpers.js +141 -0
- package/dist/tests/integration/1-core-parsing/parse-bigger-section-nesting-as-object.test.js +83 -0
- package/dist/tests/integration/1-core-parsing/parse-section-nesting-w-classic-markers.test.js +170 -0
- package/dist/tests/integration/1-core-parsing/parse-section-nesting-w-nsh-markers.test.js +27 -0
- package/dist/tests/integration/1-core-parsing/read some values from level 1 and 2.test.js +77 -0
- package/dist/tests/integration/1-core-parsing/throw on bad section heads.test.js +162 -0
- package/dist/tests/integration/10-special-validation-modes/validation-modes.test.js +38 -0
- package/dist/tests/integration/2-file-structure-and-error/able to parse mixed case filenames.test.js +72 -0
- package/dist/tests/integration/2-file-structure-and-error/throw error on bad file extensions.test.js +36 -0
- package/dist/tests/integration/2-file-structure-and-error/throw error parsing bad content.test.js +80 -0
- package/dist/tests/smoke/A-general-smoke.test.js +259 -0
- package/dist/tests/smoke/B-parse-inline-smoke.test.js +270 -0
- package/dist/tests/smoke/C-traverse-file-smoke.test.js +141 -0
- package/dist/tests/smoke/D-parse-file-smoke.test.js +134 -0
- package/dist/tests/unit/parsers/extractHeaderParts.unit.test.js +490 -0
- package/dist/tests/unit/parsers/parseSectionHeader-classic.unit.test.js +421 -0
- package/dist/tests/unit/parsers/parseSectionHeader-nsh.unit.test.js +436 -0
- package/dist/tests/unit/parsers/parseSectionHeader-throw-on-invalid.unit.test.js +168 -0
- package/dist/tests/unit/utils/utils-pathAndFileName.unit.test.js +80 -0
- package/dist/tests/unit/utils/utils-string.unit.test.js +185 -0
- package/dist/tests/unit/yiniHelpers.unit.test.js +306 -0
- package/package.json +94 -0
|
@@ -0,0 +1,170 @@
|
|
|
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/section-nesting-w-classic-markers';
|
|
10
|
+
/**
|
|
11
|
+
* Parse section nesting with classic (repeating characters) section head markers test.
|
|
12
|
+
*/
|
|
13
|
+
describe('Parse section nesting w CLASSIC markers:', () => {
|
|
14
|
+
const baseDir = path_1.default.join(__dirname, DIR_OF_FIXTURES);
|
|
15
|
+
test('1. Parse section nesting w CLASSIC markers.', () => {
|
|
16
|
+
// Arrange.
|
|
17
|
+
const fileName = 'section-nesting-1.yini';
|
|
18
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
19
|
+
// Act.
|
|
20
|
+
const result = src_1.default.parseFile(fullPath);
|
|
21
|
+
(0, system_1.debugPrint)(result);
|
|
22
|
+
// Assert.
|
|
23
|
+
expect(!!result).toEqual(true);
|
|
24
|
+
expect(result.Section1).not.toBe('this should fail');
|
|
25
|
+
expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify({ Section1: { Section11: { value: 11 } } }, null, 4));
|
|
26
|
+
});
|
|
27
|
+
test('2. Parse section nesting w CLASSIC markers.', () => {
|
|
28
|
+
// Arrange.
|
|
29
|
+
const fileName = 'section-nesting-2.yini';
|
|
30
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
31
|
+
// Act.
|
|
32
|
+
const result = src_1.default.parseFile(fullPath);
|
|
33
|
+
(0, system_1.debugPrint)(result);
|
|
34
|
+
// Assert.
|
|
35
|
+
expect(!!result).toEqual(true);
|
|
36
|
+
expect(result.Section1).not.toBe('this should fail');
|
|
37
|
+
expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify({
|
|
38
|
+
Section1: { value: 1, Section11: { value: 11 } },
|
|
39
|
+
Section2: { value: 2 },
|
|
40
|
+
}, null, 4));
|
|
41
|
+
});
|
|
42
|
+
test('3. Parse section nesting w CLASSIC markers.', () => {
|
|
43
|
+
// Arrange.
|
|
44
|
+
const fileName = 'section-nesting-3.yini';
|
|
45
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
46
|
+
// Act.
|
|
47
|
+
const result = src_1.default.parseFile(fullPath);
|
|
48
|
+
(0, system_1.debugPrint)(result);
|
|
49
|
+
// Assert.
|
|
50
|
+
expect(!!result).toEqual(true);
|
|
51
|
+
expect(result.Section1).not.toBe('this should fail');
|
|
52
|
+
expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify({
|
|
53
|
+
Section1: {
|
|
54
|
+
value: 1,
|
|
55
|
+
Section11: { value: 11, Section111: { value: 111 } },
|
|
56
|
+
},
|
|
57
|
+
}, null, 4));
|
|
58
|
+
});
|
|
59
|
+
test('4. Parse section nesting w CLASSIC markers.', () => {
|
|
60
|
+
// Arrange.
|
|
61
|
+
const fileName = 'section-nesting-4.yini';
|
|
62
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
63
|
+
// Act.
|
|
64
|
+
const result = src_1.default.parseFile(fullPath);
|
|
65
|
+
(0, system_1.debugPrint)(result);
|
|
66
|
+
// Assert.
|
|
67
|
+
expect(!!result).toEqual(true);
|
|
68
|
+
expect(result.Section1).not.toBe('this should fail');
|
|
69
|
+
expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify({
|
|
70
|
+
Section1: {
|
|
71
|
+
Section11: { Section111: { value: 111 } },
|
|
72
|
+
},
|
|
73
|
+
}, null, 4));
|
|
74
|
+
});
|
|
75
|
+
test('4. Parse section nesting w CLASSIC markers.', () => {
|
|
76
|
+
// Arrange.
|
|
77
|
+
const fileName = 'section-nesting-4.yini';
|
|
78
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
79
|
+
// Act.
|
|
80
|
+
const result = src_1.default.parseFile(fullPath);
|
|
81
|
+
(0, system_1.debugPrint)(result);
|
|
82
|
+
// Assert.
|
|
83
|
+
expect(!!result).toEqual(true);
|
|
84
|
+
expect(result.Section1).not.toBe('this should fail');
|
|
85
|
+
expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify({
|
|
86
|
+
Section1: {
|
|
87
|
+
Section11: { Section111: { value: 111 } },
|
|
88
|
+
},
|
|
89
|
+
}, null, 4));
|
|
90
|
+
});
|
|
91
|
+
test('5. Parse section nesting w CLASSIC markers.', () => {
|
|
92
|
+
// Arrange.
|
|
93
|
+
const fileName = 'section-nesting-5.yini';
|
|
94
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
95
|
+
// Act.
|
|
96
|
+
const result = src_1.default.parseFile(fullPath);
|
|
97
|
+
(0, system_1.debugPrint)(result);
|
|
98
|
+
// Assert.
|
|
99
|
+
expect(!!result).toEqual(true);
|
|
100
|
+
expect(result.Section1).not.toBe('this should fail');
|
|
101
|
+
expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify({
|
|
102
|
+
Section1: {
|
|
103
|
+
Section11: { Section111: { value: 111 } },
|
|
104
|
+
},
|
|
105
|
+
Section2: { value: 2 },
|
|
106
|
+
}, null, 4));
|
|
107
|
+
});
|
|
108
|
+
test('6. Parse section nesting w CLASSIC markers.', () => {
|
|
109
|
+
// Arrange.
|
|
110
|
+
const fileName = 'section-nesting-6.yini';
|
|
111
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
112
|
+
// Act.
|
|
113
|
+
const result = src_1.default.parseFile(fullPath);
|
|
114
|
+
(0, system_1.debugPrint)(result);
|
|
115
|
+
// Assert.
|
|
116
|
+
expect(!!result).toEqual(true);
|
|
117
|
+
expect(result.Section1).not.toBe('this should fail');
|
|
118
|
+
expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify({
|
|
119
|
+
Section1: {
|
|
120
|
+
Section11: { Section111: { value: 111 } },
|
|
121
|
+
},
|
|
122
|
+
Section2: {
|
|
123
|
+
value: 2,
|
|
124
|
+
Section21: { Section211: { value: 211 } },
|
|
125
|
+
},
|
|
126
|
+
}, null, 4));
|
|
127
|
+
});
|
|
128
|
+
test('7. Parse section nesting w CLASSIC markers.', () => {
|
|
129
|
+
// Arrange.
|
|
130
|
+
const fileName = 'section-nesting-7.yini';
|
|
131
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
132
|
+
// Act.
|
|
133
|
+
const result = src_1.default.parseFile(fullPath);
|
|
134
|
+
(0, system_1.debugPrint)(result);
|
|
135
|
+
// Assert.
|
|
136
|
+
expect(!!result).toEqual(true);
|
|
137
|
+
expect(result.Section1).not.toBe('this should fail');
|
|
138
|
+
expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify({
|
|
139
|
+
Section1: {
|
|
140
|
+
Section11: { Section111: { value: 111 } },
|
|
141
|
+
},
|
|
142
|
+
Section2: {
|
|
143
|
+
value: 2,
|
|
144
|
+
Section21: { Section211: { value: 211 } },
|
|
145
|
+
Section22: { value: 221 },
|
|
146
|
+
},
|
|
147
|
+
}, null, 4));
|
|
148
|
+
});
|
|
149
|
+
test('8. Parse section nesting w CLASSIC markers.', () => {
|
|
150
|
+
// Arrange.
|
|
151
|
+
const fileName = 'section-nesting-8.yini';
|
|
152
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
153
|
+
// Act.
|
|
154
|
+
const result = src_1.default.parseFile(fullPath);
|
|
155
|
+
(0, system_1.debugPrint)(result);
|
|
156
|
+
// Assert.
|
|
157
|
+
expect(!!result).toEqual(true);
|
|
158
|
+
expect(result.Section1).not.toBe('this should fail');
|
|
159
|
+
expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify({
|
|
160
|
+
Section1: {
|
|
161
|
+
Section11: { Section111: {} },
|
|
162
|
+
},
|
|
163
|
+
Section2: {
|
|
164
|
+
value: 2,
|
|
165
|
+
Section21: { Section211: {} },
|
|
166
|
+
Section22: { value: 22 },
|
|
167
|
+
},
|
|
168
|
+
}, null, 4));
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
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/section-nesting-w-nsh-markers';
|
|
10
|
+
/**
|
|
11
|
+
* Parse section nesting with NUMERIC SHORTHAND section head markers test.
|
|
12
|
+
*/
|
|
13
|
+
describe('Parse section nesting w NUMERIC SHORTHAND markers:', () => {
|
|
14
|
+
const baseDir = path_1.default.join(__dirname, DIR_OF_FIXTURES);
|
|
15
|
+
xtest('1. Parse section nesting w NUMERIC SHORTHAND markers.', () => {
|
|
16
|
+
// Arrange.
|
|
17
|
+
const fileName = 'nsh-section-nesting-1.yini';
|
|
18
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
19
|
+
// Act.
|
|
20
|
+
const result = src_1.default.parseFile(fullPath);
|
|
21
|
+
(0, system_1.debugPrint)(result);
|
|
22
|
+
// Assert.
|
|
23
|
+
expect(!!result).toEqual(true);
|
|
24
|
+
expect(result.Section1).not.toBe('this should fail');
|
|
25
|
+
expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify({ Section1: { Section11: { value: 11 } } }, null, 4));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
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/level-two-deep';
|
|
10
|
+
/**
|
|
11
|
+
* Read correctly some values from level 1 and 2 sections tests.
|
|
12
|
+
*/
|
|
13
|
+
describe('Read correctly some values from level 1 and 2 sections tests:', () => {
|
|
14
|
+
const baseDir = path_1.default.join(__dirname, DIR_OF_FIXTURES);
|
|
15
|
+
beforeAll(() => { });
|
|
16
|
+
test('1. Read correctly some values from level 1 and 2, from file "single-section-member-1.yini".', () => {
|
|
17
|
+
// Arrange.
|
|
18
|
+
const fileName = 'level-two-deep-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
|
+
expect(!!result).toEqual(true);
|
|
26
|
+
expect(result.general.name).toEqual('Kim');
|
|
27
|
+
expect(result.general.name).not.toBe('KIM');
|
|
28
|
+
expect(result.general.preferences.avatarMode).toEqual(false);
|
|
29
|
+
});
|
|
30
|
+
test('2. Read correctly some values from level 1 and 2, from file "level-two-deep-2.yini".', () => {
|
|
31
|
+
// Arrange.
|
|
32
|
+
const fileName = 'level-two-deep-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.ID).toEqual(8);
|
|
42
|
+
expect(result.APP.EXTRA.FLAG).toEqual(false);
|
|
43
|
+
expect(result.APP.EXTRA.TIME_OUT).toEqual(6000);
|
|
44
|
+
expect(result.APP.EXTRA.TIME_OUT).not.toBe(0);
|
|
45
|
+
});
|
|
46
|
+
test('3. Read correctly some values from level 1 and 2, from file "level-two-deep-3.yini".', () => {
|
|
47
|
+
// Arrange.
|
|
48
|
+
const fileName = 'level-two-deep-3.yini';
|
|
49
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
50
|
+
// Act.
|
|
51
|
+
const result = src_1.default.parseFile(fullPath);
|
|
52
|
+
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
53
|
+
(0, system_1.debugPrint)(result);
|
|
54
|
+
// Assert.
|
|
55
|
+
// NOTE: Dry run parsing - enough that something is successfully returned.
|
|
56
|
+
expect(!!result).toEqual(true);
|
|
57
|
+
expect(result.Title.Alpha).toEqual(0.98);
|
|
58
|
+
expect(result.Title.Alpha).not.toBe(98);
|
|
59
|
+
expect(result.Title.AlternativeTitle.Name).toEqual('Some other name');
|
|
60
|
+
});
|
|
61
|
+
test('4. Read correctly some values from level 1 and 2, from file "level-two-deep-4.yini".', () => {
|
|
62
|
+
// Arrange.
|
|
63
|
+
const fileName = 'level-two-deep-4.yini';
|
|
64
|
+
const fullPath = path_1.default.join(baseDir, fileName);
|
|
65
|
+
// Act.
|
|
66
|
+
const result = src_1.default.parseFile(fullPath);
|
|
67
|
+
(0, system_1.debugPrint)('fullPath = ' + fullPath);
|
|
68
|
+
(0, system_1.debugPrint)(result);
|
|
69
|
+
// Assert.
|
|
70
|
+
// NOTE: Dry run parsing - enough that something is successfully returned.
|
|
71
|
+
expect(!!result).toEqual(true);
|
|
72
|
+
expect(result.User.username).toEqual('Alice');
|
|
73
|
+
expect(result.User.Preferences.theme).toEqual('classic');
|
|
74
|
+
expect(result.User.Preferences.notifications).toEqual(false);
|
|
75
|
+
expect(result.User.Preferences.notifications).not.toBe('false'); // NOTE: A string!
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
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 DIR_OF_FIXTURES = '../../fixtures/valid/level-two-deep';
|
|
8
|
+
/**
|
|
9
|
+
* Throw error when parsing bad section heads tests.
|
|
10
|
+
*/
|
|
11
|
+
describe('Throw error when parsing bad section head tests:', () => {
|
|
12
|
+
beforeAll(() => { });
|
|
13
|
+
test('1. Should throw error if starting with section (with a member) ^^.', () => {
|
|
14
|
+
// Arrange.
|
|
15
|
+
const fixture = `
|
|
16
|
+
^^ InvalidHeader // INVALID: Must start with atleast one 1-level section.
|
|
17
|
+
value = 3
|
|
18
|
+
`;
|
|
19
|
+
// Act & Assert.
|
|
20
|
+
expect(() => {
|
|
21
|
+
src_1.default.parse(fixture);
|
|
22
|
+
}).toThrow();
|
|
23
|
+
});
|
|
24
|
+
test('2. Should throw error if jumping from section (with a member) ^ -> ^^^.', () => {
|
|
25
|
+
// Arrange.
|
|
26
|
+
const fixture = `
|
|
27
|
+
^ Header1
|
|
28
|
+
value = true
|
|
29
|
+
// BELOW INVALID: Invalid to jump over sections when increasing nesting.
|
|
30
|
+
^^^ InvalidHeader
|
|
31
|
+
anotherValue = 123
|
|
32
|
+
`;
|
|
33
|
+
// Act & Assert.
|
|
34
|
+
expect(() => {
|
|
35
|
+
src_1.default.parse(fixture);
|
|
36
|
+
}).toThrow();
|
|
37
|
+
});
|
|
38
|
+
test('3. Should throw error if starting with section (without members) ^^.', () => {
|
|
39
|
+
// Arrange.
|
|
40
|
+
const fixture = `
|
|
41
|
+
^^ InvalidHeader // INVALID: Must start with atleast one 1-level section.
|
|
42
|
+
`;
|
|
43
|
+
// Act & Assert.
|
|
44
|
+
expect(() => {
|
|
45
|
+
src_1.default.parse(fixture);
|
|
46
|
+
}).toThrow();
|
|
47
|
+
});
|
|
48
|
+
test('4. Should throw error if jumping from section (without members) ^ -> ^^^.', () => {
|
|
49
|
+
// Arrange.
|
|
50
|
+
const fixture = `
|
|
51
|
+
^ Header1
|
|
52
|
+
// BELOW INVALID: Invalid to jump over sections when increasing nesting.
|
|
53
|
+
^^^ InvalidHeader
|
|
54
|
+
`;
|
|
55
|
+
// Act & Assert.
|
|
56
|
+
expect(() => {
|
|
57
|
+
src_1.default.parse(fixture);
|
|
58
|
+
}).toThrow();
|
|
59
|
+
});
|
|
60
|
+
test('5. Should throw error if starting with section (with a member) ^^^.', () => {
|
|
61
|
+
// Arrange.
|
|
62
|
+
const fixture = `
|
|
63
|
+
^^^ InvalidHeader // INVALID: Must start with atleast one 1-level section.
|
|
64
|
+
strValue = "5"
|
|
65
|
+
`;
|
|
66
|
+
// Act & Assert.
|
|
67
|
+
expect(() => {
|
|
68
|
+
src_1.default.parse(fixture);
|
|
69
|
+
}).toThrow();
|
|
70
|
+
});
|
|
71
|
+
test('6. Should throw error if jumping from section (with a member) ^^ -> ^^^^.', () => {
|
|
72
|
+
// Arrange.
|
|
73
|
+
const fixture = `
|
|
74
|
+
^ Section1
|
|
75
|
+
numValue = 66
|
|
76
|
+
^^ Section2
|
|
77
|
+
numValue = 662
|
|
78
|
+
// BELOW INVALID: Invalid to jump over sections when increasing nesting.
|
|
79
|
+
^^^^ InvalidHeader
|
|
80
|
+
anotherValue = 123
|
|
81
|
+
`;
|
|
82
|
+
// Act & Assert.
|
|
83
|
+
expect(() => {
|
|
84
|
+
src_1.default.parse(fixture);
|
|
85
|
+
}).toThrow();
|
|
86
|
+
});
|
|
87
|
+
test('7. Should throw error if starting with section (without members) ^^^.', () => {
|
|
88
|
+
// Arrange.
|
|
89
|
+
const fixture = `
|
|
90
|
+
^^^ InvalidHeader // INVALID: Must start with atleast one 1-level section.
|
|
91
|
+
`;
|
|
92
|
+
// Act & Assert.
|
|
93
|
+
expect(() => {
|
|
94
|
+
src_1.default.parse(fixture);
|
|
95
|
+
}).toThrow();
|
|
96
|
+
});
|
|
97
|
+
test('8. Should throw error if jumping from section (without members) ^^ -> ^^^^.', () => {
|
|
98
|
+
// Arrange.
|
|
99
|
+
const fixture = `
|
|
100
|
+
^ Section1
|
|
101
|
+
^^ Section2
|
|
102
|
+
// BELOW INVALID: Invalid to jump over sections when increasing nesting.
|
|
103
|
+
^^^^ InvalidHeader
|
|
104
|
+
`;
|
|
105
|
+
// Act & Assert.
|
|
106
|
+
expect(() => {
|
|
107
|
+
src_1.default.parse(fixture);
|
|
108
|
+
}).toThrow();
|
|
109
|
+
});
|
|
110
|
+
test('9. Should throw error if starting with section (without members) ^^ (prev. line is a comment).', () => {
|
|
111
|
+
// Arrange.
|
|
112
|
+
const fixture = `
|
|
113
|
+
// BELOW IS INVALID: Must start with atleast one 1-level section.
|
|
114
|
+
^^ InvalidHeader
|
|
115
|
+
`;
|
|
116
|
+
// Act & Assert.
|
|
117
|
+
expect(() => {
|
|
118
|
+
src_1.default.parse(fixture);
|
|
119
|
+
}).toThrow();
|
|
120
|
+
});
|
|
121
|
+
test('10. Should throw error if jumping from section (without members) ^^ -> ^^^^.', () => {
|
|
122
|
+
// Arrange.
|
|
123
|
+
const fixture = `
|
|
124
|
+
^ Section1
|
|
125
|
+
^^ Section2
|
|
126
|
+
--// BELOW INVALID: Invalid to jump over sections when increasing nesting.
|
|
127
|
+
^^^^ InvalidHeader
|
|
128
|
+
`;
|
|
129
|
+
// Act & Assert.
|
|
130
|
+
expect(() => {
|
|
131
|
+
src_1.default.parse(fixture);
|
|
132
|
+
}).toThrow();
|
|
133
|
+
});
|
|
134
|
+
test('11. Should throw error if mixing section header types.', () => {
|
|
135
|
+
// Arrange.
|
|
136
|
+
const invalidYini = `
|
|
137
|
+
^^^3 Section1 // NOT OK, bad section marker, cannot mix marker types.
|
|
138
|
+
x = 200
|
|
139
|
+
`;
|
|
140
|
+
// Act & Assert.
|
|
141
|
+
expect(() => {
|
|
142
|
+
src_1.default.parse(invalidYini);
|
|
143
|
+
}).toThrow();
|
|
144
|
+
});
|
|
145
|
+
test('12. Should throw error if mixing section header types.', () => {
|
|
146
|
+
// Arrange.
|
|
147
|
+
const invalidYini = `
|
|
148
|
+
~1 user3
|
|
149
|
+
username = 'tester three'
|
|
150
|
+
isSysOp = NO
|
|
151
|
+
|
|
152
|
+
# Below is invalid marker, mixup between basic and numeric section marker.
|
|
153
|
+
~~2 prefs // NOT OK, bad section marker, cannot mix marker types.
|
|
154
|
+
theme = "special-dark"
|
|
155
|
+
notifications = ON
|
|
156
|
+
`;
|
|
157
|
+
// Act & Assert.
|
|
158
|
+
expect(() => {
|
|
159
|
+
src_1.default.parse(invalidYini);
|
|
160
|
+
}).toThrow();
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
});
|