Add tests for array reverse & join

This commit is contained in:
Tom Morris 2020-09-30 20:24:05 -04:00
parent d6e42bf5d9
commit dbb8e530c8
2 changed files with 49 additions and 2 deletions

View File

@ -28,13 +28,35 @@ package com.google.refine.expr.functions.arrays;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.ParsingException;
import com.google.refine.util.TestUtils;
public class JoinTests {
public class JoinTests extends RefineTest {
@Test
public void serializeJoin() {
String json = "{\"description\":\"Returns the string obtained by joining the array a with the separator sep\",\"params\":\"array a, string sep\",\"returns\":\"string\"}";
TestUtils.isSerializedTo(new Join(), json);
}
@Test
public void joinArray() throws ParsingException {
String[] test = {"[2,1,3].join('|')", "2|1|3"};
parseEval(bindings, test);
// TODO: This is current behavior, but is it what we want?
String[] test1 = {"[2,null,3].join(', ')", "2, 3"};
parseEval(bindings, test1);
String[] test2 = {"['z','b','c','a'].join('-')", "z-b-c-a"};
parseEval(bindings, test2);
// TODO: Do we really want the following two tests to return different results?
String[] test3 = {"['z', null,'c','a'].join('-')", "z-c-a"};
parseEval(bindings, test3);
String[] test4 = {"['z', '','c','a'].join('-')", "z--c-a"};
parseEval(bindings, test4);
}
}

View File

@ -28,13 +28,38 @@ package com.google.refine.expr.functions.arrays;
import org.testng.annotations.Test;
import com.google.refine.RefineTest;
import com.google.refine.expr.ParsingException;
import com.google.refine.util.TestUtils;
public class ReverseTests {
public class ReverseTests extends RefineTest {
@Test
public void serializeReverse() {
String json = "{\"description\":\"Reverses array a\",\"params\":\"array a\",\"returns\":\"array\"}";
TestUtils.isSerializedTo(new Reverse(), json);
}
@Test
public void reverseJsonArray() throws ParsingException {
String[] test = {"'[2,1,3]'.parseJson().reverse().toString()", "[3, 1, 2]"};
parseEval(bindings, test);
String[] test1 = {"'[2,null,3]'.parseJson().reverse().toString()", "[3, null, 2]"};
parseEval(bindings, test1);
}
@Test
public void reverseArray() throws ParsingException {
String[] test = {"[2,1,3].reverse().toString()", "[3, 1, 2]"};
parseEval(bindings, test);
String[] test1 = {"[2,null,3].reverse().toString()", "[3, null, 2]"};
parseEval(bindings, test1);
String[] test2 = {"['z','b','c','a'].reverse().toString()", "[a, c, b, z]"};
parseEval(bindings, test2);
String[] test3 = {"['z',null,'c','a'].reverse().toString()", "[a, c, null, z]"};
parseEval(bindings, test3);
}
}