Skip to content

Commit 90fd553

Browse files
committed
test: integ tests for auto tab space detection
1 parent 4b88ac3 commit 90fd553

File tree

8 files changed

+155
-1
lines changed

8 files changed

+155
-1
lines changed

src/extensions/default/DebugCommands/MacroRunner.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ define(function (require, exports, module) {
5050
KeyEvent = brackets.getModule("utils/KeyEvent"),
5151
Commands = brackets.getModule("command/Commands"),
5252
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
53+
Editor = brackets.getModule("editor/Editor"),
54+
_ = brackets.getModule("thirdparty/lodash"),
5355
ProjectManager = brackets.getModule("project/ProjectManager");
5456

5557
/**
@@ -304,6 +306,12 @@ define(function (require, exports, module) {
304306
}
305307
}
306308

309+
function validateEqual(obj1, obj2) {
310+
if(!_.isEqual(obj1, obj2)){
311+
throw new Error(`validateEqual: expected ${JSON.stringify(obj1)} to equal ${JSON.stringify(obj2)}`);
312+
}
313+
}
314+
307315
/**
308316
* validates if the given mark type is present in the specified selections
309317
* @param {string} markType
@@ -355,9 +363,29 @@ define(function (require, exports, module) {
355363
return PreferencesManager.get(key);
356364
}
357365

366+
const EDITING = {
367+
setEditorSpacing: function (useTabs, spaceOrTabCount, isAutoMode) {
368+
const activeEditor = EditorManager.getActiveEditor();
369+
if(!activeEditor){
370+
throw new Error(`No active editor found to setEditorSpacing`);
371+
}
372+
const fullPath = activeEditor.document.file.fullPath;
373+
if(Editor.Editor.getAutoTabSpaces(fullPath) !== isAutoMode){
374+
Editor.Editor.setAutoTabSpaces(isAutoMode, fullPath);
375+
isAutoMode && Editor.Editor._autoDetectTabSpaces(activeEditor, true, true);
376+
}
377+
Editor.Editor.setUseTabChar(useTabs);
378+
if(useTabs) {
379+
Editor.Editor.setTabSize(spaceOrTabCount);
380+
} else {
381+
Editor.Editor.setSpaceUnits(spaceOrTabCount);
382+
}
383+
}
384+
};
385+
358386
const __PR= {
359387
openFile, setCursors, expectCursorsToBe, keydown, typeAtCursor, validateText, validateAllMarks, validateMarks,
360-
closeFile, closeAll, undo, redo, setPreference, getPreference
388+
closeFile, closeAll, undo, redo, setPreference, getPreference, validateEqual, EDITING
361389
};
362390

363391
async function runMacro(macroText) {

test/UnitTestSuite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ define(function (require, exports, module) {
117117
require("spec/StateManager-test");
118118
require("spec/TaskManager-integ-test");
119119
require("spec/Generic-integ-test");
120+
require("spec/spacing-auto-detect-integ-test");
120121
// Integrated extension tests
121122
require("spec/Extn-InAppNotifications-integ-test");
122123
require("spec/Extn-RemoteFileAdapter-integ-test");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function f() {
2+
console.log("hello");
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function f() {
2+
console.log("hello");
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function f() {console.log("hello");}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function x(){
2+
console.log();
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function x(){
2+
console.log();
3+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
* Original work Copyright (c) 2013 - 2021 Adobe Systems Incorporated. All rights reserved.
6+
*
7+
* This program is free software: you can redistribute it and/or modify it
8+
* under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
19+
*
20+
*/
21+
22+
/*global describe, it, beforeAll, afterAll */
23+
24+
define(function (require, exports, module) {
25+
26+
27+
var SpecRunnerUtils = require("spec/SpecRunnerUtils");
28+
29+
describe("integration:Auto space and tabs detect", function () {
30+
const testRootSpec = "/spec/space-detect-test-files/";
31+
let testProjectsFolder = SpecRunnerUtils.getTestPath(testRootSpec),
32+
testWindow,
33+
$,
34+
__PR; // __PR can be debugged using debug menu> phoenix code diag tools> test builder
35+
36+
beforeAll(async function () {
37+
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
38+
// Load module instances from brackets.test
39+
await SpecRunnerUtils.loadProjectInTestWindow(testProjectsFolder);
40+
__PR = testWindow.__PR;
41+
$ = testWindow.$;
42+
}, 30000);
43+
44+
afterAll(async function () {
45+
await __PR.closeAll();
46+
testWindow = null;
47+
__PR = null;
48+
$ = null;
49+
await SpecRunnerUtils.closeTestWindow();
50+
}, 30000);
51+
52+
function validateSpacing(type, value, autoMode) {
53+
__PR.validateEqual($("#indent-type").text(), type);
54+
__PR.validateEqual($("#indent-width-label").text(), value);
55+
__PR.validateEqual($("#indent-auto").text(), autoMode);
56+
}
57+
58+
it(`should detect 1 space auto`, async function () {
59+
await __PR.openFile("space-1.js");
60+
validateSpacing("Spaces:", "1", "Auto");
61+
await __PR.closeFile();
62+
});
63+
64+
it(`should detect 12 space as 10 spaces auto`, async function () {
65+
await __PR.openFile("space-12.js");
66+
validateSpacing("Spaces:", "10", "Auto");
67+
await __PR.closeFile();
68+
});
69+
70+
it(`should detect no space as default 4 spaces auto`, async function () {
71+
await __PR.openFile("space-none.js");
72+
validateSpacing("Spaces:", "4", "Auto");
73+
await __PR.closeFile();
74+
});
75+
76+
it(`should detect 2 tabs auto`, async function () {
77+
await __PR.openFile("tab-2.js");
78+
validateSpacing("Tab Size:", "2", "Auto");
79+
await __PR.closeFile();
80+
});
81+
82+
it(`should detect 12 tabs as 10 tabs auto`, async function () {
83+
await __PR.openFile("tab-12.js");
84+
validateSpacing("Tab Size:", "10", "Auto");
85+
await __PR.closeFile();
86+
});
87+
88+
it(`should be able to override individual file's tab/spacing in auto mode`, async function () {
89+
await __PR.openFile("space-1.js");
90+
validateSpacing("Spaces:", "1", "Auto");
91+
$("#indent-type").click();
92+
validateSpacing("Tab Size:", "4", "Auto");
93+
// now switch to another file
94+
await __PR.openFile("tab-2.js");
95+
validateSpacing("Tab Size:", "2", "Auto");
96+
// now switch back and it should remember the overridden settings
97+
await __PR.openFile("space-1.js");
98+
validateSpacing("Tab Size:", "4", "Auto");
99+
// now change the tab units
100+
__PR.EDITING.setEditorSpacing(true, 6, true);
101+
validateSpacing("Tab Size:", "6", "Auto");
102+
// now close the file and switch to another file
103+
await __PR.closeFile();
104+
await __PR.openFile("tab-2.js");
105+
validateSpacing("Tab Size:", "2", "Auto");
106+
// now switch back and it should remember the overridden settings
107+
await __PR.openFile("space-1.js");
108+
validateSpacing("Tab Size:", "6", "Auto");
109+
await __PR.closeFile();
110+
});
111+
});
112+
});

0 commit comments

Comments
 (0)