Bug 263316 - [Test] Filename patterns for content types

Change-Id: Iab64b62e3107b775bd9da96d7d2a65731a9754c9
Signed-off-by: Mickael Istria <mistria@redhat.com>
diff --git a/tests/org.eclipse.core.tests.resources/plugin.xml b/tests/org.eclipse.core.tests.resources/plugin.xml
index 63c0a16..2a21c0c 100644
--- a/tests/org.eclipse.core.tests.resources/plugin.xml
+++ b/tests/org.eclipse.core.tests.resources/plugin.xml
@@ -502,6 +502,16 @@
             name="XML Based with Different Extension and Low Priority"
             priority="low">
       </content-type>
+      <content-type
+            id="org.eclipse.core.tests.resources.predefinedContentTypeWithRegexp"
+            name="Predefined content type with regexp matching *predefinedContentTypeWithRegexp* files"
+            file-patterns="*predefinedContentTypeWithRegexp*,*predefinedContentTypeWithPattern*"
+            priority="low">
+      </content-type>
+      <file-association
+            content-type="org.eclipse.core.tests.resources.predefinedContentTypeWithRegexp"
+            file-patterns="*predefinedContentTypeWithWildcards*,somethingElseToCheckCommaSeparated">
+      </file-association>
    </extension>
 <extension
       id="contentTypeRelated1"
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java
index 946a02b..10f8547 100644
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java
+++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java
@@ -7,6 +7,7 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Mickael Istria (Red Hat Inc.) - [263316] regexp for file association
  *******************************************************************************/
 package org.eclipse.core.tests.resources.content;
 
@@ -885,6 +886,35 @@
 		assertTrue("3.0", contains(multiple, xmlContentType));
 	}
 
+	public void testFindContentTypPredefinedRegexp() throws UnsupportedEncodingException, IOException, CoreException {
+		IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
+		IContentTypeMatcher finder = contentTypeManager.getMatcher(new LocalSelectionPolicy(), null);
+
+		IContentType targetContentType = contentTypeManager.getContentType("org.eclipse.core.tests.resources.predefinedContentTypeWithRegexp");
+		assertNotNull("Target content-type not found", targetContentType);
+
+		IContentType single = finder.findContentTypeFor(getInputStream("Just a test"), "somepredefinedContentTypeWithRegexpFile");
+		assertEquals(targetContentType, single);
+		single = finder.findContentTypeFor(getInputStream("Just a test"), "somepredefinedContentTypeWithPatternFile");
+		assertEquals(targetContentType, single);
+		single = finder.findContentTypeFor(getInputStream("Just a test"), "somepredefinedContentTypeWithWildcardsFile");
+		assertEquals(targetContentType, single);
+	}
+
+	public void testFindContentTypeUserRegexp() throws UnsupportedEncodingException, IOException, CoreException {
+		IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
+		IContentTypeMatcher finder = contentTypeManager.getMatcher(new LocalSelectionPolicy(), null);
+
+		IContentType textContentType = contentTypeManager.getContentType(Platform.PI_RUNTIME + '.' + "text");
+
+		IContentType single = finder.findContentTypeFor(getInputStream("Just a test"), "someText.unknown");
+		assertNull("File pattern unknown at that point", single);
+
+		textContentType.addFileSpec("*Text*", IContentType.FILE_PATTERN_SPEC);
+		single = finder.findContentTypeFor(getInputStream("Just a test"), "someText.unknown");
+		assertEquals("Text content should now match *Text* files", textContentType, single);
+	}
+
 	public void testImportFileAssociation() throws CoreException {
 		IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
 		assertNull(contentTypeManager.findContentTypeFor("*.bug122217"));