コード例 #1
0
ファイル: sml_test.go プロジェクト: kung-foo/golib
// TestSML2XML checks the conversion from SML to XML.
func TestSML2XML(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	in := `{html
{head {title A test document}}
{body
  {h1:title A test document}
  {p:intro:preface The is a simple sentence with an {em emphasized}
  and a {strong strong} text. We'll see how it renders.}
  {ul
    {li:1 It should be nice.}
    {li:2 It should be error free.}
    {li:3 It should be fast.}
  }
  {!
for foo := 0; foo < 42; foo++ {
	println(foo)
}
  !}
}}`
	builder := sml.NewNodeBuilder()
	err := sml.ReadSML(strings.NewReader(in), builder)
	assert.Nil(err)
	root, err := builder.Root()
	assert.Nil(err)

	buf := bytes.NewBufferString("")
	ctx := sml.NewWriterContext(sml.NewXMLWriter("pre"), buf, true, "    ")
	ctx.Register("li", newLIWriter())
	sml.WriteSML(root, ctx)

	assert.Logf("===== XML =====")
	assert.Logf(buf.String())
	assert.Logf("===== DONE =====")
}
コード例 #2
0
ファイル: sml_test.go プロジェクト: kung-foo/golib
// TestWriterProcessing checks the writing of SML.
func TestWriterProcessing(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	root := createNodeStructure(assert)
	bufA := bytes.NewBufferString("")
	bufB := bytes.NewBufferString("")
	ctxA := sml.NewWriterContext(sml.NewStandardSMLWriter(), bufA, true, "    ")
	ctxB := sml.NewWriterContext(sml.NewStandardSMLWriter(), bufB, false, "")

	sml.WriteSML(root, ctxA)
	sml.WriteSML(root, ctxB)

	assert.Logf("===== WITH INDENT =====")
	assert.Logf(bufA.String())
	assert.Logf("===== WITHOUT INDENT =====")
	assert.Logf(bufB.String())
	assert.Logf("===== DONE =====")

	assert.NotEmpty(bufA, "Buffer A must not be empty.")
	assert.NotEmpty(bufB, "Buffer B must not be empty.")
}
コード例 #3
0
ファイル: sml_test.go プロジェクト: kung-foo/golib
// TestPositiveNodeReading checks the successful reading of nodes.
func TestPositiveNodeReading(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	text := "Before!   {foo:main {bar:1:first Yadda ^{Test^} 1} {! Raw: }} { ! ^^^ !}  {inbetween}  {bar:2:last Yadda {Test ^^} 2}}   After!"
	builder := sml.NewNodeBuilder()
	err := sml.ReadSML(strings.NewReader(text), builder)
	assert.Nil(err)
	root, err := builder.Root()
	assert.Nil(err)
	assert.Equal(root.Tag(), []string{"foo", "main"})
	assert.NotEmpty(root)

	buf := bytes.NewBufferString("")
	ctx := sml.NewWriterContext(sml.NewStandardSMLWriter(), buf, true, "    ")
	sml.WriteSML(root, ctx)

	assert.Logf("===== PARSED SML =====")
	assert.Logf(buf.String())
	assert.Logf("===== DONE =====")
}