mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Parameter Name Hints] settings tests added
This commit is contained in:
+10
-3
@@ -22,6 +22,7 @@ import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -54,6 +55,12 @@ public class ParameterNameHintsSettings implements PersistentStateComponent<Para
|
||||
);
|
||||
|
||||
private ParameterNameHintsSettings.State state = new State();
|
||||
private Set<String> defaultIgnoreSet = DEFAULT;
|
||||
|
||||
@TestOnly
|
||||
protected void setDefaultSet(@NotNull Set<String> ignoreSet) {
|
||||
defaultIgnoreSet = ignoreSet;
|
||||
}
|
||||
|
||||
public static ParameterNameHintsSettings getInstance() {
|
||||
return ServiceManager.getService(ParameterNameHintsSettings.class);
|
||||
@@ -79,7 +86,7 @@ public class ParameterNameHintsSettings implements PersistentStateComponent<Para
|
||||
}
|
||||
|
||||
public Set<String> getIgnorePatternSet() {
|
||||
Set<String> ignoreSet = ContainerUtil.newHashSet(DEFAULT);
|
||||
Set<String> ignoreSet = ContainerUtil.newHashSet(defaultIgnoreSet);
|
||||
state.diff.forEach((item) -> {
|
||||
if (item.startsWith("+")) {
|
||||
ignoreSet.add(item.substring(1));
|
||||
@@ -97,9 +104,9 @@ public class ParameterNameHintsSettings implements PersistentStateComponent<Para
|
||||
|
||||
public void setIgnorePatternSet(@NotNull Set<String> updatedBlackList) {
|
||||
Set<String> addedItems = ContainerUtil.newHashSet(updatedBlackList);
|
||||
DEFAULT.forEach((pattern) -> addedItems.remove(pattern));
|
||||
defaultIgnoreSet.forEach((pattern) -> addedItems.remove(pattern));
|
||||
|
||||
Set<String> removedItems = ContainerUtil.newHashSet(DEFAULT);
|
||||
Set<String> removedItems = ContainerUtil.newHashSet(defaultIgnoreSet);
|
||||
updatedBlackList.forEach((pattern) -> removedItems.remove(pattern));
|
||||
|
||||
List<String> diff = ContainerUtil.newArrayList();
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.hints.settings
|
||||
|
||||
import junit.framework.TestCase
|
||||
|
||||
class ParameterNameSettingsTest : TestCase() {
|
||||
|
||||
fun `test deleted value is saved to state`() {
|
||||
val settings = ParameterNameHintsSettings()
|
||||
val ignoreSet = settings.ignorePatternSet
|
||||
|
||||
assert(ignoreSet.size > 0)
|
||||
val first = ignoreSet.first()
|
||||
ignoreSet.remove(first)
|
||||
|
||||
settings.ignorePatternSet = ignoreSet
|
||||
|
||||
val diff = settings.state!!.diff
|
||||
assert(diff.size == 1)
|
||||
assert(diff[0].startsWith("-"))
|
||||
assert(diff[0].endsWith(first))
|
||||
}
|
||||
|
||||
fun `test saved value is saved to state`() {
|
||||
val settings = ParameterNameHintsSettings()
|
||||
val newPattern = "java.util.*(*)"
|
||||
settings.addIgnorePattern(newPattern)
|
||||
|
||||
val diff = settings.state!!.diff
|
||||
assert(diff.size == 1)
|
||||
assert(diff[0].startsWith("+"))
|
||||
assert(diff[0].endsWith(newPattern))
|
||||
}
|
||||
|
||||
fun `test on defaults change ensure removed default items remains removed`() {
|
||||
val settings = ParameterNameHintsSettings()
|
||||
settings.setDefaultSet(setOf("aaa", "bbb", "ccc"))
|
||||
|
||||
settings.ignorePatternSet = setOf("aaa", "ccc", "zzz")
|
||||
settings.addIgnorePattern("xxx")
|
||||
|
||||
val savedState = settings.state
|
||||
|
||||
val newSettings = ParameterNameHintsSettings()
|
||||
newSettings.setDefaultSet(setOf("aaa", "bbb", "ccc", "qqq", "xxx"))
|
||||
newSettings.loadState(savedState)
|
||||
|
||||
val newIgnoreSet = newSettings.ignorePatternSet
|
||||
assert(newIgnoreSet.containsAll(setOf("aaa", "ccc", "qqq", "zzz", "xxx")))
|
||||
assert(newIgnoreSet.size == 5)
|
||||
newSettings.ignorePatternSet = newSettings.ignorePatternSet
|
||||
|
||||
val diff = newSettings.state!!.diff
|
||||
assert(diff.containsAll(setOf("-bbb", "+zzz")))
|
||||
assert(diff.size == 2)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user