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.
Files changed (67) 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 +34 -0
  5. package/dist/config/env.js +62 -0
  6. package/dist/core/ErrorDataHandler.d.ts +60 -0
  7. package/dist/core/YINIVisitor.d.ts +149 -0
  8. package/dist/core/objectBuilder.d.ts +6 -0
  9. package/dist/core/types.d.ts +59 -0
  10. package/dist/grammar/YiniLexer.d.ts +68 -0
  11. package/dist/grammar/YiniParser.d.ts +284 -0
  12. package/dist/grammar/YiniParserVisitor.d.ts +143 -0
  13. package/dist/index.d.ts +1 -0
  14. package/dist/{src/index.js → index.js} +17 -9
  15. package/dist/parseEntry.d.ts +2 -0
  16. package/dist/{src/parseEntry.js → parseEntry.js} +10 -0
  17. package/dist/parsers/extractHeaderParts.d.ts +31 -0
  18. package/dist/parsers/extractSignificantYiniLine.d.ts +9 -0
  19. package/dist/parsers/parseBoolean.d.ts +5 -0
  20. package/dist/parsers/parseNull.d.ts +2 -0
  21. package/dist/parsers/parseNumber.d.ts +6 -0
  22. package/dist/parsers/parseSectionHeader.d.ts +13 -0
  23. package/dist/parsers/parseString.d.ts +2 -0
  24. package/dist/utils/pathAndFileName.d.ts +5 -0
  25. package/dist/utils/string.d.ts +42 -0
  26. package/dist/utils/system.d.ts +7 -0
  27. package/dist/{src/utils → utils}/system.js +2 -2
  28. package/dist/yiniHelpers.d.ts +44 -0
  29. package/package.json +25 -26
  30. package/dist/src/config/env.js +0 -15
  31. package/dist/tests/integration/1-core-parsing/parse-bigger-section-nesting-as-object.test.js +0 -83
  32. package/dist/tests/integration/1-core-parsing/parse-section-nesting-w-classic-markers.test.js +0 -170
  33. package/dist/tests/integration/1-core-parsing/parse-section-nesting-w-nsh-markers.test.js +0 -27
  34. package/dist/tests/integration/1-core-parsing/read some values from level 1 and 2.test.js +0 -77
  35. package/dist/tests/integration/1-core-parsing/throw on bad section heads.test.js +0 -162
  36. package/dist/tests/integration/10-special-validation-modes/validation-modes.test.js +0 -38
  37. package/dist/tests/integration/2-file-structure-and-error/able to parse mixed case filenames.test.js +0 -72
  38. package/dist/tests/integration/2-file-structure-and-error/throw error on bad file extensions.test.js +0 -36
  39. package/dist/tests/integration/2-file-structure-and-error/throw error parsing bad content.test.js +0 -80
  40. package/dist/tests/smoke/A-general-smoke.test.js +0 -259
  41. package/dist/tests/smoke/B-parse-inline-smoke.test.js +0 -270
  42. package/dist/tests/smoke/C-traverse-file-smoke.test.js +0 -141
  43. package/dist/tests/smoke/D-parse-file-smoke.test.js +0 -134
  44. package/dist/tests/unit/parsers/extractHeaderParts.unit.test.js +0 -490
  45. package/dist/tests/unit/parsers/parseSectionHeader-classic.unit.test.js +0 -421
  46. package/dist/tests/unit/parsers/parseSectionHeader-nsh.unit.test.js +0 -436
  47. package/dist/tests/unit/parsers/parseSectionHeader-throw-on-invalid.unit.test.js +0 -168
  48. package/dist/tests/unit/utils/utils-pathAndFileName.unit.test.js +0 -80
  49. package/dist/tests/unit/utils/utils-string.unit.test.js +0 -185
  50. package/dist/tests/unit/yiniHelpers.unit.test.js +0 -306
  51. /package/dist/{src/core → core}/ErrorDataHandler.js +0 -0
  52. /package/dist/{src/core → core}/YINIVisitor.js +0 -0
  53. /package/dist/{src/core → core}/objectBuilder.js +0 -0
  54. /package/dist/{src/core → core}/types.js +0 -0
  55. /package/dist/{src/grammar → grammar}/YiniLexer.js +0 -0
  56. /package/dist/{src/grammar → grammar}/YiniParser.js +0 -0
  57. /package/dist/{src/grammar → grammar}/YiniParserVisitor.js +0 -0
  58. /package/dist/{src/parsers → parsers}/extractHeaderParts.js +0 -0
  59. /package/dist/{src/parsers → parsers}/extractSignificantYiniLine.js +0 -0
  60. /package/dist/{src/parsers → parsers}/parseBoolean.js +0 -0
  61. /package/dist/{src/parsers → parsers}/parseNull.js +0 -0
  62. /package/dist/{src/parsers → parsers}/parseNumber.js +0 -0
  63. /package/dist/{src/parsers → parsers}/parseSectionHeader.js +0 -0
  64. /package/dist/{src/parsers → parsers}/parseString.js +0 -0
  65. /package/dist/{src/utils → utils}/pathAndFileName.js +0 -0
  66. /package/dist/{src/utils → utils}/string.js +0 -0
  67. /package/dist/{src/yiniHelpers.js → yiniHelpers.js} +0 -0
@@ -0,0 +1,44 @@
1
+ /**
2
+ * This file contains specific YINI helper functions (utils).
3
+ * @note More general helper functions should go into the dir "src/utils/".
4
+ */
5
+ /**
6
+ * Check if the character is a section marker character.
7
+ * @param character A character in a string.
8
+ * @note The string must be of length 1.
9
+ * @throws Will throw if not exactly of length 1.
10
+ */
11
+ export declare const isMarkerCharacter: (character: string) => boolean;
12
+ /**
13
+ * @returns Returns the beginning up to (but not including) any comments
14
+ * starting with //, #, ; or --.
15
+ * @throws Will throw if consisting more than 1 lines.
16
+ */
17
+ export declare const stripCommentsAndAfter: (line: string) => string;
18
+ /**
19
+ * Checks if a string conforms to the identifier rules for section headers and
20
+ * member key names as defined by the YINI specification, following
21
+ * the ANTLR4 lexer rule:
22
+ * IDENT: ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '0'..'9' | '_')*
23
+
24
+ * @throws Will only throw if blank string.
25
+ *
26
+ * @satisfies Should satisfy YINI spec 7, chapter: 3.4. Identifiers, Form 1:
27
+ * Identifier of Simple Form.
28
+ * @link https://github.com/YINI-lang/YINI-spec/blob/develop/YINI-Specification.md#34-identifiers
29
+ */
30
+ export declare const isValidSimpleIdent: (str: string) => boolean;
31
+ /**
32
+ * Checks if a string is a valid backticked phrase/identifier:
33
+ * - Wrapped in backticks.
34
+ * - No raw tabs, newlines, or control characters (U+0000–U+001F), except as
35
+ * escaped sequences (e.g., \n).
36
+ * - May contain ordinary spaces.
37
+ * @note Empty is allowed: ``, as in spec (due to conform with the JSON empty key "").
38
+ * @throws Will only throw if missing enclosed backtick(s).
39
+ *
40
+ * @satisfies Should satisfy YINI spec 7, chapter: 3.4. Identifiers, Form 2:
41
+ * Backticked Identifier.
42
+ * @link https://github.com/YINI-lang/YINI-spec/blob/develop/YINI-Specification.md#34-identifiers
43
+ */
44
+ export declare const isValidBacktickedIdent: (str: string) => boolean;
package/package.json CHANGED
@@ -1,18 +1,28 @@
1
1
  {
2
2
  "name": "yini-parser",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.3",
4
4
  "description": "YINI parser for JavaScript/TypeScript, an INI-inspired configuration format, meant to be readable, and easy to use.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "keywords": [
6
+ "read",
7
+ "yini",
8
+ "config",
9
+ "ini",
10
+ "parser",
11
+ "file",
12
+ "parse",
13
+ "configuration"
14
+ ],
15
+ "homepage": "https://m4se.com/yini-lang.org/",
16
+ "license": "Apache-2.0",
7
17
  "files": [
8
18
  "dist/",
9
- "index.js",
10
- "index.d.ts",
11
19
  "package.json",
12
20
  "README.md",
13
21
  "LICENSE",
14
22
  "CHANGELOG.md"
15
23
  ],
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
16
26
  "exports": {
17
27
  ".": {
18
28
  "import": "./dist/index.js",
@@ -22,35 +32,23 @@
22
32
  },
23
33
  "repository": {
24
34
  "type": "git",
25
- "url": "git+https://github.com/YOUR_USERNAME/yini-parser.git"
35
+ "url": "https://github.com/YINI-lang/yini-parser-typescript.git"
26
36
  },
27
- "keywords": [
28
- "read",
29
- "yini",
30
- "config",
31
- "ini",
32
- "parser",
33
- "file",
34
- "parse",
35
- "configuration"
36
- ],
37
- "author": "Marko K. Seppänen",
38
- "license": "Apache-2.0",
39
37
  "private": false,
40
38
  "scripts": {
41
- "start": "cross-env NODE_ENV=production APP_ENV=production node dist/index.js",
42
- "start:debug": "cross-env IS_DEBUG=1 npm run start",
43
- "start:dev": "cross-env NODE_ENV=development APP_ENV=local ts-node src/index.ts",
44
- "start:dev:debug": "cross-env IS_DEBUG=1 npm run start:dev",
39
+ "start": "npm run build && node dist/index.js",
40
+ "start:debug": "npm run start -- isDebug=1",
41
+ "start:dev": "cross-env NODE_ENV=development APP_ENV=local ts-node src/index.ts isDev=1",
42
+ "start:dev:debug": "cross-env npm run start:dev -- isDebug=1",
45
43
  "start-w-clean": "npm run tsc && npm run clean:ts-js && npm run start:dev",
46
44
  "test": "cross-env NODE_ENV=test APP_ENV=local jest --bail --verbose --runInBand",
47
- "test:debug": "cross-env IS_DEBUG=1 npm run test",
45
+ "test:debug": "cross-env npm run test -- --isDebug=1",
48
46
  "test:smoke": "cross-env NODE_ENV=test APP_ENV=local jest tests/smoke --bail --verbose --runInBand",
49
47
  "test:unit": "cross-env NODE_ENV=test APP_ENV=local jest tests/unit --bail --verbose --runInBand",
50
48
  "test:integr": "cross-env NODE_ENV=test APP_ENV=local jest tests/integration --bail --verbose --runInBand",
51
- "test:smoke:debug": "cross-env IS_DEBUG=1 npm run test:smoke",
52
- "test:unit:debug": "cross-env IS_DEBUG=1 npm run test:unit",
53
- "test:integr:debug": "cross-env IS_DEBUG=1 npm run test:integr",
49
+ "test:smoke:debug": "cross-env npm run test:smoke -- --isDebug=1",
50
+ "test:unit:debug": "cross-env npm run test:unit -- --isDebug=1",
51
+ "test:integr:debug": "cross-env npm run test:integr -- --isDebug=1",
54
52
  "ci:test": "cross-env NODE_ENV=test APP_ENV=ci jest --verbose --runInBand",
55
53
  "ci:test:smoke": "cross-env NODE_ENV=test APP_ENV=ci jest tests/smoke --verbose --runInBand",
56
54
  "tsc": "npx tsc -p ./tsconfig.json",
@@ -60,6 +58,7 @@
60
58
  "build": "tsc -p ./tsconfig.json",
61
59
  "prepublishOnly": "npm run lint && npm test && npm run build"
62
60
  },
61
+ "author": "Marko K. Seppänen",
63
62
  "dependencies": {
64
63
  "antlr4": "^4.13.2"
65
64
  },
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.APP_ENV = exports.NODE_ENV = exports.isTest = exports.isProd = exports.isDev = exports.isDebug = void 0;
4
- const NODE_ENV = (process.env.NODE_ENV || 'development');
5
- exports.NODE_ENV = NODE_ENV;
6
- const APP_ENV = (process.env.APP_ENV || 'local');
7
- exports.APP_ENV = APP_ENV;
8
- const isDebug = () => !!process.env.IS_DEBUG;
9
- exports.isDebug = isDebug;
10
- const isDev = () => NODE_ENV === 'development';
11
- exports.isDev = isDev;
12
- const isProd = () => NODE_ENV === 'production';
13
- exports.isProd = isProd;
14
- const isTest = () => NODE_ENV === 'test';
15
- exports.isTest = isTest;
@@ -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
- });