Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from anatoliykmetyuk/mutable
Mutable binding classes
- Loading branch information
Showing
7 changed files
with
173 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xsd:schema xmlns="http://simple/main" | ||
targetNamespace="http://simple/main" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
elementFormDefault="qualified"> | ||
|
||
<xsd:element name="aElem" type="AElem"/> | ||
|
||
<xsd:complexType name="AElem"> | ||
<xsd:sequence> | ||
<xsd:element name="bElem" type="BElem" minOccurs="0" maxOccurs="unbounded"/> | ||
</xsd:sequence> | ||
<xsd:attribute name="dummy" type="xsd:string" use="optional" default="foo"/> | ||
</xsd:complexType> | ||
|
||
<xsd:complexType name="BElem"> | ||
<xsd:sequence> | ||
<xsd:element name="cElem" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/> | ||
</xsd:sequence> | ||
</xsd:complexType> | ||
</xsd:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import scalaxb.compiler.Config | ||
import scalaxb.compiler.ConfigEntry._ | ||
|
||
object MutableTest extends TestBase { | ||
val pkgname = "mutabletest" | ||
val ns = "http://simple/main" | ||
|
||
val schema = resource("anotherSimpleSchema.xsd") | ||
val targetXml = | ||
(<n:aElem xmlns:n={ns}> | ||
<n:bElem> | ||
<n:cElem>Foo</n:cElem> | ||
</n:bElem> | ||
<n:bElem> | ||
<n:cElem>Bar</n:cElem> | ||
</n:bElem> | ||
<n:bElem> | ||
<n:cElem>Boo</n:cElem> | ||
</n:bElem> | ||
</n:aElem>).toString.replace("\n", "") | ||
|
||
val setup = s""" | ||
import $pkgname._ | ||
|
||
val elem = scalaxb.fromXML[AElem]($targetXml) | ||
""" | ||
|
||
def genXml(elemName: String) = s""" | ||
scalaxb.toXML( | ||
obj = $elemName | ||
, namespace = Some("$ns") | ||
, elementLabel = Some("aElem") | ||
, scope = scalaxb.toScope(Some("n") -> "$ns") | ||
, typeAttribute = false | ||
) | ||
""" | ||
|
||
|
||
lazy val generated = module.processFiles( | ||
List(schema), | ||
Config.default | ||
.update(PackageNames(Map(None -> Some(pkgname)))) | ||
.update(Outdir(tmp)) | ||
.update(GenerateMutable) | ||
.remove(VarArg) // VarArg is removed automatically in the command line app | ||
) | ||
|
||
"It should be possible to modify the nodes" in repl(generated)(s""" | ||
$setup | ||
|
||
elem.bElem = Nil | ||
${genXml("elem")}.toString | ||
""", | ||
"""<n:aElem xmlns:n="http://simple/main"/>""" | ||
) | ||
|
||
"It should be possible to modify the attributes" in repl(generated)(s""" | ||
$setup | ||
|
||
elem.dummy = "bar" | ||
elem.bElem = Nil | ||
${genXml("elem")}.toString | ||
""", | ||
"""<n:aElem dummy="bar" xmlns:n="http://simple/main"/>""" | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters