Skip to content

Commit

Permalink
More tests and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvaro Carrasco committed Jan 11, 2014
1 parent 597f222 commit 07fd711
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
6 changes: 6 additions & 0 deletions plugin/src/main/scala/com/gravitydev/s2js/Printer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ object Printer extends PrettyPrinter {
case Ident(name, _) => name

case This => "this"

case Void => ""

case x => "UNKNOWN: " <> x.toString
}
Expand Down Expand Up @@ -120,6 +122,10 @@ object Printer extends PrettyPrinter {
"throw" <+> showInner(x)
}

case Return(x) => {
"return" <+> showInner(x)
}

// top-level selects
case Select(Ident("$toplevel", Type("_scala_", Nil)), name, _) => name

Expand Down
4 changes: 3 additions & 1 deletion plugin/src/main/scala/com/gravitydev/s2js/Translator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class Translator (val global: Global) {
if (x == null) ast.Null
else {
val tpe = getType(l.tpe).asInstanceOf[ast.Type with ast.BuiltInType]
val value = if (tpe == ast.Types.StringT) "\"" + x.toString + "\"" else x.toString
val value = if (tpe == ast.Types.StringT) "\"" + x.toString.replace("\"", "\\\"") + "\"" else x.toString
ast.Literal(value, tpe)
}
}
Expand Down Expand Up @@ -317,6 +317,8 @@ class Translator (val global: Global) {

case This(qual) => ast.This

case Return(x) => ast.Return(getTree(x))

case x => {
//sys.error("not implemented for " + x.getClass)
println(x)
Expand Down
7 changes: 6 additions & 1 deletion plugin/src/test/resources/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ false
#### sys.error
sys.error("Error")
----
throw new Error("Error")
throw new Error("Error")

#### codePoint
"".codePointAt(0)
----
"".charCodeAt(0)
8 changes: 7 additions & 1 deletion plugin/src/test/resources/temp.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#### codePoint
"".codePointAt(0)
import goog.events.KeyEvent
class X {
def getValue (k: KeyEvent) = {
if (k.charCode == "".codePointAt(0)) "x" else "y"
}
}
----

"".charCodeAt(0)
8 changes: 5 additions & 3 deletions plugin/src/test/scala/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ class BasicCompilerSpec extends FunSpec {

describe("Expressions Compiler") {
val basePath = "/Users/alvarocarrasco/workspace/s2js/plugin/src/test/resources"


/*
parseFile(basePath + "/expressions.txt") map {case (title, sc, js) => ExpressionCompiler.checkCode(sc, js, title)}
parseFile(basePath + "/browser.txt") map {case (title, sc, js) => StatementCompiler.checkCode(sc, js, title)}
parseFile(basePath + "/collections.txt") map {case (title, sc, js) => ExpressionCompiler.checkCode(sc, js, title)}
parseFile(basePath + "/statements.txt") map {case (title, sc, js) => StatementCompiler.checkCode(sc, js, title)}
parseFile(basePath + "/modules.txt") map {case (title, sc, js) => CompilationUnitCompiler.checkCode(sc, js, title)}
parseFile(basePath + "/classes.txt") map {case (title, sc, js) => CompilationUnitCompiler.checkCode(sc, js, title)}

parseFile(basePath + "/temp.txt") map {case (title, sc, js) => ExpressionCompiler.checkCode(sc, js, title)}
*/

parseFile(basePath + "/temp.txt") map {case (title, sc, js) => CompilationUnitCompiler.checkCode(sc, js, title)}

//parseFile(basePath + "/map2.txt") map {case (title, sc, js) => CompilationUnitCompiler.checkCode(sc, js, title)}

Expand Down

0 comments on commit 07fd711

Please sign in to comment.