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, "+") }
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`)) }
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)) }
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 <à> <em>tést</em>.</p>" c.Assert(p.AsHtml(), gocheck.Equals, content, gocheck.Commentf("Has the right rendering")) }
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")) }
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 <a> test.</pre>" c.Assert(p.AsHtml(), gocheck.Equals, content, gocheck.Commentf("Has the right rendering")) }
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& i& <a> <em>test</em>.</p>" c.Assert(p.AsHtml(), gocheck.Equals, content, gocheck.Commentf("Has the right rendering")) }
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")) }
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")) }
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")) }
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)) } }
// 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)) } }
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")) }
// 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)) } }
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")) }
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")) }
// 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 }
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")) }
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) } }
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")) } }
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)) }
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")) }
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")) }
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)) }
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") }
// 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) }
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)) }
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)) }
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")) }
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) } }