mirror of https://github.com/hyper-tuner/ini.git
Add very simple tests
This commit is contained in:
parent
af726fadbf
commit
96c5561b3a
|
@ -1,7 +1,7 @@
|
|||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
||||
|
||||
name: Lint code
|
||||
name: Lint and test
|
||||
|
||||
on:
|
||||
push:
|
||||
|
@ -29,3 +29,4 @@ jobs:
|
|||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm ci
|
||||
- run: npm run lint
|
||||
- run: npm test
|
|
@ -16,3 +16,7 @@ yarn-debug.log*
|
|||
yarn-error.log*
|
||||
|
||||
.eslintcache
|
||||
|
||||
# temp test data
|
||||
/test/data/tmp/*
|
||||
!/test/data/tmp/.keep
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
"prepublishOnly": "npm run build",
|
||||
"start": "tsc --watch",
|
||||
"lint": "tsc && eslint --max-warnings=0 src/**/*.ts src/*.ts",
|
||||
"ini:start": "npm run build && node dist/ini.js",
|
||||
"ini:watch": "npx onchange src/ini.ts -- npm run ini:start"
|
||||
"test": "npm run build && node test/test.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/js-yaml": "^4.0.3",
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export * from './ini';
|
31
src/ini.ts
31
src/ini.ts
|
@ -1,15 +1,10 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import yaml from 'js-yaml';
|
||||
import * as P from 'parsimmon';
|
||||
import {
|
||||
Config as ConfigType,
|
||||
Constant,
|
||||
} from '@speedy-tuner/types';
|
||||
|
||||
console.log('------- start --------');
|
||||
|
||||
class INI {
|
||||
export class INI {
|
||||
space: P.Parser<any>;
|
||||
|
||||
expression: P.Parser<any>;
|
||||
|
@ -1155,27 +1150,3 @@ class INI {
|
|||
};
|
||||
}
|
||||
|
||||
const versions = [
|
||||
// '202012',
|
||||
// '202103',
|
||||
'202109-dev',
|
||||
];
|
||||
|
||||
versions.forEach((version) => {
|
||||
const result = new INI(
|
||||
fs.readFileSync(path.join(__dirname, `/../test/data/ini/${version}.ini`), 'utf8'),
|
||||
).parse();
|
||||
|
||||
fs.writeFileSync(path.join(__dirname, `/../test/data/yaml/${version}.yml`), yaml.dump(result));
|
||||
fs.writeFileSync(path.join(__dirname, `/../test/data/json/${version}.json`), JSON.stringify(result));
|
||||
});
|
||||
|
||||
// const result = new INI(
|
||||
// fs.readFileSync(path.join(__dirname, `/../test/data/tunes/${versions[1]}.ini`), 'utf8'),
|
||||
// ).parse();
|
||||
// console.dir(
|
||||
// result.outputChannels,
|
||||
// { depth: null, compact: false },
|
||||
// );
|
||||
|
||||
console.log('------- end --------');
|
||||
|
|
51
test/test.js
51
test/test.js
|
@ -2,3 +2,54 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert').strict;
|
||||
const yaml = require('js-yaml');
|
||||
const crypto = require('crypto');
|
||||
const { INI } = require('../dist');
|
||||
|
||||
const VERSIONS = [
|
||||
'202012',
|
||||
'202103',
|
||||
'202109-dev',
|
||||
];
|
||||
|
||||
const pathFor = (file) => path.join(__dirname, `/../test/data/${file}`);
|
||||
|
||||
const hashReference = (version) => {
|
||||
const md5Yaml = crypto.createHash('md5');
|
||||
const md5Json = crypto.createHash('md5');
|
||||
|
||||
md5Yaml.update(fs.readFileSync(pathFor(`yaml/${version}.yml`), 'utf8'));
|
||||
md5Json.update(fs.readFileSync(pathFor(`json/${version}.json`), 'utf8'));
|
||||
|
||||
return {
|
||||
yamlOld: md5Yaml.digest('hex'),
|
||||
jsonOld: md5Json.digest('hex'),
|
||||
};
|
||||
};
|
||||
|
||||
VERSIONS.forEach((version) => {
|
||||
const result = new INI(
|
||||
fs.readFileSync(pathFor(`ini/${version}.ini`), 'utf8'),
|
||||
).parse();
|
||||
|
||||
const yamlContent = yaml.dump(result);
|
||||
const jsonContent = JSON.stringify(result);
|
||||
|
||||
const md5YamlNew = crypto.createHash('md5');
|
||||
const md5JsonNew = crypto.createHash('md5');
|
||||
|
||||
const yamlNew = md5YamlNew.update(yamlContent).digest('hex');
|
||||
const jsonNew = md5JsonNew.update(jsonContent).digest('hex');
|
||||
|
||||
const { yamlOld, jsonOld } = hashReference(version);
|
||||
|
||||
// write temp files to disk so we can debug more easily
|
||||
fs.writeFileSync(pathFor(`tmp/${version}.yml`), yamlContent);
|
||||
fs.writeFileSync(pathFor(`tmp/${version}.json`), jsonContent);
|
||||
|
||||
assert.equal(yamlNew, yamlOld);
|
||||
assert.equal(jsonNew, jsonOld);
|
||||
|
||||
fs.unlinkSync(pathFor(`tmp/${version}.yml`));
|
||||
fs.unlinkSync(pathFor(`tmp/${version}.json`));
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue