This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-278
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-278 by this push:
new 7182853 WIP.
7182853 is described below
commit 71828530cab0646810b4d79f0ff87e74a58582c1
Author: Sergey Kamov <[email protected]>
AuthorDate: Wed Mar 24 10:37:58 2021 +0300
WIP.
---
.../idl/compiler/functions/NCIdlFunctions.scala | 13 ++++++++++++-
.../compiler/functions/NCIdlFunctionsMath.scala | 19 ++++---------------
.../compiler/functions/NCIdlFunctionsStrings.scala | 22 +++++++++++++++++++++-
3 files changed, 37 insertions(+), 17 deletions(-)
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
index 9290694..58237ba 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
@@ -17,7 +17,7 @@
package org.apache.nlpcraft.model.intent.idl.compiler.functions
-import org.apache.nlpcraft.common.ScalaMeta
+import org.apache.nlpcraft.common.{NCE, ScalaMeta}
import org.apache.nlpcraft.model.intent.compiler.{NCIdlCompiler,
NCIdlCompilerGlobal}
import org.apache.nlpcraft.model.intent.{NCIdlContext, NCIdlTerm}
import org.apache.nlpcraft.model.{NCCompany, NCModel, NCModelView, NCRequest,
NCToken, NCUser}
@@ -173,5 +173,16 @@ private[functions] trait NCIdlFunctions {
}
}
+ protected def testExpectedError(f: String): Unit =
+ try {
+ test(f)
+
+ require(false)
+ }
+ catch {
+ case e: NCE ⇒ println(s"Expected error: ${e.getLocalizedMessage}")
+ case e: Exception ⇒ throw e
+ }
+
protected implicit def convert(pred: String): TestDesc = TestDesc(truth =
pred)
}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
index bcd33df..1e89459 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
@@ -25,26 +25,15 @@ import org.junit.jupiter.api.Test
* Tests for 'math' functions.
*/
class NCIdlFunctionsMath extends NCIdlFunctions {
- private def testError(f: String): Unit =
- try {
- test(f)
-
- require(false)
- }
- catch {
- case e: NCE ⇒ println(s"Expected error: ${e.getLocalizedMessage}")
- case e: Exception ⇒ throw e
- }
-
@Test
def testError(): Unit = {
// Invalid name.
- testError("xxx(1, 1)")
- testError("xxx()")
+ testExpectedError("xxx(1, 1)")
+ testExpectedError("xxx()")
// Invalid arguments count.
- testError("atan(1, 1) == 1")
- testError("pi(1)")
+ testExpectedError("atan(1, 1) == 1")
+ testExpectedError("pi(1)")
}
@Test
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
index 3784115..1c5e37d 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
@@ -30,7 +30,27 @@ class NCIdlFunctionsStrings extends NCIdlFunctions {
"strip(' a b ') == 'a b'",
"uppercase('aB') == 'AB'",
"lowercase('aB') == 'ab'",
+ "is_alpha('aB') == true",
+ "is_alpha('aB1') == false",
+ "is_alphanum('aB1') == true",
+ "is_whitespace(' ') == true",
+ "is_whitespace('A') == false",
"is_num('a') == false",
- "is_num('1') == true"
+ "is_num('1') == true",
+ "is_numspace('A') == false",
+ "is_alphaspace('A') == true",
+ "is_alphanumspace('A') == true",
+ "is_alphanumspace(' ') == true",
+ "is_alphanumspace('1 A') == true",
+ "is_alphanumspace(' ') == true",
+ "is_alphanumspace(' ') == true",
+ "split('1 A') == list(1, 2)"
)
+
+ @Test
+ def testError(): Unit = {
+ // TODO: add correct test for `split` and `split_trim`
+ testExpectedError("split('1 A') == true")
+ testExpectedError("split_trim('1 A') == true")
+ }
}