/
DefaultTSTypeTests.scala
91 lines (76 loc) · 3.31 KB
/
DefaultTSTypeTests.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package nl.codestar.scalatsi
import nl.codestar.scalatsi.TypescriptType._
import org.scalactic.source
import org.scalatest.words.StringVerbBlockRegistration
import org.scalatest.{Matchers, WordSpec}
class DefaultTSTypeTests extends WordSpec with Matchers with DefaultTSTypes {
"Default TS Types should be defined" forWord {
"String" in { "implicitly[TSType[String]]" should compile }
"Boolean" in { "implicitly[TSType[Boolean]]" should compile}
"Int" in { "implicitly[TSType[Int]]" should compile }
"Long" in { "implicitly[TSType[Long]]" should compile }
"Double" in { "implicitly[TSType[Double]]" should compile }
"scala.math.BigDecimal" in { "implicitly[TSType[scala.math.BigDecimal]]" should compile }
"java.math.BigDecimal" in { "implicitly[TSType[java.math.BigDecimal]]" should compile }
"scala.math.BigInt" in { "implicitly[TSType[scala.math.BigInt]]" should compile }
"Tuple2" in {
"implicitly[TSType[(Int, String)]]" should compile
val generated = implicitly[TSType[(Int, String)]].get
val manual = TSTuple.of(implicitly[TSType[Int]].get, implicitly[TSType[String]].get)
generated should ===(manual)
}
"Tuple3" in {
"implicitly[TSType[(Int, String, Double)]]" should compile
val generated = implicitly[TSType[(Int, String, Double)]].get
val manual = TSTuple.of(implicitly[TSType[Int]].get, implicitly[TSType[String]].get, implicitly[TSType[Double]].get)
generated should ===(manual)
}
"Option" in {
"implicitly[TSType[Option[Int]]]" should compile
val generated = implicitly[TSType[Option[Int]]].get
val manual = implicitly[TSType[Int]] | TSNull
generated should ===(manual)
}
"Either" in {
"implicitly[TSType[Either[Int, String]]]" should compile
val generated = implicitly[TSType[Either[Int, String]]].get
val manual = implicitly[TSType[Int]] | implicitly[TSType[String]]
generated should ===(manual)
}
"Map[String, _]" in {
"implicitly[TSType[Map[String, Int]]]" should compile
}
"Map[Int, _]" in {
"implicitly[TSType[Map[Int, Int]]]" should compile
}
"Seq[_]" in {
"implicitly[TSType[scala.collection.mutable.Seq[Int]]]" should compile
"implicitly[TSType[scala.collection.immutable.Seq[Int]]]" should compile
"implicitly[TSType[IndexedSeq[Int]]]" should compile
"implicitly[TSType[List[Int]]]" should compile
"implicitly[TSType[Vector[Int]]]" should compile
}
"Set[_]" in {
"implicitly[TSType[Set[Int]]]" should compile
"implicitly[TSType[scala.collection.immutable.HashSet[Int]]]" should compile
}
"Collection<?>" in {
"implicitly[TSType[java.util.Collection[Int]]]" should compile
"implicitly[TSType[java.util.List[Int]]]" should compile
"implicitly[TSType[java.util.ArrayList[Int]]]" should compile
}
}
import scala.language.implicitConversions
implicit def convertToStringHasWrapperForVerb(o: String)(implicit position: source.Position): HasWrapper =
new HasWrapper {
override val leftSideString = o.trim
override val pos = position
}
trait HasWrapper {
val leftSideString: String
val pos : source.Position
def forWord(right: => Unit)(implicit fun: StringVerbBlockRegistration): Unit = {
fun(leftSideString, "for", pos, right _)
}
}
}