summaryrefslogtreecommitdiffstats
path: root/test/commit.tcl
blob: 1cf780b88c5538711ea976b7b3ef425b924281ba (plain)
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
Assert programBall has program {{this} {
    Commit { Claim $this has a ball at x 100 y 100 }

    When $this has a ball at x /x/ y /y/ {
        After 10 milliseconds {
            Commit { Claim $this has a ball at x $x y [expr {$y+1}] }
            if {$y > 115} { set ::done true }
        }
    }
}}
Step

vwait ::done

Retract programBall has program /something/

Assert programUpdate has program {{this} {
    Commit { Claim $this has seen 0 boops }

    Every time there is a boop & $this has seen /n/ boops {
        Commit { Claim $this has seen [expr {$n + 1}] boops }
    }
}}
Assert there is a boop
Step

assert {[dict get [lindex [Statements::findMatches [list /someone/ claims /thing/ has seen /n/ boops]] 0] n] eq 1}

Retract there is a boop
Assert there is a boop
Step

assert {[dict get [lindex [Statements::findMatches [list /someone/ claims /thing/ has seen /n/ boops]] 0] n] eq 2}

#################

Assert programTestReset has program {{this} {
    When $this has context color /color/ {
        Commit { Claim $this has counter 0 }
        Every time a button is pressed & $this has counter /counter/ {
            Commit { Claim $this has counter [incr counter] }
        }
    }
}}
Assert programTestReset has context color red
Assert a button is pressed
Step
Retract a button is pressed
Assert a button is pressed
Step
Retract a button is pressed
Assert a button is pressed
Step
proc getCounter {} {
    set results [Statements::findMatches [list /someone/ claims programTestReset has counter /counter/]]
    set firstResult [lindex $results 0]
    dict get $firstResult counter
}
assert {[getCounter] == 3}

Retract programTestReset has context color red
Assert programTestReset has context color blue
Step
assert {[getCounter] == 1}