public
Description: The Nu programming language.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nu.git
nu / test / test_errors.nu
100644 92 lines (72 sloc) 3.438 kb
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
;; test_errors.nu
;; tests for Nu errors that throw exceptions.
;;
;; Copyright (c) 2007 Tim Burks, Neon Design Technology, Inc.
 
;; use these functions to call class construction operators outside of any class scope.
(function misplaced-imethod () (imethod foo is nil))
(function misplaced-cmethod () (cmethod foo is nil))
(function misplaced-ivar () (ivar (id) foo))
(function misplaced-ivars () (ivars))
 
(class TestErrors is NuTestCase
     
     (imethod (id) testMisplacedImethod is
          (try
               (misplaced-imethod)
               (catch (exception) (set myException exception)))
          (assert_equal "NuMisplacedDeclaration" (myException name)))
     
     (imethod (id) testMisplacedCmethod is
          (try
               (misplaced-cmethod)
               (catch (exception) (set myException exception)))
          (assert_equal "NuMisplacedDeclaration" (myException name)))
     
     (imethod (id) testMisplacedIvar is
          (try
               (misplaced-ivar)
               (catch (exception) (set myException exception)))
          (assert_equal "NuMisplacedDeclaration" (myException name)))
     
     (imethod (id) testMisplacedIvars is
          (try
               (misplaced-ivars)
               (catch (exception) (set myException exception)))
          (assert_equal "NuMisplacedDeclaration" (myException name)))
     
     (imethod (id) testUndefinedClass is
          (try
               (class Undefined)
               (catch (exception) (set myException exception)))
          (assert_equal "NuUndefinedClass" (myException name)))
     
     (imethod (id) testUndefinedSuperClass is
          (try
               (class Undefined is AlsoUndefined)
               (catch (exception) (set myException exception)))
          (assert_equal "NuUndefinedSuperclass" (myException name)))
     
     (imethod (id) testParseError is
          (try
              (parse "(1 + ))") ;; parse error
              (catch (exception) (set myException exception)))
          (assert_equal "NuParseError" (myException name)))
     
     (imethod (id) testUndefinedSymbol is
          (try
              foo ;; undefined symbol
              (catch (exception) (set myException exception)))
          (assert_equal "NuUndefinedSymbol" (myException name)))
     
     (imethod (id) testCarOnAtom is
          (try
              (car 'foo) ;; can't call car on atoms
              (catch (exception) (set myException exception)))
          (assert_equal "NuCarCalledOnAtom" (myException name)))
     
     (imethod (id) testCdrOnAtom is
          (try
              (cdr 'foo) ;; can't call cdr on atoms
              (catch (exception) (set myException exception)))
          (assert_equal "NuCdrCalledOnAtom" (myException name)))
     
     (imethod (id) testIncorrectNumberOfBlockArguments is
          (try
              ((do (x y) (+ x y)) 1 2 3) ;; incorrect number of block arguments
              (catch (exception) (set myException exception)))
          (assert_equal "NuIncorrectNumberOfArguments" (myException name)))
     
     (imethod (id) testNoInstanceVariable is
          (try
              (class TestClass is NSObject
                   (imethod (id) accessMissingIvar is @foo))
              (((TestClass alloc) init) accessMissingIvar)
              (catch (exception) (set myException exception)))
          (assert_equal "NuNoInstanceVariable" (myException name))))