-
Notifications
You must be signed in to change notification settings - Fork 92
Fix #49: Add Scala.js support #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package scala.xml | ||
|
||
import scala.xml.transform._ | ||
import org.junit.Test | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Assert.assertEquals | ||
import org.junit.runner.RunWith | ||
/** | ||
* This test verify that after the tranform, the resultant xml node | ||
* uses as many old nodes as possible. | ||
* | ||
* Three transformers class for case - | ||
* One for orginal, one for modified, and one proposed which shows | ||
* all are equivalent when it comes to reusing as many nodes as possible | ||
*/ | ||
object ReuseNodesTest { | ||
|
||
class OriginalTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) { | ||
override def transform(ns: Seq[Node]): Seq[Node] = { | ||
val xs = ns.toStream map transform | ||
val (xs1, xs2) = xs zip ns span { case (x, n) => unchanged(n, x) } | ||
|
||
if (xs2.isEmpty) ns | ||
else (xs1 map (_._2)) ++ xs2.head._1 ++ transform(ns drop (xs1.length + 1)) | ||
} | ||
override def transform(n:Node): Seq[Node] = super.transform(n) | ||
} | ||
|
||
class ModifiedTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) { | ||
override def transform(ns: Seq[Node]): Seq[Node] = { | ||
val changed = ns flatMap transform | ||
|
||
if (changed.length != ns.length || (changed, ns).zipped.exists(_ != _)) changed | ||
else ns | ||
} | ||
override def transform(n:Node): Seq[Node] = super.transform(n) | ||
} | ||
|
||
class AlternateTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) { | ||
override def transform(ns: Seq[Node]): Seq[Node] = { | ||
val xs = ns.toStream map transform | ||
val (xs1, xs2) = xs zip ns span { case (x, n) => unchanged(n, x) } | ||
|
||
if (xs2.isEmpty) ns | ||
else (xs1 map (_._2)) ++ xs2.head._1 ++ transform(ns drop (xs1.length + 1)) | ||
} | ||
override def transform(n:Node): Seq[Node] = super.transform(n) | ||
} | ||
|
||
def rewriteRule = new RewriteRule { | ||
override def transform(n: Node): NodeSeq = n match { | ||
case n if n.label == "change" => Elem( | ||
n.prefix, "changed", n.attributes, n.scope, n.child.isEmpty, n.child : _*) | ||
case _ => n | ||
} | ||
} | ||
|
||
} |
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,68 @@ | ||
package scala.xml | ||
|
||
import org.junit.Test | ||
import org.junit.Ignore | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.JUnit4 | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertEquals | ||
|
||
class XMLSyntaxTest { | ||
|
||
private def handle[A](x: Node): A = { | ||
x.child(0).asInstanceOf[Atom[A]].data | ||
} | ||
|
||
@Test | ||
def test1(): Unit = { | ||
val xNull = <hello>{null}</hello> // these used to be Atom(unit), changed to empty children | ||
assertTrue(xNull.child sameElements Nil) | ||
|
||
val x0 = <hello>{}</hello> // these used to be Atom(unit), changed to empty children | ||
val x00 = <hello>{ }</hello> // dto. | ||
val xa = <hello>{ "world" }</hello> | ||
|
||
assertTrue(x0.child sameElements Nil) | ||
assertTrue(x00.child sameElements Nil) | ||
assertEquals("world", handle[String](xa)) | ||
|
||
val xb = <hello>{ 1.5 }</hello> | ||
assertEquals(1.5, handle[Double](xb), 0.0) | ||
|
||
val xc = <hello>{ 5 }</hello> | ||
assertEquals(5, handle[Int](xc)) | ||
|
||
val xd = <hello>{ true }</hello> | ||
assertEquals(true, handle[Boolean](xd)) | ||
|
||
val xe = <hello>{ 5:Short }</hello> | ||
assertEquals((5:Short), handle[Short](xe)) | ||
|
||
val xf = <hello>{ val x = 27; x }</hello> | ||
assertEquals(27, handle[Int](xf)) | ||
|
||
val xg = <hello>{ List(1,2,3,4) }</hello> | ||
assertEquals("<hello>1 2 3 4</hello>", xg.toString) | ||
assertFalse(xg.child.map(_.isInstanceOf[Text]).exists(identity)) | ||
|
||
val xh = <hello>{ for(x <- List(1,2,3,4) if x % 2 == 0) yield x }</hello> | ||
assertEquals("<hello>2 4</hello>", xh.toString) | ||
assertFalse(xh.child.map(_.isInstanceOf[Text]).exists(identity)) | ||
} | ||
|
||
/** see SVN r13821 (emir): support for <elem key={x:Option[Seq[Node]]} />, | ||
* so that Options can be used for optional attributes. | ||
*/ | ||
@Test | ||
def test2(): Unit = { | ||
val x1: Option[Seq[Node]] = Some(<b>hello</b>) | ||
val n1 = <elem key={x1} />; | ||
assertEquals(x1, n1.attribute("key")) | ||
|
||
val x2: Option[Seq[Node]] = None | ||
val n2 = <elem key={x2} />; | ||
assertEquals(x2, n2.attribute("key")) | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cleanup of the build.sbt file and modernization for other compilers is great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the
publish-signed
task work with the new changes to SBT? The admin/build.sh file is run by Travis, and when it's for a Git tag, it will copy the admin/publish-settings.sbt file to the root directory. Looks like it will cause SBT to fail to load: