public
Description: ioke is a new language for the JVM, based on Io and other languages.
Homepage: http://ioke.org
Clone URL: git://github.com/olabini/ioke.git
ioke / test / let_spec.ik
100644 75 lines (63 sloc) 2.114 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
 
use("ispec")
 
describe(DefaultBehavior,
  describe("FlowControl",
    describe("let",
      it("should take a code argument, apply that on the current ground and return the result",
        let(40+2) should == 42
      )
 
      it("should establish a new lexical scope inside",
        let(non_existing_let_binding = 42)
        cell?(:non_existing_let_binding) should be false
      )
 
      it("should take zero or more name-value pairs",
        let(42)
        let(x, 42, x)
        let(
          x, 42,
          y, 43,
          x + y)
      )
 
      it("should bind a simple name to a value",
        let(probably_not_existing_name, 42,
          probably_not_existing_name*2) should == 84
      )
      
      it("should shadow an existing name",
        wow_this_is_a_test = 42
        let(wow_this_is_a_test, 43, wow_this_is_a_test) should == 43
        wow_this_is_a_test should == 42
      )
 
      it("should rebind a place specification during the time of the code running",
        Text fluxie = Origin mimic
        Text fluxie wowsie = 13
        let(
          Text fluxie wowsie, 14,
          "foo" fluxie wowsie) should == 14
        Text fluxie wowsie should == 13
      )
 
      it("should unbind places even if a non-local transfer happens",
        Text fluxie2 = Origin mimic
        Text fluxie2 wowsie = 13
        bind(rescue(Condition Error, fn(c, nil)),
          let(
            Text fluxie2 wowsie, 14,
            "foo" fluxie2 wowsie should == 14
            error!("non-local yay!")))
        Text fluxie2 wowsie should == 13
      )
 
      it("should bind a new place temporarily, and then remove it",
        X = Origin mimic
        let(X testOfLetMethod, method(42),
          X testOfLetMethod should == 42
        )
        X cellNames should not include(:testOfLetMethod)
      )
 
      it("should bind a new place with cell temporarily, and then remove it",
        X = Origin mimic
        let(X cell(:testOfLetMethod2), method(42),
          X testOfLetMethod2 should == 42
        )
        X cellNames should not include(:testOfLetMethod2)
      )
    )
  )
)