Skip to content

Commit c88dd69

Browse files
authored
include both properties and contained nodes in NewNode.copy (#106)
1 parent f1dc1a6 commit c88dd69

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

codegen/src/main/scala/overflowdb/codegen/CodeGen.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,8 +1674,8 @@ class CodeGen(schema: Schema) {
16741674
}
16751675
}.mkString("\n")
16761676

1677-
val copyPropertiesImpl = properties.map { property =>
1678-
val memberName = camelCase(property.name)
1677+
val copyFieldsImpl = fieldDescriptions.map { field =>
1678+
val memberName = field.name
16791679
s"newInstance.$memberName = this.$memberName"
16801680
}.mkString("\n")
16811681

@@ -1697,7 +1697,7 @@ class CodeGen(schema: Schema) {
16971697
|
16981698
| override def copy: this.type = {
16991699
| val newInstance = new New$nodeClassName
1700-
| $copyPropertiesImpl
1700+
| $copyFieldsImpl
17011701
| newInstance.asInstanceOf[this.type]
17021702
| }
17031703
|

integration-tests/tests/src/test/scala/Schema04Test.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,21 @@ class Schema04Test extends AnyWordSpec with Matchers {
168168
node1.intList shouldBe IndexedSeq(1,2,3)
169169
edge1.intList shouldBe IndexedSeq(3,4,5)
170170
}
171+
172+
"NewNode.copy includes contained nodes" in {
173+
val node1 = NewNode1()
174+
.bool(true)
175+
.str("foo")
176+
.intList(Seq(1,2,3): Seq[Integer])
177+
178+
val node2 = NewNode1().node1Inner(node1)
179+
180+
val node1Copy = node1.copy
181+
node1Copy.bool shouldBe true
182+
node1Copy.str shouldBe "foo"
183+
node1Copy.intList shouldBe Seq(1,2,3)
184+
185+
val node2Copy = node2.copy
186+
node2Copy.node1Inner shouldBe node1
187+
}
171188
}

0 commit comments

Comments
 (0)