-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbind_test.go
52 lines (49 loc) · 1.33 KB
/
bind_test.go
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
package asyncpi
import (
"strings"
"testing"
)
func TestBindIdempotent(t *testing.T) {
const proc = `(new a)!(a<>|a().0)`
p, err := Parse(strings.NewReader(proc))
if err != nil {
t.Fatal(err)
}
p0 := p.Calculi()
if err := Bind(&p); err != nil {
t.Fatal(err)
}
p1 := p.Calculi()
if err := Bind(&p); err != nil {
t.Fatal(err)
}
p2 := p.Calculi()
if p0 != p1 {
t.Errorf("expect Bind to be idempotent but got: \nBefore:\t%s\nAfter:\t%s", p0, p1)
}
if p1 != p2 {
t.Errorf("expect Bind to be idempotent but got: \nBefore:\t%s\nAfter:\t%s", p1, p2)
}
}
func TestBindRebind(t *testing.T) {
const proc = `(new a)(a<> | a().(new a)a().0)`
p, err := Parse(strings.NewReader(proc))
if err != nil {
t.Fatal(err)
}
if err := Bind(&p); err != nil {
t.Fatalf("cannot bind: %v", err)
}
type setter interface {
SetName(string)
}
if s, ok := p.(*Restrict).Name.(setter); ok {
s.SetName("b")
}
if want, got := "b", p.(*Restrict).Proc.(*Par).Procs[1].(*Recv).Chan.Ident(); want != got {
t.Fatalf("expects %s but got %s for %s", want, got, p.(*Restrict).Proc.(*Par).Procs[1].(*Recv).Calculi())
}
if want, got := "a", p.(*Restrict).Proc.(*Par).Procs[1].(*Recv).Cont.(*Restrict).Name.Ident(); want != got {
t.Fatalf("expects %s but got %s for %s", want, got, p.(*Restrict).Proc.(*Par).Procs[1].(*Recv).Cont.(*Restrict).Calculi())
}
}