Skip to content

Commit

Permalink
Fixed bug with parameters, regex and pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
systay committed Nov 18, 2011
1 parent bbcb277 commit 2131d45
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
Expand Up @@ -109,7 +109,7 @@ case class RegularExpression(a: Value, regex: Value) extends Clause {
regex(m).toString.r.pattern.matcher(value).matches()
}

def dependsOn: Set[ String ] = a.dependsOn
def dependsOn: Set[ String ] = a.dependsOn ++ regex.dependsOn

def atoms: Seq[ Clause ] = Seq(this)

Expand Down
45 changes: 27 additions & 18 deletions cypher/src/test/scala/org/neo4j/cypher/ExecutionEngineTest.scala
Expand Up @@ -70,6 +70,16 @@ class ExecutionEngineTest extends ExecutionEngineHelper {
assertEquals(List(n1), result.columnAs[Node]("node").toList)
}

@Test def shouldBeAbleToUseParamsInPatternMatchingPredicates() {
val n1 = createNode()
val n2 = createNode()
relate(n1, n2, "A", Map("foo" -> "bar"))

val result = parseAndExecute("start a=node(1) match a-[r]->b where r.foo =~ {param} return b", "param" -> "bar")

assertEquals(List(n2), result.columnAs[Node]("b").toList)
}

@Test def shouldGetOtherNode() {
val node: Node = createNode()

Expand Down Expand Up @@ -1126,23 +1136,23 @@ return distinct a
order by a.name
""")

assert(List(a,b,c) === result.columnAs[Node]("a") .toList)
assert(List(a, b, c) === result.columnAs[Node]("a").toList)
}

@Test def shouldHandleAggregationOnFunctions() {
val a = createNode("A")
val b = createNode("B")
val c = createNode("C")
relate(a,b,"X")
relate(a,c,"X")
relate(a, b, "X")
relate(a, c, "X")

val result = parseAndExecute("""
start a = node(1)
match p = a -[*]-> b
return b, avg(length(p))
""")

assert(List(b,c) === result.columnAs[Node]("b") .toList)
assert(List(b, c) === result.columnAs[Node]("b").toList)
}

@Test def shouldHandleOptionalPaths() {
Expand All @@ -1158,8 +1168,8 @@ return x, p
""")

assert(List(
Map("x"->b, "p"->PathImpl(a,r,b)),
Map("x"->c, "p"->null)
Map("x" -> b, "p" -> PathImpl(a, r, b)),
Map("x" -> c, "p" -> null)
) === result.toList)
}

Expand All @@ -1176,8 +1186,8 @@ return x, p
""")

assert(List(
Map("x"->b, "p"->PathImpl(a,r,b)),
Map("x"->c, "p"->null)
Map("x" -> b, "p" -> PathImpl(a, r, b)),
Map("x" -> c, "p" -> null)
) === result.toList)
}

Expand All @@ -1193,7 +1203,7 @@ return p
""")

assert(List(
Map("p"->null)
Map("p" -> null)
) === result.toList)
}

Expand All @@ -1210,13 +1220,13 @@ return x, p
""")

assert(List(
Map("x"->b, "p"->PathImpl(a,r,b)),
Map("x"->c, "p"->null)
Map("x" -> b, "p" -> PathImpl(a, r, b)),
Map("x" -> c, "p" -> null)
) === result.toList)
}

@Test def shouldSupportMultipleRegexes() {
val a = createNode(Map("name"->"Andreas"))
val a = createNode(Map("name" -> "Andreas"))


val result = parseAndExecute("""
Expand All @@ -1225,22 +1235,21 @@ where a.name =~ /And.*/ AND a.name =~ /And.*/
return a
""")

assert(List(a) === result.columnAs[Node]("a") .toList)
assert(List(a) === result.columnAs[Node]("a").toList)
}


@Test(expected = classOf[SyntaxException]) def shouldNotSupportSortingOnThingsAfterDistinctHasRemovedIt() {
val a = createNode("name"->"A", "age"->13)
val b = createNode("name"->"B", "age"->12)
val c = createNode("name"->"C", "age"->11)
val a = createNode("name" -> "A", "age" -> 13)
val b = createNode("name" -> "B", "age" -> 12)
val c = createNode("name" -> "C", "age" -> 11)

val result = parseAndExecute("""
start a = node(1,2,3,1)
return distinct a.name
order by a.age
""")

assert(List(a,b,c) === result.columnAs[Node]("a") .toList)
assert(List(a, b, c) === result.columnAs[Node]("a").toList)
}

@Test def shouldThrowNiceErrorMessageWhenPropertyIsMissing() {
Expand Down

0 comments on commit 2131d45

Please sign in to comment.