* Fix for issue #3330 phonetic-function * Update main/src/com/google/refine/expr/functions/strings/Phonetic.java Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu> * Corrected Intendation Corrected intendation as suggested. * Added tests to check invalid parameters * Added tests to check invalid parameters Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu>
This commit is contained in:
parent
fa90da2a27
commit
990540ce10
@ -72,7 +72,10 @@ public class Phonetic implements Function {
|
|||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this)
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this)
|
||||||
+ " expects a string for the second argument");
|
+ " expects a string for the second argument");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this)
|
||||||
|
+ " expects a string for the second argument, the phonetic encoding to use.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
if ("doublemetaphone".equalsIgnoreCase(encoding)) {
|
if ("doublemetaphone".equalsIgnoreCase(encoding)) {
|
||||||
|
@ -25,16 +25,26 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package com.google.refine.expr.functions.strings;
|
package com.google.refine.expr.functions.strings;
|
||||||
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
import com.google.refine.RefineTest;
|
||||||
import com.google.refine.util.TestUtils;
|
import com.google.refine.util.TestUtils;
|
||||||
|
import com.google.refine.expr.EvalError;
|
||||||
|
|
||||||
public class PhoneticTests {
|
public class PhoneticTests extends RefineTest {
|
||||||
@Test
|
@Test
|
||||||
public void serializePhonetic() {
|
public void serializePhonetic() {
|
||||||
String json = "{\"description\":\"Returns the a phonetic encoding of s (optionally indicating which encoding to use')\",\"params\":\"string s, string encoding (optional, defaults to 'metaphone3')\",\"returns\":\"string\"}";
|
String json = "{\"description\":\"Returns the a phonetic encoding of s (optionally indicating which encoding to use')\",\"params\":\"string s, string encoding (optional, defaults to 'metaphone3')\",\"returns\":\"string\"}";
|
||||||
TestUtils.isSerializedTo(new Phonetic(), json);
|
TestUtils.isSerializedTo(new Phonetic(), json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testtoPhoneticInvalidParams() {
|
||||||
|
Assert.assertTrue(invoke("phonetic") instanceof EvalError); //if no arguments are provided
|
||||||
|
Assert.assertTrue(invoke("phonetic",(Object[])null) instanceof EvalError); //if first argument(value) is null
|
||||||
|
Assert.assertTrue(invoke("phonetic","one",(Object[])null) instanceof EvalError); //if second argument(encoding type) is null
|
||||||
|
Assert.assertTrue(invoke("phonetic","one","other") instanceof EvalError); //if second argument(encoding type) is not a valid encoding type
|
||||||
|
Assert.assertTrue(invoke("phonetic","one","metaphone3","three") instanceof EvalError); //if more than 2 arguments are provided
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user