public
Description: The Nu programming language.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nu.git
nu / test / test_protocols.nu
100644 28 lines (24 sloc) 1.197 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
;; test_protocols.nu
;; tests for Nu protocol support.
;;
;; Copyright (c) 2007 Tim Burks, Neon Design Technology, Inc.
 
(if (eq (uname) "Darwin")
    
    (class TestProtocols is NuTestCase
         
         (imethod (id) testSimple is
              ;; first define a class with two methods
              (class Foo is NSObject
                   (- hello is "hello")
                   (- goodbye is "goodbye"))
              ;; make sure that both methods work
              (set foo ((Foo alloc) init))
              (assert_equal "hello" (foo hello))
              (assert_equal "goodbye" (foo goodbye))
              ;; now declare a protocol that includes only one of them
              (protocol DontSayGoodbye
                   (- (id) hello))
              (assert_equal 1 ((DontSayGoodbye methodDescriptions) count))
              ;; give the instance and protocol to a protocol checker
              (set bar ((NSProtocolChecker alloc) initWithTarget:foo protocol:DontSayGoodbye))
              ;; try the two methods; only the one in the protocol should be allowed
              (assert_equal "hello" (bar hello))
              (assert_throws "NuUnknownMessage" (bar goodbye)))))