Skip to content

Commit

Permalink
Implemented case insensitive matching by default.
Browse files Browse the repository at this point in the history
Case sensitive matching can be turned on in the preferences.
  • Loading branch information
oyse committed Aug 28, 2015
1 parent 51093db commit 518c64c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public class TaskTagParserTest {

private TaskTagParser parser;

public TaskTagParserTest(String inputFilename){
public TaskTagParserTest(String inputFilename, boolean caseSensitive){
this.inputFilename = TEST_FILE_DIR + inputFilename + ".yaml";
testCaseFilename = TEST_FILE_DIR + inputFilename + "-result.yaml";

List<TaskTagPreference> tagsToFind = new ArrayList<TaskTagPreference>();
tagsToFind.add(new TaskTagPreference("TODO", "normal"));
tagsToFind.add(new TaskTagPreference("FIXME", "high"));
YAMLScanner scanner = new YAMLScanner(new ColorManager());
parser = new TaskTagParser(tagsToFind, scanner);
parser = new TaskTagParser(tagsToFind, scanner, caseSensitive);
}

@Test
Expand All @@ -60,10 +60,11 @@ public void verifyTodoTags(){
public static Collection<Object[]> parameters() {

Collection<Object[]> testCases = new ArrayList<Object[]>();
testCases.add( new Object[]{ "empty-doc" } );
testCases.add( new Object[]{ "no-todo" } );
testCases.add( new Object[]{ "multi-todo" } );
testCases.add( new Object[]{ "todo-in-scalar" } );
testCases.add( new Object[]{ "empty-doc", false } );
testCases.add( new Object[]{ "no-todo", false } );
testCases.add( new Object[]{ "multi-todo", false } );
testCases.add( new Object[]{ "todo-in-scalar", false } );
testCases.add( new Object[]{ "case-sensitive", true } );


return testCases;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Tests for document with a tag in wrong case
expectedTags:
- tag: TODO
severity: normal
lineNumber: 5
message: number two


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- this is a
- simple test #Todo not picked up due to case
- file with
- some:
tags here and there # TODO number two
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public class TaskTagParser {

private final Pattern tagPattern;

public TaskTagParser(List<TaskTagPreference> tagsToFind, YAMLScanner scanner){
public TaskTagParser(List<TaskTagPreference> tagsToFind, YAMLScanner scanner, boolean caseSensitive){
this.tagsToFind = tagsToFind;
this.scanner = scanner;

tagPattern = Pattern.compile(constructTagPattern(tagsToFind));
if(caseSensitive){
tagPattern = Pattern.compile(constructTagPattern(tagsToFind));
} else {
tagPattern = Pattern.compile(constructTagPattern(tagsToFind), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
}

}

Expand Down Expand Up @@ -122,8 +126,9 @@ private String getTodoTagMessage(String comment, String tag){

private TaskTagPreference getFoundTagType(String comment){

comment = comment.toLowerCase();
for(TaskTagPreference ttp : tagsToFind){
if(comment.indexOf(ttp.tag) > 0){
if(comment.indexOf(ttp.tag.toLowerCase()) > 0){
return ttp;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ void locateTaskTags() {
}

List<TaskTagPreference> prefs = getTaskTagPreferences();
TaskTagParser ttp = new TaskTagParser(prefs, sourceViewerConfig.getScanner());
boolean caseSensitiveTags = Boolean.valueOf(Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.TODO_TASK_CASE_SENSITIVE));
TaskTagParser ttp = new TaskTagParser(prefs, sourceViewerConfig.getScanner(), caseSensitiveTags);
List<TaskTag> tags = ttp.parseTags(this.getDocumentProvider().getDocument(this.getEditorInput()));


Expand Down

0 comments on commit 518c64c

Please sign in to comment.