Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
platers committed Aug 4, 2021
1 parent 1cb74dc commit a6a43a3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// babel.config.js
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
};
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
"main": "main.js",
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js --environment BUILD:production"
"build": "rollup --config rollup.config.js --environment BUILD:production",
"test": "jest"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.14.8",
"@babel/preset-env": "^7.14.9",
"@babel/preset-typescript": "^7.14.5",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.1",
"@types/jest": "^26.0.24",
"@types/node": "^14.14.37",
"babel-jest": "^27.0.6",
"jest": "^27.0.6",
"obsidian": "^0.12.0",
"rollup": "^2.32.1",
"tslib": "^2.2.0",
Expand Down
3 changes: 2 additions & 1 deletion rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const rules: { [name: string] : (text: string, params?: any) => string }
return text.replace(/[ \t]+$/gm, "");
},
"newlines_around_headings" : (text: string) => {
return text.replace(/\n*^(#+ .*)\n*/gm, "\n\n$1\n\n");
text = text.replace(/\n*(#+ .*)\n+/g, "\n\n$1\n\n");
return text.replace(/\n*(#+ .*)/g, "\n\n$1");
},
"spaces_after_list_markers" : (text: string) => {
// Space after marker
Expand Down
34 changes: 34 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { rules } from './rules';

test("trailing_spaces", () => {
const text =
`
# H1
line with trailing spaces and tabs `;
const expected = `
# H1
line with trailing spaces and tabs`;
expect(rules['trailing_spaces'](text)).toBe(expected);
});

test("newlines_around_headings", () => {
const text = `
# H1
## H2
# H1
line`;
const expected = `
# H1
## H2
# H1
line`;
expect(rules['newlines_around_headings'](text)).toBe(expected);
});


0 comments on commit a6a43a3

Please sign in to comment.