コード例 #1
0
ファイル: compiler_test.go プロジェクト: nlfiedler/bakeneko
func (cs *CompilerSuite) TestApplication(c *gc.C) {
	expr := parseAndExpandForTest(`(+ 1 2 3)`, c)
	name := "TestApplication"
	code, err := Compile(name, expr)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to compile code: %s", err))
	c.Assert(code, gc.NotNil, gc.Commentf("failed to produce code"))
	c.Check(code.Name(), gc.Equals, name)
	c.Assert(code.CodeLen(), gc.Equals, uint(5))
	c.Assert(code.SymbolLen(), gc.Equals, uint(1))
	c.Assert(code.ConstantLen(), gc.Equals, uint(3))
	c.Check(code.GetInstruction(0).Code(), gc.Equals, OP_CONST)
	c.Check(code.GetInstruction(0).Argument(), gc.Equals, uint(0))
	c.Check(code.GetInstruction(1).Code(), gc.Equals, OP_CONST)
	c.Check(code.GetInstruction(1).Argument(), gc.Equals, uint(1))
	c.Check(code.GetInstruction(2).Code(), gc.Equals, OP_CONST)
	c.Check(code.GetInstruction(2).Argument(), gc.Equals, uint(2))
	c.Check(code.GetInstruction(3).Code(), gc.Equals, OP_LOADVAR)
	c.Check(code.GetInstruction(3).Argument(), gc.Equals, uint(0))
	c.Check(code.GetInstruction(4).Code(), gc.Equals, OP_CALL)
	c.Check(code.GetInstruction(4).Argument(), gc.Equals, uint(3))
	num := code.GetConstant(0).(Integer)
	c.Check(num.ToInteger(), gc.Equals, int64(1))
	num = code.GetConstant(1).(Integer)
	c.Check(num.ToInteger(), gc.Equals, int64(2))
	num = code.GetConstant(2).(Integer)
	c.Check(num.ToInteger(), gc.Equals, int64(3))
	c.Check(code.GetSymbol(0).String(), gc.Equals, "+")
}
コード例 #2
0
ファイル: pair_test.go プロジェクト: nlfiedler/bakeneko
func (ps *PairSuite) TestCar(c *gc.C) {
	c.Check(Car(nil), gc.IsNil, gc.Commentf("Car(nil) should be nil"))
	c.Check(Car("foo"), gc.IsNil, gc.Commentf(`Car("foo") should be nil`))
	foo := NewSymbol("foo")
	p := NewPair(foo)
	c.Check(Car(p), gc.Equals, foo, gc.Commentf(`Car() should return first of list`))
}
コード例 #3
0
ファイル: compiler_test.go プロジェクト: nlfiedler/bakeneko
func (cs *CompilerSuite) TestIfElse(c *gc.C) {
	expr := parseAndExpandForTest(`(if #t 1 2)`, c)
	name := "TestIfElse"
	code, err := Compile(name, expr)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to compile code: %s", err))
	c.Assert(code, gc.NotNil, gc.Commentf("failed to produce code"))
	c.Assert(code.CodeLen(), gc.Equals, uint(5))
	c.Check(code.GetInstruction(0).Code(), gc.Equals, OP_CONST)
	c.Check(code.GetInstruction(0).Argument(), gc.Equals, uint(0))
	c.Check(code.GetInstruction(1).Code(), gc.Equals, OP_FJUMP)
	c.Check(code.GetInstruction(1).Argument(), gc.Equals, uint(4))
	c.Check(code.GetInstruction(2).Code(), gc.Equals, OP_CONST)
	c.Check(code.GetInstruction(2).Argument(), gc.Equals, uint(1))
	c.Check(code.GetInstruction(3).Code(), gc.Equals, OP_JUMP)
	c.Check(code.GetInstruction(3).Argument(), gc.Equals, uint(5))
	c.Check(code.GetInstruction(4).Code(), gc.Equals, OP_CONST)
	c.Check(code.GetInstruction(4).Argument(), gc.Equals, uint(2))
	c.Check(code.Name(), gc.Equals, name)
	c.Assert(code.SymbolLen(), gc.Equals, uint(0))
	c.Assert(code.ConstantLen(), gc.Equals, uint(3))
	boo := code.GetConstant(0).(Boolean)
	c.Check(boo.Value(), gc.Equals, true)
	num := code.GetConstant(1).(Integer)
	c.Check(num.ToInteger(), gc.Equals, int64(1))
	num = code.GetConstant(2).(Integer)
	c.Check(num.ToInteger(), gc.Equals, int64(2))
}
コード例 #4
0
ファイル: document_test.go プロジェクト: durgeshm/goprismic
func (s *TestSuite) TestParagraphUtf8Span(c *gocheck.C) {
	text, _ := s.doc.GetStructuredTextFragment("utf8span")
	p, _ := text.GetFirstParagraph()
	c.Assert(p, gocheck.NotNil, gocheck.Commentf("Has a first paragraph"))
	content := "<p>Thìs ìs &lt;à&gt; <em>tést</em>.</p>"
	c.Assert(p.AsHtml(), gocheck.Equals, content, gocheck.Commentf("Has the right rendering"))
}
コード例 #5
0
ファイル: api_test.go プロジェクト: durgeshm/goprismic
func (s *ApiTestSuite) TestQuery(c *gocheck.C) {
	c.Assert(s.api, gocheck.NotNil, gocheck.Commentf("Connection with api is OK"))
	sr, err := s.api.Master().Form("everything").Query("[[:d = at(document.tags, [\"Macaron\"])]]").Submit()
	c.Assert(err, gocheck.IsNil, gocheck.Commentf("Submit did not return an error - %s", err))
	c.Assert(len(sr.Results), gocheck.Equals, 7, gocheck.Commentf("Submit did return 7 documents"))

}
コード例 #6
0
ファイル: document_test.go プロジェクト: durgeshm/goprismic
func (s *TestSuite) TestPreformattedEscape(c *gocheck.C) {
	text, _ := s.doc.GetStructuredTextFragment("escape")
	p, _ := text.GetFirstPreformatted()
	c.Assert(p, gocheck.NotNil, gocheck.Commentf("Has a first preformatted"))
	content := "<pre>This is &lt;a&gt; test.</pre>"
	c.Assert(p.AsHtml(), gocheck.Equals, content, gocheck.Commentf("Has the right rendering"))
}
コード例 #7
0
ファイル: document_test.go プロジェクト: durgeshm/goprismic
func (s *TestSuite) TestParagraphEscapeAndSpan(c *gocheck.C) {
	text, _ := s.doc.GetStructuredTextFragment("escapespan")
	p, _ := text.GetFirstParagraph()
	c.Assert(p, gocheck.NotNil, gocheck.Commentf("Has a first paragraph"))
	content := "<p>Thi&amp; i&amp; &lt;a&gt; <em>test</em>.</p>"
	c.Assert(p.AsHtml(), gocheck.Equals, content, gocheck.Commentf("Has the right rendering"))
}
コード例 #8
0
ファイル: proxy_test.go プロジェクト: durgeshm/goprismic
func (s *ProxyTestSuite) TestGetBy(c *gocheck.C) {
	c.Assert(s.proxy, gocheck.NotNil, gocheck.Commentf("Connection with api is OK"))
	d, err := s.proxy.GetDocumentBy("product", "flavour", "Pistachio")
	c.Assert(d, gocheck.Not(gocheck.IsNil), gocheck.Commentf("Submit did not return an error - %s", err))
	f, _ := d.GetTextFragment("flavour")
	c.Assert(f.AsText(), gocheck.Equals, "Pistachio", gocheck.Commentf("Proxy returns the same doc"))
}
コード例 #9
0
ファイル: document_test.go プロジェクト: durgeshm/goprismic
func (s *TestSuite) TestPreformattedRendering(c *gocheck.C) {
	text, _ := s.doc.GetStructuredTextFragment("render")
	p, _ := text.GetFirstPreformatted()
	c.Assert(p, gocheck.NotNil, gocheck.Commentf("Has a first preformatted"))
	content := "<pre>This <em>is</em> <strong>a</strong> test.</pre>"
	c.Assert(p.AsHtml(), gocheck.Equals, content, gocheck.Commentf("Has the right rendering"))
}
コード例 #10
0
ファイル: proxy_test.go プロジェクト: durgeshm/goprismic
func (s *ProxyTestSuite) TestLRU(c *gocheck.C) {
	c.Assert(s.proxy, gocheck.NotNil, gocheck.Commentf("Connection with api is OK"))
	sr, err := s.proxy.Search().Form("products").Submit()
	log.Printf("%#v", sr)
	c.Assert(sr, gocheck.Not(gocheck.IsNil), gocheck.Commentf("Submit did not return an error - %s", err))
	s.proxy.Clear()
	stats := s.proxy.GetStats()
	// accessing ds[0]
	s.proxy.GetDocument(sr.Results[0].Id)
	stats1 := s.proxy.GetStats()
	c.Assert(stats1.Hit, gocheck.Equals, stats.Hit, gocheck.Commentf("on an empty cache, no hit"))
	c.Assert(stats1.Miss, gocheck.Equals, stats.Miss+1, gocheck.Commentf("on an empty cache, miss"))
	// accessing ds[0] again
	s.proxy.GetDocument(sr.Results[0].Id)
	stats1 = s.proxy.GetStats()
	c.Assert(stats1.Hit, gocheck.Equals, stats.Hit+1, gocheck.Commentf("doc in cache, hit"))
	c.Assert(stats1.Miss, gocheck.Equals, stats.Miss+1, gocheck.Commentf("doc in cache, no miss"))
	// accessing another doc. LRU size is 1 => ds[0] should be evicted
	s.proxy.GetDocument(sr.Results[1].Id)
	stats1 = s.proxy.GetStats()
	c.Assert(stats1.Hit, gocheck.Equals, stats.Hit+1, gocheck.Commentf("doc not in cache, no hit"))
	c.Assert(stats1.Miss, gocheck.Equals, stats.Miss+2, gocheck.Commentf("doc not in cache, miss"))
	// accessing ds[0] again, should not be found in cache
	s.proxy.GetDocument(sr.Results[0].Id)
	stats1 = s.proxy.GetStats()
	c.Assert(stats1.Hit, gocheck.Equals, stats.Hit+1, gocheck.Commentf("doc evicted from cache, no hit"))
	c.Assert(stats1.Miss, gocheck.Equals, stats.Miss+3, gocheck.Commentf("doc evicted from cache, miss"))
}
コード例 #11
0
ファイル: dense_test.go プロジェクト: rosrad/matrix
func (s *S) TestAtSet(c *check.C) {
	for test, af := range [][][]float64{
		{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, // even
		{{1, 2}, {4, 5}, {7, 8}},          // wide
		{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, //skinny
	} {
		m := NewDense(flatten(af))
		rows, cols := m.Dims()
		for i := 0; i < rows; i++ {
			for j := 0; j < cols; j++ {
				c.Check(m.At(i, j), check.Equals, af[i][j], check.Commentf("At test %d", test))

				v := float64(i * j)
				m.Set(i, j, v)
				c.Check(m.At(i, j), check.Equals, v, check.Commentf("Set test %d", test))
			}
		}
		// Check access out of bounds fails
		c.Check(func() { m.At(rows, 0) }, check.PanicMatches, "index error: row access out of bounds", check.Commentf("Test %d", test))
		c.Check(func() { m.At(rows+1, 0) }, check.PanicMatches, "index error: row access out of bounds", check.Commentf("Test %d", test))
		c.Check(func() { m.At(0, cols) }, check.PanicMatches, "index error: column access out of bounds", check.Commentf("Test %d", test))
		c.Check(func() { m.At(0, cols+1) }, check.PanicMatches, "index error: column access out of bounds", check.Commentf("Test %d", test))
		c.Check(func() { m.At(-1, 0) }, check.PanicMatches, "index error: row access out of bounds", check.Commentf("Test %d", test))
		c.Check(func() { m.At(0, -1) }, check.PanicMatches, "index error: column access out of bounds", check.Commentf("Test %d", test))

		// Check access out of bounds fails
		c.Check(func() { m.Set(rows, 0, 1.2) }, check.PanicMatches, "index error: row access out of bounds", check.Commentf("Test %d", test))
		c.Check(func() { m.Set(rows+1, 0, 1.2) }, check.PanicMatches, "index error: row access out of bounds", check.Commentf("Test %d", test))
		c.Check(func() { m.Set(0, cols, 1.2) }, check.PanicMatches, "index error: column access out of bounds", check.Commentf("Test %d", test))
		c.Check(func() { m.Set(0, cols+1, 1.2) }, check.PanicMatches, "index error: column access out of bounds", check.Commentf("Test %d", test))
		c.Check(func() { m.Set(-1, 0, 1.2) }, check.PanicMatches, "index error: row access out of bounds", check.Commentf("Test %d", test))
		c.Check(func() { m.Set(0, -1, 1.2) }, check.PanicMatches, "index error: column access out of bounds", check.Commentf("Test %d", test))
	}
}
コード例 #12
0
// checkInterpret takes a map of inputs to expected outputs, running the
// inputs through the interpreter and checking the output.
func checkInterpret(c *gc.C, inputs map[string]string) {
	for input, expected := range inputs {
		result, err := Interpret(input)
		c.Assert(err, gc.IsNil, gc.Commentf("Interpret() failed for %q: %v", input, err))
		c.Check(stringify(result), gc.Equals, expected, gc.Commentf(input))
	}
}
コード例 #13
0
ファイル: document_test.go プロジェクト: durgeshm/goprismic
func (s *TestSuite) TestGetFirstPreformatted(c *gocheck.C) {
	text, _ := s.doc.GetStructuredTextFragment("description")
	p, _ := text.GetFirstPreformatted()
	c.Assert(p, gocheck.NotNil, gocheck.Commentf("Has a first preformatted"))
	content := "If you ever met coconut taste on its bad day, you surely know that coconut, coming from bad-tempered islands, can be rough sometimes. That is why we like to soften it with a touch of caramel taste in its ganache. The result is the perfect encounter between the finest palm fruit and the most tasty of sugarcane's offspring."
	c.Assert(p.Text, gocheck.Equals, content, gocheck.Commentf("Has the right content"))
}
コード例 #14
0
// checkInterpretError takes a map of inputs to expected error messages,
// running the inputs through the interpreter and ensuring that each one fails
// with the associated error message.
func checkInterpretError(c *gc.C, inputs map[string]string) {
	for input, expected := range inputs {
		result, err := Interpret(input)
		c.Assert(err, gc.NotNil, gc.Commentf("expected %q to fail, got %v", input, result))
		c.Check(err, gc.ErrorMatches, expected, gc.Commentf(input))
	}
}
コード例 #15
0
ファイル: document_test.go プロジェクト: durgeshm/goprismic
func (s *TestSuite) TestGetBoolean(c *gocheck.C) {
	a, _ := s.doc.GetBool("adult")
	c.Assert(a, gocheck.Equals, true, gocheck.Commentf("Found the right bool"))
	a, _ = s.doc.GetBool("teenager")
	c.Assert(a, gocheck.Equals, true, gocheck.Commentf("Found the right bool"))
	a, _ = s.doc.GetBool("french")
	c.Assert(a, gocheck.Equals, false, gocheck.Commentf("Found the right bool"))
}
コード例 #16
0
ファイル: document_test.go プロジェクト: durgeshm/goprismic
func (s *TestSuite) TestGeoPoint(c *gocheck.C) {
	geo, _ := s.doc.GetGeoPointFragment("location")

	c.Assert(geo.Latitude, gocheck.Equals, 48.87687670000001, gocheck.Commentf("Geopoint has the correct latitude"))
	c.Assert(geo.Longitude, gocheck.Equals, 2.3338801999999825, gocheck.Commentf("Geopoint has the correct longitude"))

	content := fmt.Sprintf(`<div class="geopoint"><span class="latitude">%f</span><span class="longitude">%f</span></div>`, geo.Latitude, geo.Longitude)
	c.Assert(geo.AsHtml(), gocheck.Equals, content, gocheck.Commentf("GeoPoints have the right rendering"))
}
コード例 #17
0
ファイル: compiler_test.go プロジェクト: nlfiedler/bakeneko
// parseAndExpandForTest parses and expands the input text into an
// expression ready for compilation.
func parseAndExpandForTest(input string, c *gc.C) interface{} {
	var err LispError
	parser := NewParser()
	body, err := parser.Parse(input)
	c.Assert(err, gc.IsNil, gc.Commentf("error parsing %q: %s", input, err))
	expr, err := parser.Expand(body)
	c.Assert(err, gc.IsNil, gc.Commentf("error expanding %q: %s", input, err))
	return expr
}
コード例 #18
0
ファイル: proxy_test.go プロジェクト: durgeshm/goprismic
func (s *ProxyTestSuite) TestLoadReload(c *gocheck.C) {
	c.Assert(s.proxy, gocheck.NotNil, gocheck.Commentf("Connection with api is OK"))
	d := s.docs[0]
	d1, err := s.proxy.GetDocument(d.Id)
	c.Assert(err, gocheck.IsNil, gocheck.Commentf("Submit did not return an error - %s", err))
	c.Assert(d, gocheck.DeepEquals, *d1, gocheck.Commentf("Proxy returns the same doc"))
	d1, err = s.proxy.GetDocument(d.Id)
	c.Assert(err, gocheck.IsNil, gocheck.Commentf("Submit did not return an error - %s", err))
	c.Assert(d, gocheck.DeepEquals, *d1, gocheck.Commentf("Proxy returns the same doc again"))
}
コード例 #19
0
ファイル: parser_test.go プロジェクト: nlfiedler/bakeneko
func verifyExpandMap(mapping map[string]string, c *gc.C) {
	for input, expected := range mapping {
		parser := NewParser()
		pair, err := parser.Parse(input)
		c.Assert(err, gc.IsNil, gc.Commentf("failed to parse %q: %s", input, err))
		x, err := parser.Expand(pair.First())
		c.Assert(err, gc.IsNil, gc.Commentf("failed to expand %q: %s", input, err))
		c.Check(stringify(x), gc.Equals, expected)
	}
}
コード例 #20
0
ファイル: dense_test.go プロジェクト: rosrad/matrix
func (s *S) TestMul(c *check.C) {
	for i, test := range []struct {
		a, b, r [][]float64
	}{
		{
			[][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
			[][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
			[][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
		},
		{
			[][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}},
			[][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}},
			[][]float64{{3, 3, 3}, {3, 3, 3}, {3, 3, 3}},
		},
		{
			[][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}},
			[][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}},
			[][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}},
		},
		{
			[][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}},
			[][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}},
			[][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}},
		},
		{
			[][]float64{{1, 2, 3}, {4, 5, 6}},
			[][]float64{{1, 2}, {3, 4}, {5, 6}},
			[][]float64{{22, 28}, {49, 64}},
		},
		{
			[][]float64{{0, 1, 1}, {0, 1, 1}, {0, 1, 1}},
			[][]float64{{0, 1, 1}, {0, 1, 1}, {0, 1, 1}},
			[][]float64{{0, 2, 2}, {0, 2, 2}, {0, 2, 2}},
		},
	} {
		a := NewDense(flatten(test.a))
		b := NewDense(flatten(test.b))
		r := NewDense(flatten(test.r))

		temp := &Dense{}
		temp.Mul(a, b)
		c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v add %v expect %v got %v",
			i, test.a, test.b, test.r, unflatten(temp.mat.Rows, temp.mat.Cols, temp.mat.Data)))

		zero(temp.mat.Data)
		temp.Mul(a, b)
		c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v sub %v expect %v got %v",
			i, test.a, test.b, test.r, unflatten(a.mat.Rows, a.mat.Cols, a.mat.Data)))

		// These probably warrant a better check and failure. They should never happen in the wild though.
		temp.mat.Data = nil
		c.Check(func() { temp.Mul(a, b) }, check.PanicMatches, "cblas: index of c out of range", check.Commentf("Test %d"))
	}
}
コード例 #21
0
ファイル: vm_test.go プロジェクト: nlfiedler/bakeneko
func (vms *VirtMachSuite) TestRecursiveFib(c *gc.C) {
	name := "TestRecursiveFib"
	code, err := CompileString(name, fibonacciRecursiveText)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to compile code: %s", err))
	c.Assert(code, gc.NotNil, gc.Commentf("failed to produce code"))
	env := NewEnvironment(theReportEnvironment)
	result, err := EvaluateCode(code, env)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to evaluate code: %s", err))
	c.Assert(result, gc.NotNil, gc.Commentf("lambda failed to yield result"))
	c.Check(result, gc.Equals, NewInteger(3736710778780434371))
}
コード例 #22
0
ファイル: document_test.go プロジェクト: durgeshm/goprismic
func (s *TestSuite) TestEmbedAndImage(c *gocheck.C) {
	blocks, _ := s.doc.GetStructuredTextBlocks("embedimage")

	i := blocks[0]
	content := "<img src=\"https://wroomdev.s3.amazonaws.com/lesbonneschoses/899162db70c73f11b227932b95ce862c63b9df2A.jpg\" width=\"800\" height=\"400\"/>"
	c.Assert(i.AsHtml(), gocheck.Equals, content, gocheck.Commentf("Image block has the right rendering"))

	e := blocks[1]
	content = "<div data-oembed=\"http://www.youtube.com/watch?v=MmIKLlRE7n0\" data-oembed-type=\"video\" data-oembed-provider=\"YouTube\"><iframe width='459' height='344' src='http://www.youtube.com/embed/MmIKLlRE7n0?feature=oembed' frameborder='0' allowfullscreen></iframe></div>"
	c.Assert(e.AsHtml(), gocheck.Equals, content, gocheck.Commentf("Embed block has the right rendering"))
}
コード例 #23
0
ファイル: proxy_test.go プロジェクト: durgeshm/goprismic
func (s *ProxyTestSuite) TestTtl(c *gocheck.C) {
	c.Assert(s.proxy, gocheck.NotNil, gocheck.Commentf("Connection with api is OK"))
	d := s.docs[0]
	s.proxy.GetDocument(d.Id)
	c.Assert(s.proxy.GetStats(), gocheck.DeepEquals, Stats{Get: 1, Miss: 1}, gocheck.Commentf("miss"))
	s.proxy.GetDocument(d.Id)
	c.Assert(s.proxy.GetStats(), gocheck.DeepEquals, Stats{Get: 2, Hit: 1, Miss: 1}, gocheck.Commentf("miss+hit"))
	s.proxy.cache.updateRevision("foobar")
	time.Sleep(12 * time.Second)
	s.proxy.GetDocument(d.Id)
	c.Assert(s.proxy.GetStats(), gocheck.DeepEquals, Stats{Get: 3, Hit: 1, Miss: 2}, gocheck.Commentf("miss+hit+refresh+miss"))
}
コード例 #24
0
ファイル: vm_test.go プロジェクト: nlfiedler/bakeneko
func (vms *VirtMachSuite) TestRecursiveSqrt(c *gc.C) {
	c.Skip("TODO: builtinDivide() use of BigRat appears going wrong")
	name := "TestRecursiveSqrt"
	code, err := CompileString(name, squareRootSicp)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to compile code: %s", err))
	c.Assert(code, gc.NotNil, gc.Commentf("failed to produce code"))
	env := NewEnvironment(theReportEnvironment)
	result, err := EvaluateCode(code, env)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to evaluate code: %s", err))
	c.Assert(result, gc.NotNil, gc.Commentf("lambda failed to yield result"))
	c.Check(result, gc.Equals, NewInteger(12345))
}
コード例 #25
0
ファイル: vm_test.go プロジェクト: nlfiedler/bakeneko
func (vms *VirtMachSuite) TestSymbolUndef(c *gc.C) {
	expr := NewSymbol("foo")
	name := "TestSymbol"
	code, err := Compile(name, expr)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to compile code: %s", err))
	env := theReportEnvironment
	result, err := EvaluateCode(code, env)
	c.Assert(result, gc.IsNil, gc.Commentf("result should be nil when error"))
	c.Assert(err, gc.NotNil, gc.Commentf("failure expected for %q", expr))
	c.Check(err.ErrorCode(), gc.Equals, EARGUMENT)
	c.Check(err.ErrorMessage(), gc.Matches, ".*unbound variable: foo")
}
コード例 #26
0
ファイル: livetests.go プロジェクト: klyachin/juju
// TestStartStop is similar to Tests.TestStartStop except
// that it does not assume a pristine environment.
func (t *LiveTests) TestStartStop(c *gc.C) {
	t.PrepareOnce(c)
	t.UploadFakeTools(c, t.Env.Storage())

	inst, _ := testing.AssertStartInstance(c, t.Env, "0")
	c.Assert(inst, gc.NotNil)
	id0 := inst.Id()

	insts, err := t.Env.Instances([]instance.Id{id0, id0})
	c.Assert(err, gc.IsNil)
	c.Assert(insts, gc.HasLen, 2)
	c.Assert(insts[0].Id(), gc.Equals, id0)
	c.Assert(insts[1].Id(), gc.Equals, id0)

	// Asserting on the return of AllInstances makes the test fragile,
	// as even comparing the before and after start values can be thrown
	// off if other instances have been created or destroyed in the same
	// time frame. Instead, just check the instance we created exists.
	insts, err = t.Env.AllInstances()
	c.Assert(err, gc.IsNil)
	found := false
	for _, inst := range insts {
		if inst.Id() == id0 {
			c.Assert(found, gc.Equals, false, gc.Commentf("%v", insts))
			found = true
		}
	}
	c.Assert(found, gc.Equals, true, gc.Commentf("expected %v in %v", inst, insts))

	addresses, err := jujutesting.WaitInstanceAddresses(t.Env, inst.Id())
	c.Assert(err, gc.IsNil)
	c.Assert(addresses, gc.Not(gc.HasLen), 0)

	insts, err = t.Env.Instances([]instance.Id{id0, ""})
	c.Assert(err, gc.Equals, environs.ErrPartialInstances)
	c.Assert(insts, gc.HasLen, 2)
	c.Check(insts[0].Id(), gc.Equals, id0)
	c.Check(insts[1], gc.IsNil)

	err = t.Env.StopInstances(inst.Id())
	c.Assert(err, gc.IsNil)

	// The machine may not be marked as shutting down
	// immediately. Repeat a few times to ensure we get the error.
	for a := t.Attempt.Start(); a.Next(); {
		insts, err = t.Env.Instances([]instance.Id{id0})
		if err != nil {
			break
		}
	}
	c.Assert(err, gc.Equals, environs.ErrNoInstances)
	c.Assert(insts, gc.HasLen, 0)
}
コード例 #27
0
ファイル: vm_test.go プロジェクト: nlfiedler/bakeneko
func (vms *VirtMachSuite) TestClosure(c *gc.C) {
	expr := `(define (f (x)) (+ 1 2 x)) (f 7)`
	name := "TestClosure"
	code, err := CompileString(name, expr)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to compile code: %s", err))
	c.Assert(code, gc.NotNil, gc.Commentf("failed to produce code"))
	env := NewEnvironment(theReportEnvironment)
	result, err := EvaluateCode(code, env)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to evaluate code: %s", err))
	c.Assert(result, gc.NotNil, gc.Commentf("lambda failed to yield result"))
	num := result.(Integer)
	c.Check(num.ToInteger(), gc.Equals, int64(10))
}
コード例 #28
0
ファイル: vm_test.go プロジェクト: nlfiedler/bakeneko
func (vms *VirtMachSuite) TestProcedure(c *gc.C) {
	expr := parseAndExpandForTest(`(+ 1 2 3)`, c)
	name := "TestProcedure"
	code, err := Compile(name, expr)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to compile code: %s", err))
	c.Assert(code, gc.NotNil, gc.Commentf("failed to produce code"))
	env := theReportEnvironment
	result, err := EvaluateCode(code, env)
	c.Assert(err, gc.IsNil, gc.Commentf("failed to evaluate code: %s", err))
	c.Assert(result, gc.NotNil, gc.Commentf("(+) failed to yield result"))
	num := result.(Integer)
	c.Check(num.ToInteger(), gc.Equals, int64(6))
}
コード例 #29
0
ファイル: document_test.go プロジェクト: durgeshm/goprismic
func (s *TestSuite) TestGetImageView(c *gocheck.C) {
	i, _ := s.doc.GetImageFragment("image")
	c.Assert(i, gocheck.NotNil, gocheck.Commentf("Found an image"))
	c.Assert(i.Main.Url, gocheck.Equals, "https://prismicio.s3.amazonaws.com/lesbonneschoses/30214ac0c3a51e7516d13c929086c49f49af7988.png", gocheck.Commentf("Image has the right url"))
	c.Assert(i.AsHtml(), gocheck.Equals, i.Main.AsHtml(), gocheck.Commentf("The image html is the main view html"))
	c.Assert(i.AsHtml(), gocheck.Equals, "<img src=\"https://prismicio.s3.amazonaws.com/lesbonneschoses/30214ac0c3a51e7516d13c929086c49f49af7988.png\" width=\"500\" height=\"500\"/>", gocheck.Commentf("The image html is ok"))

	v, _ := i.GetView("icon")
	c.Assert(v, gocheck.NotNil, gocheck.Commentf("Found a view"))
	c.Assert(v.Url, gocheck.Equals, "https://prismicio.s3.amazonaws.com/lesbonneschoses/f428de9ed832705617063c9c69eb752f4ab92ac5.png", gocheck.Commentf("View has the right url"))
	c.Assert(v.AsHtml(), gocheck.Equals, "<img src=\"https://prismicio.s3.amazonaws.com/lesbonneschoses/f428de9ed832705617063c9c69eb752f4ab92ac5.png\" width=\"250\" height=\"250\"/>", gocheck.Commentf("The view html is ok"))
	c.Assert(v.Ratio(), gocheck.Equals, 1.0, gocheck.Commentf("The view has the right ratio"))
}
コード例 #30
0
ファイル: vm_test.go プロジェクト: nlfiedler/bakeneko
func virtmachErrorTest(c *gc.C, table map[string]string) {
	for input, expected := range table {
		expr := parseAndExpandForTest(input, c)
		code, err := Compile("compilerErrorTest", expr)
		c.Assert(err, gc.IsNil, gc.Commentf("compilation failed: %s", err))
		c.Assert(code, gc.NotNil, gc.Commentf("compiler did not produce code"))
		env := NewEnvironment(theReportEnvironment)
		result, err := EvaluateCode(code, env)
		c.Assert(err, gc.NotNil, gc.Commentf("VM should have raised error"))
		c.Assert(result, gc.IsNil, gc.Commentf("error in VM should yield nil result"))
		c.Check(err, gc.ErrorMatches, expected)
	}
}