File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed
commonMain/kotlin/li/songe/selector
jvmTest/kotlin/li/songe/selector Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,12 @@ data class PropertyWrapper(
3636
3737 val isMatchRoot = segment.units.any {
3838 val e = it.expression
39- e is BinaryExpression && e.operator == CompareOperator .Equal && e.left.value == " parent" && e.right.value == " null"
39+ e is BinaryExpression && e.operator == CompareOperator .Equal && when {
40+ // null == Identifier(name="parent")
41+ e.right.value == null && e.left.value == " parent" -> true
42+ e.left.value == null && e.right.value == " parent" -> true
43+ else -> false
44+ }
4045 }
4146
4247 val fastQueryList by lazy { segment.fastQueryList ? : emptyList() }
Original file line number Diff line number Diff line change @@ -57,7 +57,10 @@ data class LogicalSelectorExpression(
5757 }
5858
5959 override val isMatchRoot: Boolean
60- get() = left.isMatchRoot && operator == SelectorLogicalOperator .AndOperator
60+ get() = when (operator ) {
61+ SelectorLogicalOperator .AndOperator -> left.isMatchRoot || right.isMatchRoot
62+ SelectorLogicalOperator .OrOperator -> left.isMatchRoot && right.isMatchRoot
63+ }
6164
6265 override val fastQueryList: List <FastQuery >
6366 get() = left.fastQueryList + right.fastQueryList
Original file line number Diff line number Diff line change @@ -163,4 +163,10 @@ class ParserUnitTest {
163163 println (" selector: ${ast.value} " )
164164 println (" ast: ${ast.stringify()} " )
165165 }
166+
167+ @Test
168+ fun root () {
169+ assert (Selector .parse(" [null=parent]" ).isMatchRoot)
170+ assert (Selector .parse(" [parent=null]" ).isMatchRoot)
171+ }
166172}
You can’t perform that action at this time.
0 commit comments