Skip to content

Commit ba85b73

Browse files
Maximilian WittmerHeikoKlare
authored andcommitted
Added two unit tests
One unit test tests the base behaviour of how charsets are moved when files are moved. It stands in opposition to testBug67606 which does not currently run because it is run inside of workspace.run The second unit test remains disabled. It tests wether "copy" of a file copies it's charset. This is currently not the case and needs to be linked to an issue.
1 parent 4e97afe commit ba85b73

File tree

1 file changed

+41
-0
lines changed
  • resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources

1 file changed

+41
-0
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
6565
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
6666
import org.eclipse.core.runtime.preferences.InstanceScope;
67+
import org.junit.Ignore;
68+
import org.junit.Test;
6769
import org.osgi.service.prefs.BackingStoreException;
6870

6971
public class CharsetTest extends ResourceTest {
@@ -193,6 +195,45 @@ public void _testBug67606() throws CoreException {
193195
}
194196
}
195197

198+
@Test
199+
public void testCharsetMoveOnFileMove() throws CoreException {
200+
IWorkspace workspace = getWorkspace();
201+
final IProject project = workspace.getRoot().getProject("MyProject");
202+
try {
203+
final IFile file = project.getFile("file.txt");
204+
ensureExistsInWorkspace(file, true);
205+
project.setDefaultCharset("FOO", getMonitor());
206+
assertEquals("Setting up Projects default charset was successful", "FOO", file.getCharset());
207+
file.setCharset("BAR", getMonitor());
208+
assertEquals("Setting up file's explicit charset was successful", "BAR", file.getCharset());
209+
file.move(project.getFullPath().append("file2.txt"), IResource.NONE, getMonitor());
210+
IFile file2 = project.getFile("file2.txt");
211+
assertExistsInWorkspace(file2, false);
212+
assertEquals("The file's charset was correctly copied while coying the file", "BAR", file2.getCharset());
213+
} finally {
214+
ensureDoesNotExistInWorkspace(project);
215+
}
216+
}
217+
218+
@Test
219+
@Ignore("https://github.com/eclipse-platform/eclipse.platform/issues/634")
220+
public void _testCopyFileCopiesCharset() throws CoreException {
221+
IWorkspace workspace = getWorkspace();
222+
final IProject project = workspace.getRoot().getProject("MyProject");
223+
try {
224+
ensureExistsInWorkspace(project, false);
225+
final IFile file = project.getFile("file.txt");
226+
ensureExistsInWorkspace(file, true);
227+
file.setCharset("FOO", getMonitor());
228+
assertEquals("File charset correctly set", file.getCharset(true), "FOO");
229+
file.copy(project.getFullPath().append("file2.txt"), IResource.NONE, getMonitor());
230+
final IFile copiedFile = project.getFile("file2.txt");
231+
assertEquals("File with explicitly set charset keeps charset", copiedFile.getCharset(true), "FOO");
232+
} finally {
233+
ensureDoesNotExistInWorkspace(project);
234+
}
235+
}
236+
196237
/**
197238
* Asserts that the given resources have the given [default] charset.
198239
*/

0 commit comments

Comments
 (0)