• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang store.NewDocument函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/jeffail/leaps/lib/store.NewDocument函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDocument函数的具体用法?Golang NewDocument怎么用?Golang NewDocument使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewDocument函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestPushPullTransforms

func TestPushPullTransforms(t *testing.T) {
	numTransforms := 100
	arrTransforms := make([]OTransform, numTransforms)
	doc, err := store.NewDocument("hello world")
	if err != nil {
		t.Errorf("Error: %v", err)
		return
	}
	model := CreateTextModel(DefaultModelConfig())

	for j := 0; j < 2; j++ {
		for i := 0; i < numTransforms; i++ {
			arrTransforms[i] = OTransform{
				Version:  model.GetVersion() + 1,
				Position: 0,
				Insert:   fmt.Sprintf("Transform%v", i+(j*numTransforms)),
				Delete:   0,
			}

			if _, _, err := model.PushTransform(arrTransforms[i]); err != nil {
				t.Errorf("Error: %v", err)
			}

			if i%50 == 0 {
				model.FlushTransforms(&doc.Content, 60)
			}
		}

		model.FlushTransforms(&doc.Content, 60)
	}
}
开发者ID:jonasfj,项目名称:leaps,代码行数:31,代码来源:model_text_test.go


示例2: TestGracefullShutdown

func TestGracefullShutdown(t *testing.T) {
	errChan := make(chan Error, 10)

	logger, stats := loggerAndStats()
	doc, _ := store.NewDocument("hello world")

	store := testStore{documents: map[string]store.Document{
		"KILL_ME": *doc,
	}}

	binder, err := New("KILL_ME", &store, NewConfig(), errChan, logger, stats)
	if err != nil {
		t.Errorf("Error: %v", err)
		return
	}

	testClient, err := binder.Subscribe("", time.Second)
	if err != nil {
		t.Error(err)
		return
	}
	delete(store.documents, "KILL_ME")
	testClient.SendTransform(text.OTransform{Position: 0, Insert: "hello", Version: 2}, time.Second)

	<-errChan
	binder.Close()
}
开发者ID:Jeffail,项目名称:leaps,代码行数:27,代码来源:binder_test.go


示例3: TestTransformStories

func TestTransformStories(t *testing.T) {
	bytes, err := ioutil.ReadFile("../test/stories/transform_stories.js")
	if err != nil {
		t.Errorf("Read file error: %v", err)
		return
	}

	var scont storiesContainer
	if err := json.Unmarshal(bytes, &scont); err != nil {
		t.Errorf("Story parse error: %v", err)
		return
	}

	for _, story := range scont.Stories {
		stages := []byte("Stages of story:\n")

		doc, err := store.NewDocument(story.Content)
		if err != nil {
			t.Errorf("Error: %v", err)
			return
		}
		model := CreateTextModel(DefaultModelConfig())

		stages = append(stages,
			[]byte(fmt.Sprintf("\tInitial : %v\n", doc.Content))...)

		for j, change := range story.Transforms {
			if ts, _, err := model.PushTransform(change); err != nil {
				t.Errorf("Failed to insert: %v", err)
			} else {
				if len(story.TCorrected) > j {
					if story.TCorrected[j].Position != ts.Position ||
						story.TCorrected[j].Version != ts.Version ||
						story.TCorrected[j].Delete != ts.Delete ||
						story.TCorrected[j].Insert != ts.Insert {
						t.Errorf("Tform does not match corrected form: %v != %v",
							story.TCorrected[j], ts)
					}
				}
			}
			for _, at := range story.Flushes {
				if at == j {
					if _, err = model.FlushTransforms(&doc.Content, 60); err != nil {
						t.Errorf("Failed to flush: %v", err)
					}
					stages = append(stages,
						[]byte(fmt.Sprintf("\tStage %-2v: %v\n", j, doc.Content))...)
				}
			}
		}
		if _, err = model.FlushTransforms(&doc.Content, 60); err != nil {
			t.Errorf("Failed to flush: %v", err)
		}
		result := doc.Content
		if result != story.Result {
			t.Errorf("Failed transform story: %v\nexpected:\n\t%v\nresult:\n\t%v\n%v",
				story.Name, story.Result, result, string(stages))
		}
	}
}
开发者ID:jonasfj,项目名称:leaps,代码行数:60,代码来源:model_text_test.go


示例4: TestNew

func TestNew(t *testing.T) {
	errChan := make(chan Error)
	doc, _ := store.NewDocument("hello world")
	logger, stats := loggerAndStats()

	binder, err := New(
		doc.ID,
		&testStore{documents: map[string]store.Document{doc.ID: *doc}},
		NewConfig(),
		errChan,
		logger,
		stats,
	)
	if err != nil {
		t.Errorf("error: %v", err)
		return
	}

	go func() {
		for err := range errChan {
			t.Errorf("From error channel: %v", err.Err)
		}
	}()

	portal1, _ := binder.Subscribe("", time.Second)
	portal2, _ := binder.Subscribe("", time.Second)
	if v, err := portal1.SendTransform(
		text.OTransform{
			Position: 6,
			Version:  2,
			Delete:   5,
			Insert:   "universe",
		},
		time.Second,
	); v != 2 || err != nil {
		t.Errorf("Send Transform error, v: %v, err: %v", v, err)
	}
	if v, err := portal2.SendTransform(
		text.OTransform{
			Position: 0,
			Version:  3,
			Delete:   0,
			Insert:   "super ",
		},
		time.Second,
	); v != 3 || err != nil {
		t.Errorf("Send Transform error, v: %v, err: %v", v, err)
	}

	<-portal1.TransformReadChan()
	<-portal2.TransformReadChan()

	portal3, _ := binder.Subscribe("", time.Second)
	if exp, rec := "super hello universe", portal3.Document().Content; exp != rec {
		t.Errorf("Wrong content, expected %v, received %v", exp, rec)
	}
}
开发者ID:Jeffail,项目名称:leaps,代码行数:57,代码来源:binder_test.go


示例5: TestTextOTBufferUnicodeTransforms

func TestTextOTBufferUnicodeTransforms(t *testing.T) {
	doc, err := store.NewDocument("hello world 我今天要学习")
	if err != nil {
		t.Errorf("Error: %v", err)
		return
	}

	model := NewOTBuffer(NewOTBufferConfig())
	if _, _, err = model.PushTransform(OTransform{
		Version:  model.GetVersion() + 1,
		Position: 12,
		Insert:   "你听说那条新闻了吗? ",
		Delete:   0,
	}); err != nil {
		t.Errorf("Error: %v", err)
	}
	if _, _, err = model.PushTransform(OTransform{
		Version:  model.GetVersion() + 1,
		Position: 12,
		Insert:   " 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang log.Logger类代码示例发布时间:2022-05-23
下一篇:
Golang gabs.Container类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap