Merge pull request #1642 from ostephens/mass-edit-fix
Mass edit fix for blanks, numbers and booleans
This commit is contained in:
commit
f3dbc18214
@ -121,13 +121,13 @@ public class MassEditOperation extends EngineDependentMassCellOperation {
|
|||||||
|
|
||||||
from = new ArrayList<String>(fromCount);
|
from = new ArrayList<String>(fromCount);
|
||||||
for (int j = 0; j < fromCount; j++) {
|
for (int j = 0; j < fromCount; j++) {
|
||||||
from.add(fromA.getString(j));
|
from.add(fromA.get(j).toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
from = new ArrayList<String>();
|
from = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean fromBlank = editO.has("fromBlank") && editO.getBoolean("fromBlank");
|
boolean fromBlank = (editO.has("fromBlank") && editO.getBoolean("fromBlank") || from.get(0).length() == 0 && from.size() == 1);
|
||||||
boolean fromError = editO.has("fromError") && editO.getBoolean("fromError");
|
boolean fromError = editO.has("fromError") && editO.getBoolean("fromError");
|
||||||
|
|
||||||
Serializable to = (Serializable) editO.get("to");
|
Serializable to = (Serializable) editO.get("to");
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
package com.google.refine.tests.operations.cell;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.refine.operations.cell.MassEditOperation;
|
||||||
|
import com.google.refine.operations.cell.MassEditOperation.Edit;
|
||||||
|
import com.google.refine.tests.RefineTest;
|
||||||
|
import com.google.refine.util.ParsingUtilities;
|
||||||
|
|
||||||
|
public class MassOperationTests extends RefineTest {
|
||||||
|
|
||||||
|
private List<Edit> editList;
|
||||||
|
private String editsString;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReconstructEditString() throws Exception {
|
||||||
|
editsString = "[{\"from\":[\"String\"],\"to\":\"newString\",\"type\":\"text\"}]";
|
||||||
|
|
||||||
|
editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString));
|
||||||
|
|
||||||
|
Assert.assertEquals(editList.get(0).from.size(), 1);
|
||||||
|
Assert.assertEquals(editList.get(0).from.get(0), "String");
|
||||||
|
Assert.assertEquals(editList.get(0).to,"newString" );
|
||||||
|
Assert.assertFalse(editList.get(0).fromBlank);
|
||||||
|
Assert.assertFalse(editList.get(0).fromError);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReconstructEditMultiString() throws Exception {
|
||||||
|
editsString = "[{\"from\":[\"String1\",\"String2\"],\"to\":\"newString\",\"type\":\"text\"}]";
|
||||||
|
|
||||||
|
editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString));
|
||||||
|
|
||||||
|
Assert.assertEquals(editList.get(0).from.size(), 2);
|
||||||
|
Assert.assertEquals(editList.get(0).from.get(0), "String1");
|
||||||
|
Assert.assertEquals(editList.get(0).from.get(1), "String2");
|
||||||
|
Assert.assertEquals(editList.get(0).to,"newString" );
|
||||||
|
Assert.assertFalse(editList.get(0).fromBlank);
|
||||||
|
Assert.assertFalse(editList.get(0).fromError);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReconstructEditBoolean() throws Exception {
|
||||||
|
editsString = "[{\"from\":[true],\"to\":\"newString\",\"type\":\"text\"}]";
|
||||||
|
|
||||||
|
editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString));
|
||||||
|
|
||||||
|
Assert.assertEquals(editList.get(0).from.size(), 1);
|
||||||
|
Assert.assertEquals(editList.get(0).from.get(0), "true");
|
||||||
|
Assert.assertEquals(editList.get(0).to,"newString" );
|
||||||
|
Assert.assertFalse(editList.get(0).fromBlank);
|
||||||
|
Assert.assertFalse(editList.get(0).fromError);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReconstructEditNumber() throws Exception {
|
||||||
|
editsString = "[{\"from\":[1],\"to\":\"newString\",\"type\":\"text\"}]";
|
||||||
|
|
||||||
|
editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString));
|
||||||
|
|
||||||
|
Assert.assertEquals(editList.get(0).from.size(), 1);
|
||||||
|
Assert.assertEquals(editList.get(0).from.get(0), "1");
|
||||||
|
Assert.assertEquals(editList.get(0).to,"newString" );
|
||||||
|
Assert.assertFalse(editList.get(0).fromBlank);
|
||||||
|
Assert.assertFalse(editList.get(0).fromError);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReconstructEditEmpty() throws Exception {
|
||||||
|
editsString = "[{\"from\":[\"\"],\"to\":\"newString\",\"type\":\"text\"}]";
|
||||||
|
|
||||||
|
editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString));
|
||||||
|
|
||||||
|
Assert.assertEquals(editList.get(0).from.size(), 1);
|
||||||
|
Assert.assertEquals(editList.get(0).from.get(0), "");
|
||||||
|
Assert.assertEquals(editList.get(0).to,"newString" );
|
||||||
|
Assert.assertTrue(editList.get(0).fromBlank);
|
||||||
|
Assert.assertFalse(editList.get(0).fromError);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Not yet testing for mass edit from OR Error
|
||||||
|
//Not yet testing for mass edit from OR Date
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user