@@ -30,7 +30,8 @@ define(function (require, exports, module) {
3030 var SpecRunnerUtils = require ( "spec/SpecRunnerUtils" ) ,
3131 FileSystem = require ( "filesystem/FileSystem" ) ,
3232 StringUtils = require ( "utils/StringUtils" ) ,
33- Strings = require ( "strings" ) ;
33+ Strings = require ( "strings" ) ,
34+ _ = require ( "thirdparty/lodash" ) ;
3435
3536 describe ( "Code Inspection" , function ( ) {
3637 this . category = "integration" ;
@@ -42,8 +43,9 @@ define(function (require, exports, module) {
4243 CodeInspection ,
4344 CommandManager ,
4445 Commands = require ( "command/Commands" ) ,
45- DocumentManager ,
4646 EditorManager ,
47+ DocumentManager ,
48+ PreferencesManager ,
4749 prefs ;
4850
4951 var toggleJSLintResults = function ( visible ) {
@@ -115,6 +117,7 @@ define(function (require, exports, module) {
115117 EditorManager = brackets . test . EditorManager ;
116118 prefs = brackets . test . PreferencesManager . getExtensionPrefs ( "linting" ) ;
117119 CodeInspection = brackets . test . CodeInspection ;
120+ PreferencesManager = brackets . test . PreferencesManager ;
118121 CodeInspection . toggleEnabled ( true ) ;
119122 } ) ;
120123 } ) ;
@@ -300,6 +303,60 @@ define(function (require, exports, module) {
300303 } ) ;
301304 } ) ;
302305
306+ it ( "should use preferences for providers lookup" , function ( ) {
307+ var pm = PreferencesManager . getExtensionPrefs ( "linting" ) ,
308+ codeInspector1 = createCodeInspector ( "html1" , failLintResult ) ,
309+ codeInspector2 = createCodeInspector ( "html2" , successfulLintResult ) ,
310+ codeInspector3 = createCodeInspector ( "html3" , successfulLintResult ) ,
311+ codeInspector4 = createCodeInspector ( "html4" , successfulLintResult ) ,
312+ codeInspector5 = createCodeInspector ( "html5" , failLintResult ) ;
313+
314+ CodeInspection . register ( "html" , codeInspector1 ) ;
315+ CodeInspection . register ( "html" , codeInspector2 ) ;
316+ CodeInspection . register ( "html" , codeInspector3 ) ;
317+ CodeInspection . register ( "html" , codeInspector4 ) ;
318+ CodeInspection . register ( "html" , codeInspector5 ) ;
319+
320+ function setAtLocation ( name , value ) {
321+ pm . set ( name , value , { location : { layer : "language" , layerID : "html" , scope : "user" } } ) ;
322+ }
323+
324+ runs ( function ( ) {
325+ var providers ;
326+
327+ setAtLocation ( CodeInspection . _PREF_PREFER_PROVIDERS , [ "html3" , "html4" ] ) ;
328+ providers = CodeInspection . getProvidersForPath ( "my/index.html" ) ;
329+ expect ( providers ) . toNotBe ( null ) ;
330+ expect ( _ . pluck ( providers , "name" ) ) . toEqual ( [ "html3" , "html4" , "html1" , "html2" , "html5" ] ) ;
331+
332+ setAtLocation ( CodeInspection . _PREF_PREFER_PROVIDERS , [ "html5" , "html6" ] ) ;
333+ providers = CodeInspection . getProvidersForPath ( "index.html" ) ;
334+ expect ( providers ) . toNotBe ( null ) ;
335+ expect ( _ . pluck ( providers , "name" ) ) . toEqual ( [ "html5" , "html1" , "html2" , "html3" , "html4" ] ) ;
336+
337+ setAtLocation ( CodeInspection . _PREF_PREFER_PROVIDERS , [ "html19" , "html100" ] ) ;
338+ providers = CodeInspection . getProvidersForPath ( "index.html" ) ;
339+ expect ( providers ) . toNotBe ( null ) ;
340+ expect ( _ . pluck ( providers , "name" ) ) . toEqual ( [ "html1" , "html2" , "html3" , "html4" , "html5" ] ) ;
341+
342+ setAtLocation ( CodeInspection . _PREF_PREFERRED_ONLY , true ) ;
343+ providers = CodeInspection . getProvidersForPath ( "test.html" ) ;
344+ expect ( providers ) . toEqual ( [ ] ) ;
345+
346+ setAtLocation ( CodeInspection . _PREF_PREFER_PROVIDERS , [ "html2" , "html1" ] ) ;
347+ setAtLocation ( CodeInspection . _PREF_PREFERRED_ONLY , true ) ;
348+ providers = CodeInspection . getProvidersForPath ( "c:/temp/another.html" ) ;
349+ expect ( providers ) . toNotBe ( null ) ;
350+ expect ( _ . pluck ( providers , "name" ) ) . toEqual ( [ "html2" , "html1" ] ) ;
351+
352+ setAtLocation ( CodeInspection . _PREF_PREFER_PROVIDERS , undefined ) ;
353+ setAtLocation ( CodeInspection . _PREF_PREFERRED_ONLY , undefined ) ;
354+ providers = CodeInspection . getProvidersForPath ( "index.html" ) ;
355+ expect ( providers ) . toNotBe ( null ) ;
356+ expect ( _ . pluck ( providers , "name" ) ) . toEqual ( [ "html1" , "html2" , "html3" , "html4" , "html5" ] ) ;
357+ } ) ;
358+ } ) ;
359+
303360 it ( "should run asynchoronous implementation when both available in the provider" , function ( ) {
304361 var provider = createAsyncCodeInspector ( "javascript async linter with sync impl" , failLintResult ( ) , 200 , true ) ;
305362 CodeInspection . register ( "javascript" , provider ) ;
@@ -1071,20 +1128,6 @@ define(function (require, exports, module) {
10711128 CodeInspection . _unregisterAll ( ) ;
10721129 } ) ;
10731130
1074- it ( "should unregister JSLint linter if a new javascript linter is registered" , function ( ) {
1075- var codeInspector1 = createCodeInspector ( "JSLint" , successfulLintResult ( ) ) ;
1076- CodeInspection . register ( "javascript" , codeInspector1 ) ;
1077- var codeInspector2 = createCodeInspector ( "javascript inspector" , successfulLintResult ( ) ) ;
1078- CodeInspection . register ( "javascript" , codeInspector2 , true ) ;
1079-
1080- waitsForDone ( SpecRunnerUtils . openProjectFiles ( [ "no-errors.js" ] ) , "open test file" , 5000 ) ;
1081-
1082- runs ( function ( ) {
1083- expect ( codeInspector1 . scanFile ) . not . toHaveBeenCalled ( ) ;
1084- expect ( codeInspector2 . scanFile ) . toHaveBeenCalled ( ) ;
1085- } ) ;
1086- } ) ;
1087-
10881131 it ( "should call inspector 1 and inspector 2" , function ( ) {
10891132 var codeInspector1 = createCodeInspector ( "javascript inspector 1" , successfulLintResult ( ) ) ;
10901133 CodeInspection . register ( "javascript" , codeInspector1 ) ;
0 commit comments