Exemple #1
0
func TestBuilder(t *testing.T) {
	root := otm.Qualident{Class: "root"}
	br := otm.Qualident{Class: "br"}
	br0 := otm.Qualident{Class: "br", Identifier: "null"}
	b := conv.Begin(root).Value("hello", 1945, 3.14, 2.71, "world", '!')
	b.Child(conv.Begin(br).Prod()).Child(conv.Begin(br).Child(conv.Begin(br).Prod()).Prod()).Child(conv.Begin(br0).Prod())
	b.Value(conv.Link("null"))
	o := b.End()
	prettyPrintObject(o, t)
	prettyPrintObject(o.CopyOf(otm.SHALLOW), t)
	prettyPrintObject(o.CopyOf(otm.DEEP), t)
}
Exemple #2
0
func TestGenerate(t *testing.T) {
	const testTemplate = `
	html:
		body: br awef wef "fwef'wef" 22323 0.1112 49U true false nil inf -inf
		;
	;`

	p := otp.ConnectTo(ots.ConnectTo(bufio.NewReader(bytes.NewBufferString(testTemplate))))
	if tpl, err := p.Template(); err == nil {
		m := conv.Map(tpl)
		conv.Resolve(m)

		buf := bytes.NewBuffer(nil)
		otg.ConnectTo(buf).Write(m)
		s := buf.String()
		t.Log(s)
		p0 := otp.ConnectTo(ots.ConnectTo(bufio.NewReader(bytes.NewBufferString(s))))
		if tpl0, err0 := p0.Template(); err0 == nil {
			m0 := conv.Map(tpl0)
			conv.Resolve(m0)
			prettyPrintObject(m0, t)
		}
	} else {
		t.Fatal(err)
	}
	{
		buf := bytes.NewBuffer(nil)
		otg.ConnectTo(buf).Write(conv.Begin(otm.Qualident{Class: "test"}).Value("asdf asdf asdf `asdfasdf").Value([]uint8{0, 1, 2, 3, 4}).End())
		s := buf.String()
		t.Log(s)
	}
}
Exemple #3
0
func TestBinary(t *testing.T) {
	const testTemplate = `
		core~template:
			import: zbase32;
			z32: pb1sa5dxfoo8q551pt1yw "pb1sa5dxfoo8q551pt1yw";
		;`

	p := otp.ConnectTo(ots.ConnectTo(bufio.NewReader(bytes.NewBufferString(testTemplate))))
	if tpl, err := p.Template(); err == nil {
		m := conv.Map(tpl)
		if err := conv.Resolve(m); err == nil {
			prettyPrintObject(m, t)
		} else {
			t.Fatal(err)
		}
	} else {
		t.Fatal(err)
	}

	hw := []uint8("hello, world")
	b := conv.Begin(otm.Qualident{Class: "z32"}).Value("hello", hw)
	prettyPrintObject(b.End(), t)
}