示例#1
0
// TestNegativeTreeReading checks the failing reading of trees.
func TestNegativeTreeReading(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	text := "{foo {bar 1}{bar 2}}"
	builder := sml.NewKeyStringValueTreeBuilder()
	err := sml.ReadSML(strings.NewReader(text), builder)
	assert.ErrorMatch(err, `.* node has multiple values`)
}
示例#2
0
// TestPositiveTreeReading checks the successful reading of trees.
func TestPositiveTreeReading(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	text := "{config {foo 1}{bar 2}{yadda {up down}{down up}}}"
	builder := sml.NewKeyStringValueTreeBuilder()
	err := sml.ReadSML(strings.NewReader(text), builder)
	assert.Nil(err)
	tree, err := builder.Tree()
	assert.Nil(err)
	assert.Logf("%v", tree)
}
示例#3
0
// Read reads the SML source of the configuration from a
// reader, parses it, and returns the configuration instance.
func Read(source io.Reader) (Configuration, error) {
	builder := sml.NewKeyStringValueTreeBuilder()
	err := sml.ReadSML(source, builder)
	if err != nil {
		return nil, errors.Annotate(err, ErrIllegalSourceFormat, errorMessages)
	}
	tree, err := builder.Tree()
	if err != nil {
		return nil, errors.Annotate(err, ErrIllegalSourceFormat, errorMessages)
	}
	if err := tree.At("config").Error(); err != nil {
		return nil, errors.Annotate(err, ErrIllegalSourceFormat, errorMessages)
	}
	return &configuration{tree}, nil
}