public
Description: The Nu programming language.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nu.git
nu / test / test_interface.nu
100644 30 lines (26 sloc) 1.227 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
;; test_interface.nu
;; tests for the Nu public interface.
;;
;; Copyright (c) 2007 Tim Burks, Neon Design Technology, Inc.
 
(class TestInterface is NuTestCase
     
     ;; all of these calls could be made from Objective-C
     ;; using methods that are declared in Nu/Nu.h
     (imethod (id) testParser is
          ;; create a parser
          (set parser (Nu parser))
          ;; set a variable in the top-level context using KVC
          (parser setValue:2 forKey:"x")
          ;; parse text into an evaluatable object
          (set code (parser parse:"(set x (+ x x))"))
          ;; evaluate the parsed code
          (set result (parser eval:code))
          (assert_equal 4 result)
          ;; parsed code objects can be evaluated any number of times
          (set result (parser eval:code))
          (assert_equal 8 result)
          ;; KVC is broadly interpreted to allow any Nu expression as a key
          (assert_equal 16 (parser valueForKey:"(+ x x)"))
          ;; But for setting, the key must be a symbol name
          (parser setValue:"hello" forKey:"y")
          ;; Symbol values can also be looked up using parse: and eval:
          (assert_equal "hello" (parser eval:(parser parse:"y")))))