예제 #1
0
파일: ot_test.go 프로젝트: kpmy/ot
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)
	}
}
예제 #2
0
파일: ot_test.go 프로젝트: kpmy/ot
func TestModules(t *testing.T) {
	/*
		<!DOCTYPE HTML>
		<html>
			<body>
				<p id="hello-teddy">превед, медвед</p>
				<br/><br/><br/>
				<p id="good-by-teddy">пока, медвед</p>
			</body>
		</html>
	*/
	const testTemplate = `
		core~template:
			import :: html;
			html:
				body:
					p(hello-teddy): "превед, медвед";
					br br br
					p(good-by-teddy): "пока, медвед";
				;
			;
		;
	`
	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 {
			renderHtml(m, t)
		} else {
			t.Fatal(err)
		}
	} else {
		t.Fatal(err)
	}
}
예제 #3
0
파일: ot_test.go 프로젝트: kpmy/ot
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)
}
예제 #4
0
파일: ot_test.go 프로젝트: kpmy/ot
func TestContext(t *testing.T) {
	const extTemplate = `
		core~template:
			import: context;
			block(id):
				$: test-list/1; $: test-list/1; $: test-list/1;
			;
		;
	`
	const testTemplate = `
		core~template(бла-блабыч):
			import :: context;
			$: test; $: test-tri;
			$: test-path/test;
			$: test-list/0; $: test-list/1; "so template" $: test-list/2;
			test:
				$include: my~external(id);
			;
		;
	`
	data := make(map[string]interface{})
	data["test"] = "test-string"
	data["test-tri"] = tri.TRUE
	data["test-path"] = data
	data["test-list"] = []interface{}{"one", "two", "three"}

	var eo otm.Object
	p := otp.ConnectTo(ots.ConnectTo(bufio.NewReader(bytes.NewBufferString(extTemplate))))
	if ext, err := p.Template(); err == nil {
		o := conv.Map(ext)
		if err := conv.Resolve(o); err == nil {
			if err := conv.ResolveContext(o, nil, data); err == nil {
				eo = o.FindById("id")
				assert.For(eo != nil, 20)
				t.Log("external resolved")
			} else {
				t.Fatal(err)
			}
		} else {
			t.Fatal(err)
		}
	} else {
		t.Fatal(err)
	}
	resolver := func(o otm.Qualident) (otm.Object, error) {
		assert.For(o.Identifier == "id", 20)
		return eo, nil
	}
	{
		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 {
				if err := conv.ResolveContext(m, resolver, data); err == nil {
					prettyPrintObject(m, t)
				} else {
					t.Fatal(err)
				}
			} else {
				t.Fatal(err)
			}
		} else {
			t.Fatal(err)
		}
	}
}