Example #1
0
// 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.")
}
Example #2
0
// 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 =====")
}