-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #3. Add indent_width and use_tabs options support
- Loading branch information
Showing
3 changed files
with
3,558 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { newUnibeautify, Beautifier } from "unibeautify"; | ||
import beautifier from "@src"; | ||
|
||
// import * as fs from "fs"; | ||
// import * as path from "path"; | ||
|
||
// const text: string = fs | ||
// .readFileSync(path.resolve(__dirname, `../fixtures/test1.py`)) | ||
// .toString(); | ||
|
||
// testWithTabWidth(0, true); | ||
testWithTabWidth(1, true); | ||
testWithTabWidth(2, true); | ||
|
||
// testWithTabWidth(0, false); | ||
testWithTabWidth(2, false); | ||
testWithTabWidth(4, false); | ||
|
||
function testWithTabWidth(indentWidth: number, useTabs: boolean = false) { | ||
test(`should successfully beautify Python text with useTabs=${useTabs} and indentWidth=${indentWidth}`, () => { | ||
const unibeautify = newUnibeautify(); | ||
unibeautify.loadBeautifier(beautifier); | ||
|
||
const indentChar = useTabs ? "\t" : " "; | ||
const indentation = useTabs ? "\t" : indentChar.repeat(indentWidth); | ||
const indentArg = useTabs ? "tab" : "space"; | ||
|
||
const text = `def test(n):\n return n + 1\n`; | ||
const beautifierResult = `def test(n):\n${indentation}return n + 1\n`; | ||
|
||
return unibeautify | ||
.beautify({ | ||
languageName: "Python", | ||
options: { | ||
Python: { | ||
indent_style: indentArg, | ||
indent_size: indentWidth, | ||
}, | ||
}, | ||
text, | ||
}) | ||
.then(results => { | ||
expect(results).toBe(beautifierResult); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.