File: test.html

package info (click to toggle)
coffeescript 1.4.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,064 kB
  • ctags: 160
  • sloc: makefile: 60
file content (118 lines) | stat: -rw-r--r-- 2,345 bytes parent folder | download | duplicates (2)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <title>CoffeeScript Test Suite</title>
  <script src="../extras/coffee-script.js"></script>
  <style>
    body {
      margin: 30px;
      font-family: Menlo, Monaco, monospace;
    }
    h1 {
      font-size: 20px;
    }
    #stdout {
    }
  </style>
</head>
<body>

  <h1>CoffeeScript Test Suite</h1>
  <pre id="stdout"></pre>

  <script type="text/coffeescript">

  stdout  = document.getElementById 'stdout'
  start   = new Date
  success = total = done = failed = 0

  say = (msg) ->
    div = document.createElement 'div'
    div.appendChild document.createTextNode msg
    stdout.appendChild div
    msg

  @test = (desc, fn) ->
    fn()

  @ok = (good, msg) ->
    ++total
    if good then ++success else throw Error say msg

  @eq = (x, y, msg) -> ok x is y, msg ? x + ' !== ' + y

  arrayEqual = (a, b) ->
    if a is b
      # 0 isnt -0
      a isnt 0 or 1/a is 1/b
    else if a instanceof Array and b instanceof Array
      return no unless a.length is b.length
      return no for el, idx in a when not arrayEq el, b[idx]
      yes
    else
      # NaN is NaN
      a isnt a and b isnt b

  @doesNotThrow = (fn) ->
    fn()
    ok true

  @arrayEq = (a, b, msg) -> ok arrayEqual(a,b), msg

  @throws = (fun, err, msg) ->
    try
      fun()
    catch e
      if err
        eq e, err
      else
        ok yes
      return
    ok no

  run = (name) ->
    CoffeeScript.load "#{name}.coffee", ->
      say '\u2714 ' + name
      fin() if ++done is names.length

  fin = ->
    yay = success is total and not failed
    sec = (new Date - start) / 1000
    msg = "passed #{success} tests in #{ sec.toFixed 2 } seconds"
    msg = "failed #{ total - success } tests and #{msg}" unless yay
    say msg, yay

  run name for name in names = [
    'arrays'
    'assignment'
    'booleans'
    'classes'
    'comments'
    'compilation'
    'comprehensions'
    'control_flow'
    'exception_handling'
    'formatting'
    'function_invocation'
    'functions'
    'helpers'
    'importing'
    'interpolation'
    'javascript_literals'
    'numbers'
    'objects'
    'operators'
    'option_parser'
    'ranges'
    'regexps'
    'repl'
    'scope'
    'slicing_and_splicing'
    'soaks'
    'strings'
  ]
  </script>

</body>
</html>