Skip to content

Commit 80ed8ba

Browse files
committed
emptyness check for texttree
1 parent 4867f4c commit 80ed8ba

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/strings/TextTree.scala

+13
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ object TextTree {
6767
}
6868
}
6969

70+
def isEmpty: Boolean = {
71+
target match {
72+
case _: ValueNode[T] => false
73+
case s: StringNode => s.value.isEmpty
74+
case s: Shift[T] => s.nested.isEmpty
75+
case t: Trim[T] => t.nested.isEmpty
76+
case n: Node[T] =>
77+
n.chunks.forall(_.isEmpty)
78+
}
79+
}
80+
81+
def nonEmpty: Boolean = !isEmpty
82+
7083
def flatten: TextTree[T] = {
7184
target match {
7285
case v: ValueNode[T] => Node(NEList(v))

fundamentals/fundamentals-platform/src/test/scala/izumi/fundamentals/platform/TextTreeTest.scala

+11
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ class TextTreeTest extends AnyWordSpec {
9999
accept(t5)
100100
}
101101
}
102+
103+
"support emptiness check" in {
104+
val q1 = q""
105+
val q2 = q"$q1"
106+
val q3 = q"x$q1"
107+
108+
assert(q1.isEmpty)
109+
assert(q2.isEmpty)
110+
assert(q3.nonEmpty)
111+
112+
}
102113
}
103114
}
104115

0 commit comments

Comments
 (0)