You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
944 B
47 lines
944 B
7 years ago
|
package acedoc
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func TestClient(t *testing.T) {
|
||
|
doc := NewString("")
|
||
|
|
||
|
aliceCh := make(chan []Delta, 5)
|
||
|
alice := doc.Client(DeltaHandlerFunc(func(ds []Delta) error {
|
||
|
aliceCh <- ds
|
||
|
return nil
|
||
|
}))
|
||
|
defer alice.Close()
|
||
|
|
||
|
bobCh := make(chan []Delta, 5)
|
||
|
bob := doc.Client(DeltaHandlerFunc(func(ds []Delta) error {
|
||
|
bobCh <- ds
|
||
|
return nil
|
||
|
}))
|
||
|
defer bob.Close()
|
||
|
|
||
|
delta := Insert(0, 0, "alphabet")
|
||
|
|
||
|
err := alice.PushDeltas(delta)
|
||
|
if err != nil {
|
||
|
t.Error("got error pushing delta:", err)
|
||
|
}
|
||
|
|
||
|
select {
|
||
|
case got := <-bobCh:
|
||
|
if len(got) != 1 {
|
||
|
t.Errorf("got %d deltas, expected %d", len(got), 1)
|
||
|
} else if !got[0].Equal(delta) {
|
||
|
t.Error("didn't get the correct delta, saw:", got[0], "expected:", delta)
|
||
|
}
|
||
|
case <-time.After(10 * time.Millisecond):
|
||
|
t.Error("didn't get any delta")
|
||
|
}
|
||
|
|
||
|
if got := doc.Contents(); got != "alphabet" {
|
||
|
t.Errorf("saw doc %q, expected %q", got, "alphabet")
|
||
|
}
|
||
|
}
|