Skip to content

Commit

Permalink
add parsing tests for comma-separated numbers in JSON5 and YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
77it committed Oct 10, 2024
1 parent 23a937f commit 4a5e4e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/modules/_modules_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class ModulesLoader {
};
validate({ value: p, validation: _validation });

/** @type {{class: *, cdnURI: string} | undefined} */
const _ret = this.#classesRepo.get(this.#classesRepoBuildKey({ moduleEngineURI: p.moduleEngineURI, moduleName: p.moduleName }));
if (_ret === undefined)
return undefined;
Expand Down
13 changes: 13 additions & 0 deletions test/lib_test/json5__test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { parseJSON5 } from '../../src/lib/json5.js';

import { test } from 'node:test';
import assert from 'node:assert';
import { parseYAML } from '../../src/lib/yaml.js';
/** @type {any} */ const t = (typeof Deno !== 'undefined') ? Deno.test : test;

t('JSON5 tests', () => {
Expand All @@ -26,6 +27,12 @@ t('JSON5 tests', () => {
assert.deepStrictEqual(parseJSON5('ciao'), undefined);
//#endregion parsing null and undefined

//#region parsing a number with decimal separated by comma, returns undefined
// because the number is not recognized as a number, but as an invalid string
assert.deepStrictEqual(parseJSON5('999,159'), undefined);
assert.deepStrictEqual(parseJSON5('999, 159'), undefined);
//#endregion parsing a number with decimal separated by comma, returns a undefined

//#region parsing numbers returns the number
assert.deepStrictEqual(parseJSON5(999), 999);
//#endregion parsing numbers returns the number
Expand All @@ -45,6 +52,12 @@ t('JSON5 tests', () => {
//#endregion parsing object serialized in string

//#region parsing array of something
// array with comma separated numbers in an array are not recognized as numbers nor string, but split at every ,
const txt1 = '[1, 2, 1,1 , 2,2]';
let parsed1 = parseJSON5(txt1);
assert.deepStrictEqual(parsed1, [1, 2, 1, 1, 2, 2]);
assert.notDeepStrictEqual(parsed1, [1, 2, '1,1', '2,2']);

const txt2 = '[[\'2023-01-05\' , 155343.53] , [\'2023-02-05\',100000],{start:\'2024-06-01\', NP:2, npy:2}]';
let parsed2 = parseJSON5(txt2);
assert.deepStrictEqual(parsed2[0], ['2023-01-05', 155343.53]);
Expand Down
10 changes: 10 additions & 0 deletions test/lib_test/yaml__test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ t('YAML tests', () => {
assert.deepStrictEqual(parseYAML('null'), null);
//#endregion

// parsing a number with decimal separated by comma, returns a string
assert.deepStrictEqual(parseYAML('999,159'), '999,159');
assert.deepStrictEqual(parseYAML('999, 159'), '999, 159');

// parsing an object without {} goes in error then is returned undefined
let parsed_object_without_parens = parseYAML('Main: 89, Ciao: 99');
assert(parsed_object_without_parens === undefined);
Expand Down Expand Up @@ -105,6 +109,12 @@ t('YAML tests', () => {
//#endregion

//#region parsing array of something, strings also without quotes
// array with comma separated numbers in an array are not recognized as numbers nor string, but split at every ,
const txt1 = '[1, 2, 1,1 , 2,2]';
let parsed1 = parseYAML(txt1);
assert.deepStrictEqual(parsed1, [1, 2, 1, 1, 2, 2]);
assert.notDeepStrictEqual(parsed1, [1, 2, '1,1', '2,2']);

const txt2 = '[[\'2023-01-05\' , 155343.53] , [\'2023-02-05\',100000],{start: \'2024-06-01\', NP: 2, npy: 2}]';
let parsed2 = parseYAML(txt2);
assert.deepStrictEqual(parsed2[0], ['2023-01-05', 155343.53]);
Expand Down

0 comments on commit 4a5e4e2

Please sign in to comment.