Format Document Completely breaks code!!!. Fixes #19813

This commit is contained in:
Martin Aeschlimann
2017-02-06 12:53:33 +01:00
parent 63a69695f7
commit bf3cfd9dd5
6 changed files with 122 additions and 13 deletions

View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
Polymer({
is: "chat-messages",
properties: {
user: {},
friend: {
observer: "_friendChanged"
}
},
});
</script>
</head>
<body> </body>
</html>

View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
Polymer({
is: "chat-messages",
properties: {
user: {},
friend: {
observer: "_friendChanged"
}
},
});
</script>
</head>
<body> </body>
</html>

View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
Polymer({
is: "chat-messages",
properties: {
user: {},
friend: {
observer: "_friendChanged"
}
},
});
</script>
</head>
<body> </body>
</html>

View File

@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
Polymer({
is: "chat-messages",
properties: {
user: {},
friend: {
observer: "_friendChanged"
}
},
});
</script>
</head>
<body>
</body>
</html>

View File

@@ -4,6 +4,9 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as path from 'path'
import * as fs from 'fs'
import * as assert from 'assert';
import { getLanguageModes } from '../modes/languageModes';
import { TextDocument, Range, TextEdit, FormattingOptions } from 'vscode-languageserver-types';
@@ -12,7 +15,7 @@ import { format } from '../modes/formatting';
suite('HTML Embedded Formatting', () => {
function assertFormat(value: string, expected: string, options?: any): void {
function assertFormat(value: string, expected: string, options?: any, formatOptions?: FormattingOptions): void {
var languageModes = getLanguageModes({ css: true, javascript: true });
if (options) {
languageModes.getAllModes().forEach(m => m.configure(options));
@@ -31,7 +34,9 @@ suite('HTML Embedded Formatting', () => {
}
let document = TextDocument.create('test://test/test.html', 'html', 0, value);
let range = Range.create(document.positionAt(rangeStartOffset), document.positionAt(rangeEndOffset));
let formatOptions = FormattingOptions.create(2, true);
if (!formatOptions) {
formatOptions = FormattingOptions.create(2, true);
}
let result = format(languageModes, document, range, formatOptions, { css: true, javascript: true });
@@ -39,6 +44,12 @@ suite('HTML Embedded Formatting', () => {
assert.equal(actual, expected);
}
function assertFormatWithFixture(fixtureName: string, expectedPath: string, options?: any, formatOptions?: FormattingOptions): void {
let input = fs.readFileSync(path.join(__dirname, 'fixtures', 'inputs', fixtureName)).toString();
let expected = fs.readFileSync(path.join(__dirname, 'fixtures', 'expected', expectedPath)).toString();
assertFormat(input, expected, options, formatOptions);
}
test('HTML only', function (): any {
assertFormat('<html><body><p>Hello</p></body></html>', '<html>\n\n<body>\n <p>Hello</p>\n</body>\n\n</html>');
assertFormat('|<html><body><p>Hello</p></body></html>|', '<html>\n\n<body>\n <p>Hello</p>\n</body>\n\n</html>');
@@ -56,6 +67,12 @@ suite('HTML Embedded Formatting', () => {
assertFormat('<html><head>\n <script>\n|var x=6;|\n</script></head></html>', '<html><head>\n <script>\n var x = 6;\n</script></head></html>');
});
test('HTLM & Scripts - Fixtures', function() {
assertFormatWithFixture('19813.html', '19813.html');
assertFormatWithFixture('19813.html', '19813-4spaces.html', void 0, FormattingOptions.create(4, true));
assertFormatWithFixture('19813.html', '19813-tab.html', void 0, FormattingOptions.create(1, false));
})
test('Script end tag', function (): any {
assertFormat('<html>\n<head>\n <script>\nvar x = 0;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 0;\n\n </script>\n</head>\n\n</html>');
});