mirror of
https://github.com/FiloSottile/age.git
synced 2025-12-23 05:25:14 +00:00
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
// Copyright 2021 The age Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package format_test
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"filippo.io/age/internal/format"
|
|
)
|
|
|
|
func TestStanzaMarshal(t *testing.T) {
|
|
s := &format.Stanza{
|
|
Type: "test",
|
|
Args: []string{"1", "2", "3"},
|
|
Body: nil, // empty
|
|
}
|
|
buf := &bytes.Buffer{}
|
|
s.Marshal(buf)
|
|
if exp := "-> test 1 2 3\n\n"; buf.String() != exp {
|
|
t.Errorf("wrong empty stanza encoding: expected %q, got %q", exp, buf.String())
|
|
}
|
|
|
|
buf.Reset()
|
|
s.Body = []byte("AAA")
|
|
s.Marshal(buf)
|
|
if exp := "-> test 1 2 3\nQUFB\n"; buf.String() != exp {
|
|
t.Errorf("wrong normal stanza encoding: expected %q, got %q", exp, buf.String())
|
|
}
|
|
|
|
buf.Reset()
|
|
s.Body = bytes.Repeat([]byte("A"), format.BytesPerLine)
|
|
s.Marshal(buf)
|
|
if exp := "-> test 1 2 3\nQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB\n\n"; buf.String() != exp {
|
|
t.Errorf("wrong 64 columns stanza encoding: expected %q, got %q", exp, buf.String())
|
|
}
|
|
}
|