yini-parser 1.0.0-alpha.1 → 1.0.0-alpha.2

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.
Files changed (66) hide show
  1. package/README.md +21 -10
  2. package/dist/YINI.d.ts +21 -0
  3. package/dist/{src/YINI.js → YINI.js} +7 -7
  4. package/dist/config/env.d.ts +20 -0
  5. package/dist/core/ErrorDataHandler.d.ts +60 -0
  6. package/dist/core/YINIVisitor.d.ts +149 -0
  7. package/dist/core/objectBuilder.d.ts +6 -0
  8. package/dist/core/types.d.ts +49 -0
  9. package/dist/grammar/YiniLexer.d.ts +68 -0
  10. package/dist/grammar/YiniParser.d.ts +284 -0
  11. package/dist/grammar/YiniParserVisitor.d.ts +143 -0
  12. package/dist/index.d.ts +1 -0
  13. package/dist/parseEntry.d.ts +2 -0
  14. package/dist/parsers/extractHeaderParts.d.ts +31 -0
  15. package/dist/parsers/extractSignificantYiniLine.d.ts +9 -0
  16. package/dist/parsers/parseBoolean.d.ts +5 -0
  17. package/dist/parsers/parseNull.d.ts +2 -0
  18. package/dist/parsers/parseNumber.d.ts +6 -0
  19. package/dist/parsers/parseSectionHeader.d.ts +13 -0
  20. package/dist/parsers/parseString.d.ts +2 -0
  21. package/dist/utils/pathAndFileName.d.ts +5 -0
  22. package/dist/utils/string.d.ts +42 -0
  23. package/dist/utils/system.d.ts +7 -0
  24. package/dist/yiniHelpers.d.ts +44 -0
  25. package/package.json +17 -18
  26. package/dist/tests/integration/1-core-parsing/parse-bigger-section-nesting-as-object.test.js +0 -83
  27. package/dist/tests/integration/1-core-parsing/parse-section-nesting-w-classic-markers.test.js +0 -170
  28. package/dist/tests/integration/1-core-parsing/parse-section-nesting-w-nsh-markers.test.js +0 -27
  29. package/dist/tests/integration/1-core-parsing/read some values from level 1 and 2.test.js +0 -77
  30. package/dist/tests/integration/1-core-parsing/throw on bad section heads.test.js +0 -162
  31. package/dist/tests/integration/10-special-validation-modes/validation-modes.test.js +0 -38
  32. package/dist/tests/integration/2-file-structure-and-error/able to parse mixed case filenames.test.js +0 -72
  33. package/dist/tests/integration/2-file-structure-and-error/throw error on bad file extensions.test.js +0 -36
  34. package/dist/tests/integration/2-file-structure-and-error/throw error parsing bad content.test.js +0 -80
  35. package/dist/tests/smoke/A-general-smoke.test.js +0 -259
  36. package/dist/tests/smoke/B-parse-inline-smoke.test.js +0 -270
  37. package/dist/tests/smoke/C-traverse-file-smoke.test.js +0 -141
  38. package/dist/tests/smoke/D-parse-file-smoke.test.js +0 -134
  39. package/dist/tests/unit/parsers/extractHeaderParts.unit.test.js +0 -490
  40. package/dist/tests/unit/parsers/parseSectionHeader-classic.unit.test.js +0 -421
  41. package/dist/tests/unit/parsers/parseSectionHeader-nsh.unit.test.js +0 -436
  42. package/dist/tests/unit/parsers/parseSectionHeader-throw-on-invalid.unit.test.js +0 -168
  43. package/dist/tests/unit/utils/utils-pathAndFileName.unit.test.js +0 -80
  44. package/dist/tests/unit/utils/utils-string.unit.test.js +0 -185
  45. package/dist/tests/unit/yiniHelpers.unit.test.js +0 -306
  46. /package/dist/{src/config → config}/env.js +0 -0
  47. /package/dist/{src/core → core}/ErrorDataHandler.js +0 -0
  48. /package/dist/{src/core → core}/YINIVisitor.js +0 -0
  49. /package/dist/{src/core → core}/objectBuilder.js +0 -0
  50. /package/dist/{src/core → core}/types.js +0 -0
  51. /package/dist/{src/grammar → grammar}/YiniLexer.js +0 -0
  52. /package/dist/{src/grammar → grammar}/YiniParser.js +0 -0
  53. /package/dist/{src/grammar → grammar}/YiniParserVisitor.js +0 -0
  54. /package/dist/{src/index.js → index.js} +0 -0
  55. /package/dist/{src/parseEntry.js → parseEntry.js} +0 -0
  56. /package/dist/{src/parsers → parsers}/extractHeaderParts.js +0 -0
  57. /package/dist/{src/parsers → parsers}/extractSignificantYiniLine.js +0 -0
  58. /package/dist/{src/parsers → parsers}/parseBoolean.js +0 -0
  59. /package/dist/{src/parsers → parsers}/parseNull.js +0 -0
  60. /package/dist/{src/parsers → parsers}/parseNumber.js +0 -0
  61. /package/dist/{src/parsers → parsers}/parseSectionHeader.js +0 -0
  62. /package/dist/{src/parsers → parsers}/parseString.js +0 -0
  63. /package/dist/{src/utils → utils}/pathAndFileName.js +0 -0
  64. /package/dist/{src/utils → utils}/string.js +0 -0
  65. /package/dist/{src/utils → utils}/system.js +0 -0
  66. /package/dist/{src/yiniHelpers.js → yiniHelpers.js} +0 -0
@@ -1,83 +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/section-nesting-w-classic-markers';
10
- const answerSectionNestingBigger = {
11
- Section1: {
12
- bValue1: true,
13
- intValue: 1,
14
- Section11: {
15
- sValue: 11,
16
- Section111: {
17
- sValue: 111,
18
- intValue: 111,
19
- },
20
- },
21
- Section12: {
22
- sValue: 12,
23
- },
24
- },
25
- Section2: {
26
- sValue: 2,
27
- Section21: {
28
- sValue: 21,
29
- bValue: false,
30
- Section211: {
31
- sValue: 211,
32
- Section2111: {
33
- sValue: 2111,
34
- },
35
- Section2112: {
36
- sValue: 2112,
37
- strValue: 'test2112',
38
- },
39
- },
40
- },
41
- Section22: {
42
- bValue3: true,
43
- Section221: {
44
- sValue: 221,
45
- },
46
- },
47
- Section23: {
48
- bValue3: true,
49
- },
50
- },
51
- };
52
- /**
53
- * Parse bigger section nesting as an object.
54
- */
55
- describe('Parse bigger section nesting as an object test:', () => {
56
- const baseDir = path_1.default.join(__dirname, DIR_OF_FIXTURES);
57
- test('1. Parse bigger section nesting as object, file "section-nesting-bigger.yini".', () => {
58
- // Arrange.
59
- const fileName = 'section-nesting-bigger.yini';
60
- const fullPath = path_1.default.join(baseDir, fileName);
61
- // Act.
62
- const result = src_1.default.parseFile(fullPath);
63
- (0, system_1.debugPrint)('fullPath = ' + fullPath);
64
- (0, system_1.debugPrint)(result);
65
- // Assert.
66
- expect(!!result).toEqual(true);
67
- expect(result.Section1).not.toBe('this should fail');
68
- expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify(answerSectionNestingBigger, null, 4));
69
- });
70
- test('2. Parse bigger section nesting as object, file "section-nesting-bigger-w-comments.yini".', () => {
71
- // Arrange.
72
- const fileName = 'section-nesting-bigger-w-comments.yini';
73
- const fullPath = path_1.default.join(baseDir, fileName);
74
- // Act.
75
- const result = src_1.default.parseFile(fullPath);
76
- (0, system_1.debugPrint)('fullPath = ' + fullPath);
77
- (0, system_1.debugPrint)(result);
78
- // Assert.
79
- expect(!!result).toEqual(true);
80
- expect(result.Section1).not.toBe('this should fail');
81
- expect(JSON.stringify(result, null, 4)).toEqual(JSON.stringify(answerSectionNestingBigger, null, 4));
82
- });
83
- });
@@ -1,170 +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/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
- });
@@ -1,27 +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/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
- });
@@ -1,77 +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/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
- });
@@ -1,162 +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 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
- });
@@ -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
- });
@@ -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
- });
@@ -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
- });