当前位置: 首页>>代码示例>>Golang>>正文


Golang convey.So函数代码示例

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


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

示例1: Test011TranslationOfArraysWorks

func Test011TranslationOfArraysWorks(t *testing.T) {

	cv.Convey(`Given a parent Snoopy struct that has an array of`+
		` concrete types, these should be translated from Sexp`+
		` correctly.`, t, func() {

		env := NewGlisp()
		defer env.parser.Stop()

		env.StandardSetup()

		x, err := env.EvalString(`
(def snoop (snoopy pack:[8 9 4]))
`)
		panicOn(err)

		cv.So(x.SexpString(), cv.ShouldEqual, ` (snoopy pack:[8 9 4])`)

		var sn Snoopy
		_, err = SexpToGoStructs(x, &sn, env)
		panicOn(err)
		VPrintf("\n sn = %#v\n", sn)
		cv.So(&sn, cv.ShouldResemble, &Snoopy{Pack: []int{8, 9, 4}})
	})
}
开发者ID:aoeu,项目名称:zygomys,代码行数:25,代码来源:callgo_test.go

示例2: Test004SingleSlice

func Test004SingleSlice(t *testing.T) {

	cv.Convey("Given a parsable golang source file with type Vector struct { M []int }", t, func() {
		cv.Convey("then we should generate translation utility methods for List(Int64) <-> []int in the capnp output", func() {

			ex0 := `
type Vector struct {
  M []int
}`
			cv.So(ExtractString2String(ex0), ShouldContainModuloWhiteSpace, `

func Int64ListToSliceInt(p capn.Int64List) []int {
	v := make([]int, p.Len())
	for i := range v {
		v[i] = int(p.At(i))
	}
	return v
}
`)

			cv.So(ExtractString2String(ex0), ShouldContainModuloWhiteSpace, `
func SliceIntToInt64List(seg *capn.Segment, m []int) capn.Int64List {
	lst := seg.NewInt64List(len(m))
	for i := range m {
		lst.Set(i, int64(m[i]))
	}
	return lst
}

`)
		})
	})
}
开发者ID:robmurtha,项目名称:bambam,代码行数:33,代码来源:singleslice_test.go

示例3: confirmOneJobRunningOneWaiting

func confirmOneJobRunningOneWaiting(cfg *Config) {
	snapmap := HelperSnapmap(cfg)
	running, ok := snapmap["runQlen"]
	if !ok {
		panic(fmt.Sprintf("server stat must include runQlen"))
	}
	irunning, err := strconv.Atoi(running)
	if err != nil {
		panic(err)
	}
	fmt.Printf("\n    We should see one running job now, and we see: %d. snapmap: %#v\n", irunning, snapmap)
	cv.So(irunning, cv.ShouldEqual, 1)

	waiting, ok := snapmap["waitingJobs"]
	if !ok {
		panic(fmt.Sprintf("server stat must include waitingJobs"))
	}
	iwaiting, err := strconv.Atoi(waiting)
	if err != nil {
		panic(err)
	}
	fmt.Printf("\n    We should see one waiting job now, and we see: %d. snapmap: %#v\n", iwaiting, snapmap)
	cv.So(iwaiting, cv.ShouldEqual, 1)

}
开发者ID:robmurtha,项目名称:goq,代码行数:25,代码来源:save_test.go

示例4: TestEnvCannotContainKey

func TestEnvCannotContainKey(t *testing.T) {
	cv.Convey("To avoid transmitting the clusterid, the Env sent to the shepard/worker cannot contain COG_ variables or the clusterid", t, func() {
		cv.Convey("The 8 GOQ env var should all be subtracted by GetNonGOQEnv(), as well as any variable that has the specified cid in it", func() {

			// *** universal test cfg setup
			skipbye := false
			cfg := NewTestConfig()
			defer cfg.ByeTestConfig(&skipbye)
			// *** end universal test setup

			e := make(map[string]string)
			cfg.InjectConfigIntoMap(&e)

			e["UNTOUCHED"] = "sane"
			randomCid := RandomClusterId()
			e["SHALLNOTPASS"] = randomCid

			env2 := MapToEnv(e)

			cv.So(len(env2), cv.ShouldEqual, 11) // the 8 from cfg + UNTOUCHED and SHALLNOTPASS
			res := GetNonGOQEnv(env2, randomCid)

			cv.So(len(res), cv.ShouldEqual, 1)
			cv.So(res[0], cv.ShouldEqual, "UNTOUCHED=sane")
		})
	})
}
开发者ID:robmurtha,项目名称:goq,代码行数:27,代码来源:cfgenv_test.go

示例5: Test003WriteReadThroughGeneratedTranslationCode

func Test003WriteReadThroughGeneratedTranslationCode(t *testing.T) {

	tdir := NewTempDir()
	// comment the defer out to debug any rw test failures.
	defer tdir.Cleanup()

	err := exec.Command("cp", "rw.go.txt", tdir.DirPath+"/rw.go").Run()
	if err != nil {
		fmt.Printf("cp rw.go.txt %s/rw.go failed: '%s'\n", tdir.DirPath, err)
		panic(err)
	}

	MainArgs([]string{os.Args[0], "-o", tdir.DirPath, "rw.go.txt"})

	cv.Convey("Given bambam generated go bindings, \n"+
		"        then we should be able to write to disk, and read back the same structure", t, func() {

		cv.So(err, cv.ShouldEqual, nil)

		tdir.MoveTo()

		err = exec.Command("capnpc", "-ogo", "schema.capnp").Run()
		cv.So(err, cv.ShouldEqual, nil)

		err = exec.Command("go", "build").Run()
		cv.So(err, cv.ShouldEqual, nil)

		// run it
		err = exec.Command("./" + tdir.DirPath).Run()
		cv.So(err, cv.ShouldEqual, nil)

	})
}
开发者ID:robmurtha,项目名称:bambam,代码行数:33,代码来源:rw_test.go

示例6: Test017WriteRead_StructPointerWithinStruct

func Test017WriteRead_StructPointerWithinStruct(t *testing.T) {

	tdir := NewTempDir()
	// comment the defer out to debug any rw test failures.
	defer tdir.Cleanup()

	err := exec.Command("cp", "rw3.go.txt", tdir.DirPath+"/rw3.go").Run()
	if err != nil {
		panic(err)
	}

	MainArgs([]string{os.Args[0], "-o", tdir.DirPath, "rw3.go.txt"})

	cv.Convey("Given bambam generated go bindings: with a struct pointer within a struct", t, func() {
		cv.Convey("then we should be able to write to disk, and read back the same structure", func() {
			cv.So(err, cv.ShouldEqual, nil)

			tdir.MoveTo()

			err = exec.Command("capnpc", "-ogo", "schema.capnp").Run()
			cv.So(err, cv.ShouldEqual, nil)

			err = exec.Command("go", "build").Run()
			cv.So(err, cv.ShouldEqual, nil)

			// run it
			err = exec.Command("./" + tdir.DirPath).Run()
			cv.So(err, cv.ShouldEqual, nil)

		})
	})
}
开发者ID:robmurtha,项目名称:bambam,代码行数:32,代码来源:rw3_test.go

示例7: TestCreationOfZData

func TestCreationOfZData(t *testing.T) {
	const n = 20
	seg, _ := zdataFilledSegment(n)
	text := CapnpDecodeSegment(seg, "", "aircraftlib/aircraft.capnp", "Z")

	expectedText := `(zdata = (data = "\x00\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0e\x0f\x10\x11\x12\x13"))`

	cv.Convey("Given a go-capnproto created Zdata DATA element with n=20", t, func() {
		cv.Convey("When we decode it with capnp", func() {
			cv.Convey(fmt.Sprintf("Then we should get the expected text '%s'", expectedText), func() {
				cv.So(text, cv.ShouldEqual, expectedText)
			})
			cv.Convey("And our data should contain Z_ZDATA with contents 0,1,2,...,n", func() {
				z := air.ReadRootZ(seg)
				cv.So(z.Which(), cv.ShouldEqual, air.Z_ZDATA)

				var data []byte = z.Zdata().Data()
				cv.So(len(data), cv.ShouldEqual, n)
				for i := range data {
					cv.So(data[i], cv.ShouldEqual, i)
				}

			})
		})
	})

}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:27,代码来源:create_test.go

示例8: TestWebGoesUpAndDown

func TestWebGoesUpAndDown(t *testing.T) {

	// *** universal test cfg setup
	skipbye := false
	cfg := NewTestConfig() // bumps cfg.TestportBump so cfg.GetWebPort() is different in test.
	defer cfg.ByeTestConfig(&skipbye)
	// *** end universal test setup

	s := NewWebServer()
	cv.Convey("NewWebServer() should bring up a debug web-server", t, func() {
		cv.So(PortIsBound(s.Addr), cv.ShouldEqual, true)
		by, err := FetchUrl("http://" + s.Addr + "/debug/pprof")
		cv.So(err, cv.ShouldEqual, nil)
		//fmt.Printf("by:'%s'\n", string(by))
		cv.So(strings.HasPrefix(string(by), `<html>
<head>
<title>/debug/pprof/</title>
</head>
/debug/pprof/<br>
<br>`), cv.ShouldEqual, true)

	})

	cv.Convey("WebServer::Stop() should bring down the debug web-server", t, func() {
		s.Stop()
		cv.So(PortIsBound(s.Addr), cv.ShouldEqual, false)
	})
}
开发者ID:robmurtha,项目名称:goq,代码行数:28,代码来源:web_test.go

示例9: Test002ListListStructList

func Test002ListListStructList(t *testing.T) {

	cv.Convey("Given type RWTest struct { NestMatrix [][]Nester1; } in go, where Nester1 is a struct, and a mirror/parallel capnp struct air.RWTestCapn { nestMatrix @0: List(List(Nester1Capn)); } defined in the aircraftlib schema", t, func() {
		cv.Convey("When we Save() RWTest to capn and then Load() it back, the data should match, so that we have working List(List(Struct)) serialization and deserializatoin in go-capnproto", func() {

			// full RWTest
			rw := RWTest{
				NestMatrix: [][]Nester1{[]Nester1{Nester1{Strs: []string{"z", "w"}}, Nester1{Strs: []string{"q", "r"}}}, []Nester1{Nester1{Strs: []string{"zebra", "wally"}}, Nester1{Strs: []string{"qubert", "rocks"}}}},
			}

			var o bytes.Buffer
			rw.Save(&o)

			seg, n, err := capn.ReadFromMemoryZeroCopy(o.Bytes())
			cv.So(err, cv.ShouldEqual, nil)
			cv.So(n, cv.ShouldBeGreaterThan, 0)

			text := CapnpDecodeSegment(seg, "", "aircraftlib/aircraft.capnp", "RWTestCapn")

			if false {
				fmt.Printf("text = '%s'\n", text)
			}

			rw2 := &RWTest{}
			rw2.Load(&o)

			//fmt.Printf("rw = '%#v'\n", rw)
			//fmt.Printf("rw2 = '%#v'\n", rw2)

			same := reflect.DeepEqual(&rw, rw2)
			cv.So(same, cv.ShouldEqual, true)
		})
	})
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:34,代码来源:nested_test.go

示例10: TestPrint

func TestPrint(t *testing.T) {

	seg := capn.NewBuffer(nil)
	z := air.NewRootZ(seg)
	airc := air.AutoNewAircraft(seg)
	b737 := air.AutoNewB737(seg)
	base := air.AutoNewPlaneBase(seg)
	base.SetName("helen")
	base.SetMaxSpeed(0.5)
	homes := air.NewAirportList(seg, 2)
	homes.Set(0, air.AIRPORT_JFK)
	homes.Set(1, air.AIRPORT_SFO)
	base.SetHomes(homes)
	b737.SetBase(base)
	airc.SetB737(b737)
	z.SetAircraft(airc)
	lit, err := z.MarshalCapLit()
	panicOn(err)
	json, err := z.MarshalJSON()
	panicOn(err)

	cv.Convey("Given the aircraftlib schema (and an Aircraft value), we should generate a MarshalCapLit() function that returns a literal representation in bytes for the given Aircraft value. And the MarshalJSON() should return the expected format too.", t, func() {
		cv.So(string(lit), cv.ShouldEqual, `(aircraft = (b737 = (base = (name = "helen", homes = [jfk, sfo], rating = 0, canFly = false, capacity = 0, maxSpeed = 0.5))))`)
		cv.So(string(json), cv.ShouldEqual, `{"aircraft":{"b737":{"base":{"name":"helen","homes":["jfk", "sfo"],"rating":0,"canFly":false,"capacity":0,"maxSpeed":0.5}}}}`)
	})

}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:27,代码来源:print_test.go

示例11: Test001StructList

// start with smaller Struct(List)
func Test001StructList(t *testing.T) {

	cv.Convey("Given type Nester1 struct { Strs []string } in go, where Nester1 is a struct, and a mirror/parallel capnp struct air.Nester1Capn { strs @0: List(Text); } defined in the aircraftlib schema", t, func() {
		cv.Convey("When we Save() Nester to capn and then Load() it back, the data should match, so that we have working Struct(List) serialization and deserializatoin in go-capnproto", func() {

			// Does Nester1 alone serialization and deser okay?
			rw := Nester1{Strs: []string{"xenophilia", "watchowski"}}

			var o bytes.Buffer
			rw.Save(&o)

			seg, n, err := capn.ReadFromMemoryZeroCopy(o.Bytes())
			cv.So(err, cv.ShouldEqual, nil)
			cv.So(n, cv.ShouldBeGreaterThan, 0)

			text := CapnpDecodeSegment(seg, "", "aircraftlib/aircraft.capnp", "Nester1Capn")
			if false {
				fmt.Printf("text = '%s'\n", text)
			}
			rw2 := &Nester1{}
			rw2.Load(&o)

			//fmt.Printf("rw = '%#v'\n", rw)
			//fmt.Printf("rw2 = '%#v'\n", rw2)

			same := reflect.DeepEqual(&rw, rw2)
			cv.So(same, cv.ShouldEqual, true)
		})
	})
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:31,代码来源:nested_test.go

示例12: TestDecompressorVerbosely

func TestDecompressorVerbosely(t *testing.T) {
	cv.Convey("Testing the go-capnproto Decompressor.Read() function:", t, func() {
		for _, test := range compressionTests {

			fmt.Printf("\n\nGiven compressed text '%#v'\n", test.compressed)

			//	fmt.Printf("   test.original = %#v\n test.compressed = %#v\n", test.original, test.compressed)
			for readSize := 1; readSize <= 8+2*len(test.original); readSize++ {
				fmt.Printf("\n  When we use go-capnproto NewDecompressor, with readSize: %d\n    Then we should get the original text back.", readSize)

				r := bytes.NewReader(test.compressed)
				d := capn.NewDecompressor(r)
				buf := make([]byte, readSize)
				var actual []byte
				for {
					n, err := d.Read(buf)
					actual = append(actual, buf[:n]...)
					if err != nil {
						if err == io.EOF {
							break
						}
						t.Fatalf("Read: %v", err)
					}
				}

				cv.So(len(actual), cv.ShouldResemble, len(test.original))
				if len(test.original) > 0 {
					cv.So(actual, cv.ShouldResemble, test.original)
				}
			} // end readSize loop
		}
		fmt.Printf("\n\n")
	})
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:34,代码来源:stream_test.go

示例13: TestDecodeOnKnownWellPackedData

func TestDecodeOnKnownWellPackedData(t *testing.T) {

	// length 17
	byteSliceIn := []byte{0x10, 0x5, 0x50, 0x2, 0x1, 0x1, 0x25, 0x0, 0x0, 0x11, 0x1, 0xc, 0xf, 0xd4, 0x7, 0xc, 0x7}
	fmt.Printf("len of byteSliceIn is %d\n", len(byteSliceIn))
	// annotated: byteSliceIn := []byte{tag:0x10, 0x5, tag:0x50, 0x2, 0x1, tag:0x1, 0x25, tag:0x0, 0x0, tag:0x11, 0x1, 0xc, tag:0xf, 0xd4, 0x7, 0xc, 0x7}

	// length 48
	expectedOut := []byte{0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x1, 0x0, 0x25, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0xd4, 0x7, 0xc, 0x7, 0x0, 0x0, 0x0, 0x0}

	r := bytes.NewReader(byteSliceIn)
	actual, err := ioutil.ReadAll(capn.NewDecompressor(r))
	if err != nil {
		panic(err)
	}

	cv.Convey("Given a known-to-be-correctly packed 17-byte long sequence for a ZdateVector holding a single Zdate", t, func() {
		cv.Convey("When we use go-capnproto NewDecompressor", func() {
			cv.Convey("Then we should get the same unpacked bytes as capnp provides", func() {
				cv.So(len(actual), cv.ShouldResemble, len(expectedOut))
				cv.So(actual, cv.ShouldResemble, expectedOut)
			})
		})
	})

}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:26,代码来源:stream_test.go

示例14: Test014TranslationOfArraysOfInterfacesEmbeddedWorks

func Test014TranslationOfArraysOfInterfacesEmbeddedWorks(t *testing.T) {

	cv.Convey(`Given a parent Snoopy struct that has an array of Flyer interfaces that are embedded inside Plane, these should be translated from Sexp correctly.`, t, func() {

		env := NewGlisp()
		env.StandardSetup()

		x, err := env.EvalString(`
(def he (hellcat speed:567))
(def ho (hornet SpanCm:12))
(def snoop (snoopy friends:[he ho]))
`)
		panicOn(err)
		cv.So(x.SexpString(), cv.ShouldEqual, ` (snoopy friends:[ (hellcat speed:567)  (hornet SpanCm:12)])`)

		var sn Snoopy
		_, err = SexpToGoStructs(x, &sn, env)
		panicOn(err)
		fmt.Printf("\n sn = %#v\n", sn)
		cv.So(&sn, cv.ShouldResemble, &Snoopy{
			Plane: Plane{
				Friends: []Flyer{
					&Hellcat{Plane: Plane{Speed: 567}},
					&Hornet{Plane: Plane{
						Wings: Wings{
							SpanCm: 12,
						},
					},
					},
				},
			},
		})

	})
}
开发者ID:glaucosydow,项目名称:zygomys,代码行数:35,代码来源:callgo_test.go

示例15: Test030LexingPauseAndResume

func Test030LexingPauseAndResume(t *testing.T) {

	cv.Convey(`to enable the repl to properly detect the end of a multiline expression (or an expression containing quoted parentheses), the lexer should be able to pause and resume when more input is available.`, t, func() {

		str := `(defn hello [] "greetings!(((")`
		str1 := `(defn hel`
		str2 := `lo [] "greetings!(((")`
		env := NewGlisp()
		defer env.parser.Stop()
		stream := bytes.NewBuffer([]byte(str1))
		env.parser.ResetAddNewInput(stream)
		ex, err := env.parser.ParseTokens()

		P("\n In lexer_test, after parsing with incomplete input, we should get 0 expressions back.\n")
		cv.So(len(ex), cv.ShouldEqual, 0)
		P("\n In lexer_test, after ParseTokens on incomplete fragment, expressions = '%v' and err = '%v'\n", (&SexpArray{Val: ex, Env: env}).SexpString(nil), err)

		P("\n In lexer_test: calling parser.NewInput() to provide str2='%s'\n", str2)
		env.parser.NewInput(bytes.NewBuffer([]byte(str2)))
		P("\n In lexer_test: done with parser.NewInput(), now calling parser.ParseTokens()\n")
		ex, err = env.parser.ParseTokens()
		P(`
 in lexer test: After providing the 2nd half of the input, we returned from env.parser.ParseTokens()
 with expressions = %v
 with err = %v
`, (&SexpArray{Val: ex, Env: env}).SexpString(nil), err)

		cv.So(len(ex), cv.ShouldEqual, 1)
		panicOn(err)

		P("str=%s\n", str)
	})
}
开发者ID:glycerine,项目名称:zygomys,代码行数:33,代码来源:lexer_test.go


注:本文中的github.com/glycerine/goconvey/convey.So函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。