motemen (owner)

Fork Of

Revisions

gist: 143011 Download_button fork
public
Public Clone URL: git://gist.github.com/143011.git
Embed All Files: show embed
TAP.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
object Main extends Application {
  object TAP {
    var number:Int = 1
 
    var directive = ""
 
    def plan (planNum:Int) {
      println(
        "1.." + planNum
      )
    }
 
    def skip (desc:String)(block: => Unit) {
      directive = "SKIP " + desc
      block
      directive = ""
    }
 
    def todo (desc:String)(block: => Unit) {
      directive = "TODO " + desc
      block
      directive = ""
    }
 
    def ok (bool:Boolean, desc:String) {
      println(
        (if (bool) "ok" else "not ok") + " " + number +
        (if (desc.isEmpty) "" else " - " + desc) +
        (if (directive.isEmpty) "" else " # " + directive)
      )
      number += 1
    }
 
    def is (self:Any, other:Any, desc:String) {
      ok(self == other, desc)
    }
  }
 
  class TestObject (self:Any) {
    def is (other:Int) {
      TAP.is(self, other, "")
    }
 
    def is (other:TestDescription) {
      TAP.is(self, other.self, other.description)
    }
  }
 
  class TestDescription (_self:Any) {
    val self : Any = _self
    var description : String = ""
    def apply (desc:String) = {
      description = desc
      this
    }
  }
 
  implicit def testobj (o:Any):TestObject = new TestObject(o)
  implicit def testdesc (o:Any):TestDescription = new TestDescription(o)
 
  TAP.plan(1)
  TAP.is(1, 1, "foo")
 
  1 is 1 ("Trivial")
 
  TAP.todo("foobar") {
    TAP.is(1, 1, "foo")
  }
}
 
Main