Skip to content

Commit

Permalink
Added two unit tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Maximilian Wittmer authored and HeikoKlare committed Aug 14, 2023
1 parent 4e97afe commit ba85b73
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.junit.Ignore;
import org.junit.Test;
import org.osgi.service.prefs.BackingStoreException;

public class CharsetTest extends ResourceTest {
Expand Down Expand Up @@ -193,6 +195,45 @@ public void _testBug67606() throws CoreException {
}
}

@Test
public void testCharsetMoveOnFileMove() throws CoreException {
IWorkspace workspace = getWorkspace();
final IProject project = workspace.getRoot().getProject("MyProject");
try {
final IFile file = project.getFile("file.txt");
ensureExistsInWorkspace(file, true);
project.setDefaultCharset("FOO", getMonitor());
assertEquals("Setting up Projects default charset was successful", "FOO", file.getCharset());
file.setCharset("BAR", getMonitor());
assertEquals("Setting up file's explicit charset was successful", "BAR", file.getCharset());
file.move(project.getFullPath().append("file2.txt"), IResource.NONE, getMonitor());
IFile file2 = project.getFile("file2.txt");
assertExistsInWorkspace(file2, false);
assertEquals("The file's charset was correctly copied while coying the file", "BAR", file2.getCharset());
} finally {
ensureDoesNotExistInWorkspace(project);
}
}

@Test
@Ignore("https://github.com/eclipse-platform/eclipse.platform/issues/634")
public void _testCopyFileCopiesCharset() throws CoreException {
IWorkspace workspace = getWorkspace();
final IProject project = workspace.getRoot().getProject("MyProject");
try {
ensureExistsInWorkspace(project, false);
final IFile file = project.getFile("file.txt");
ensureExistsInWorkspace(file, true);
file.setCharset("FOO", getMonitor());
assertEquals("File charset correctly set", file.getCharset(true), "FOO");
file.copy(project.getFullPath().append("file2.txt"), IResource.NONE, getMonitor());
final IFile copiedFile = project.getFile("file2.txt");
assertEquals("File with explicitly set charset keeps charset", copiedFile.getCharset(true), "FOO");
} finally {
ensureDoesNotExistInWorkspace(project);
}
}

/**
* Asserts that the given resources have the given [default] charset.
*/
Expand Down

0 comments on commit ba85b73

Please sign in to comment.