11/*******************************************************************************
2- * Copyright (c) 2013 EclipseSource.
2+ * Copyright (c) 2013, 2014 EclipseSource and others .
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License v1.0
55 * which accompanies this distribution, and is available at
1010 ******************************************************************************/
1111package com .eclipsesource .jshint .ui .internal .builder ;
1212
13+ import java .util .Arrays ;
14+
1315import org .eclipse .core .resources .IProject ;
1416import org .junit .After ;
1517import org .junit .Before ;
1618import org .junit .Test ;
19+ import org .osgi .service .prefs .BackingStoreException ;
1720
1821import com .eclipsesource .jshint .ui .internal .preferences .OptionsPreferences ;
1922import com .eclipsesource .jshint .ui .internal .preferences .PreferencesFactory ;
@@ -39,8 +42,9 @@ public void setUp() {
3942 }
4043
4144 @ After
42- public void tearDown () {
45+ public void tearDown () throws BackingStoreException {
4346 deleteProject ( project );
47+ PreferencesFactory .getWorkspacePreferences ().clear ();
4448 }
4549
4650 @ Test
@@ -56,7 +60,7 @@ public void usesWorkspaceOptionsByDefault() {
5660 }
5761
5862 @ Test
59- public void ignoresWorkspaceOptions_ifProjectSpecific () {
63+ public void ignoresWorkspaceOptionsIfProjectSpecific () {
6064 workspacePrefs .getNode ().put ( "options" , "a: 1, b: 1" );
6165 createProjectConfig ( new JsonObject ().add ( "b" , 2 ).add ( "c" , 2 ) );
6266 projectPrefs .setProjectSpecific ( true );
@@ -68,6 +72,18 @@ public void ignoresWorkspaceOptions_ifProjectSpecific() {
6872 assertEquals ( 2 , configuration .get ( "c" ).asInt () );
6973 }
7074
75+ @ Test
76+ public void usesWorkspaceConfigIfNotProjectSpecific () {
77+ workspacePrefs .setConfig ( "{\" a\" : 1, \" b\" : 1}" );
78+ createProjectConfig ( new JsonObject ().add ( "b" , 2 ).add ( "c" , 2 ) );
79+
80+ JsonObject configuration = new ConfigLoader ( project ).getConfiguration ();
81+
82+ assertEquals ( 1 , configuration .get ( "a" ).asInt () );
83+ assertEquals ( 1 , configuration .get ( "b" ).asInt () );
84+ assertNull ( configuration .get ( "c" ) );
85+ }
86+
7187 @ Test
7288 public void fallsBackToOldProjectProperties_ifConfigFileMissing () {
7389 projectPrefs .setProjectSpecific ( true );
@@ -102,6 +118,27 @@ public void emptyConfigForProjectsWithoutConfigFileAndProperties() {
102118 assertEquals ( new JsonObject (), configuration );
103119 }
104120
121+ @ Test
122+ public void filtersCommentsFromProjectConfig () {
123+ projectPrefs .setConfig ( "{\n // \" a\" : 1,\n \" b\" : 2 /*, \" c\" : 3*/}" );
124+ projectPrefs .setProjectSpecific ( true );
125+
126+ JsonObject configuration = new ConfigLoader ( project ).getConfiguration ();
127+
128+ assertEquals ( new JsonObject ().add ( "b" , 2 ), configuration );
129+ assertEquals ( Arrays .asList ( "b" ), configuration .names () );
130+ }
131+
132+ @ Test
133+ public void filtersCommentsFromWorkspaceConfig () {
134+ workspacePrefs .setConfig ( "{\n // \" a\" : 1,\n \" b\" : 2 /*, \" c\" : 3*/}" );
135+
136+ JsonObject configuration = new ConfigLoader ( project ).getConfiguration ();
137+
138+ assertEquals ( new JsonObject ().add ( "b" , 2 ), configuration );
139+ assertEquals ( Arrays .asList ( "b" ), configuration .names () );
140+ }
141+
105142 private void createProjectConfig ( JsonObject projectConfig ) {
106143 TestUtil .createFile ( project , ".jshintrc" , projectConfig .toString () );
107144 }
0 commit comments