Add isEmpty, isNotEmpty, and isBlank methods to ObjString, update tests and docs
This commit is contained in:
1 parent
d4bb186f85
commit
05e15e8e42
3 files changed
+76
-2
No files matched your search
@@ -301,6 +301,18 @@ data class ObjString(val value: String) : Obj() {
|
||||
) {
|
||||
thisAs<ObjString>().value.trim().let(::ObjString)
|
||||
}
|
||||
addFnDoc("isBlank", "Whether this string is empty or contains only whitespace characters.",
|
||||
returns = type("lyng.Bool"), moduleName = "lyng.stdlib") {
|
||||
ObjBool(thisAs<ObjString>().value.isBlank())
|
||||
}
|
||||
addFnDoc("isEmpty", "Whether this string is empty.",
|
||||
returns = type("lyng.Bool"), moduleName = "lyng.stdlib") {
|
||||
ObjBool(thisAs<ObjString>().value.isEmpty())
|
||||
}
|
||||
addFnDoc("isNotEmpty", "Whether this string is not empty.",
|
||||
returns = type("lyng.Bool"), moduleName = "lyng.stdlib") {
|
||||
ObjBool(thisAs<ObjString>().value.isNotEmpty())
|
||||
}
|
||||
addFnDoc(
|
||||
name = "matches",
|
||||
doc = "Whether this string matches the given regular expression or pattern string.",
|
||||
|
||||
@@ -779,7 +779,8 @@ class OOTest {
|
||||
|
||||
@Test
|
||||
fun testOverrideVisibilityRules1() = runTest {
|
||||
eval("""
|
||||
val scope = Script.newScope()
|
||||
scope.eval("""
|
||||
interface Base {
|
||||
abstract protected fun foo()
|
||||
|
||||
@@ -802,12 +803,70 @@ class OOTest {
|
||||
class Derived2: Base {
|
||||
private var value = 42
|
||||
|
||||
private fun fooPrivateImpl() = value
|
||||
|
||||
override protected fun foo() {
|
||||
if( value < 10 ) 10 else value
|
||||
fooPrivateImpl()
|
||||
value++
|
||||
}
|
||||
}
|
||||
assertEquals("bar!", Derived().bar())
|
||||
val d = Derived2()
|
||||
assertEquals(42, d.bar())
|
||||
assertEquals(43, d.bar())
|
||||
""".trimIndent())
|
||||
scope.createChildScope().eval("""
|
||||
assertEquals("bar!", Derived().bar())
|
||||
assertEquals(42, Derived2().bar())
|
||||
""".trimIndent())
|
||||
}
|
||||
@Test
|
||||
fun testOverrideVisibilityRules2() = runTest {
|
||||
val scope = Script.newScope()
|
||||
scope.eval("""
|
||||
interface Base {
|
||||
abstract fun foo()
|
||||
|
||||
fun bar() {
|
||||
// it must see foo() as it is protected and
|
||||
// is declared here (even as abstract):
|
||||
foo()
|
||||
}
|
||||
}
|
||||
class Derived : Base {
|
||||
protected val suffix = "!"
|
||||
|
||||
private fun fooPrivateImpl() = "bar"
|
||||
|
||||
override fun foo() {
|
||||
// it should access own private and all protected memberes here:
|
||||
fooPrivateImpl() + suffix
|
||||
}
|
||||
}
|
||||
class Derived2: Base {
|
||||
private var value = 42
|
||||
|
||||
private fun fooPrivateImpl() = value
|
||||
|
||||
override fun foo() {
|
||||
fooPrivateImpl()
|
||||
value++
|
||||
}
|
||||
}
|
||||
assertEquals("bar!", Derived().bar())
|
||||
val d = Derived2()
|
||||
assertEquals(42, d.bar())
|
||||
assertEquals(43, d.bar())
|
||||
""".trimIndent())
|
||||
scope.createChildScope().eval("""
|
||||
assertEquals("bar!", Derived().bar())
|
||||
assertEquals(42, Derived2().bar())
|
||||
import lyng.serialization
|
||||
for( i in 1..100 ) {
|
||||
val d2 = Lynon.decode(Lynon.encode(Derived2()))
|
||||
assertEquals(42, d2.bar())
|
||||
assertEquals(43, d2.bar())
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user