Assisted-by: GLM 5.3 Flash
This commit is contained in:
+17
-17
@@ -96,8 +96,8 @@ func TestMarshalContextHonoursCancellation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncoderGroupByKindDefault(t *testing.T) {
|
||||
// NewEncoder must default to GroupByKind=true so legacy callers keep the
|
||||
func TestEncoderLayoutGroupedDefault(t *testing.T) {
|
||||
// NewEncoder must default to LayoutKindGrouped so legacy callers keep the
|
||||
// scalars-first ordering.
|
||||
type Cfg struct {
|
||||
Name string `toml:"name"`
|
||||
@@ -117,7 +117,7 @@ func TestEncoderGroupByKindDefault(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncoderGroupByKindFalsePreservesOrder(t *testing.T) {
|
||||
func TestEncoderLayoutDeclarationPreservesOrder(t *testing.T) {
|
||||
type Inner struct {
|
||||
Host string `toml:"host"`
|
||||
}
|
||||
@@ -131,11 +131,11 @@ func TestEncoderGroupByKindFalsePreservesOrder(t *testing.T) {
|
||||
Server: Inner{Host: "h"},
|
||||
Debug: true,
|
||||
}
|
||||
out, err := NewEncoder().GroupByKind(false).Marshal(in)
|
||||
out, err := NewEncoder().Layout(LayoutKindDeclaration).Marshal(in)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
// With GroupByKind(false) the encoder walks entries in declaration order.
|
||||
// With Layout(LayoutKindDeclaration) the encoder walks entries in declaration order.
|
||||
// The output is still parseable, but a scalar that follows a header is
|
||||
// parsed as a sub-table key. That is the user's trade-off; see
|
||||
// docs/API.md.
|
||||
@@ -145,8 +145,8 @@ func TestEncoderGroupByKindFalsePreservesOrder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncoderGroupByKindTrueDefaultOrder(t *testing.T) {
|
||||
// The default (GroupByKind=true) must lift the trailing scalar ahead of
|
||||
func TestEncoderLayoutGroupedDefaultOrder(t *testing.T) {
|
||||
// The default (LayoutKindGrouped) must lift the trailing scalar ahead of
|
||||
// the [server] block so the document round-trips losslessly.
|
||||
type Inner struct {
|
||||
Host string `toml:"host"`
|
||||
@@ -224,12 +224,12 @@ func TestEncoderOmitEmptyArrayOfTablesStillSkipped(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncoderUseLiteralMultiline(t *testing.T) {
|
||||
func TestEncoderLiteralMultiline(t *testing.T) {
|
||||
type Cfg struct {
|
||||
Long string `toml:"long"`
|
||||
}
|
||||
long := strings.Repeat("a", 50) + "\nline two\nline three"
|
||||
out, err := NewEncoder().UseLiteralMultiline(20).Marshal(Cfg{Long: long})
|
||||
out, err := NewEncoder().LiteralMultiline(20).Marshal(Cfg{Long: long})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
@@ -239,12 +239,12 @@ func TestEncoderUseLiteralMultiline(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncoderUseLiteralMultilineBelowThreshold(t *testing.T) {
|
||||
func TestEncoderLiteralMultilineBelowThreshold(t *testing.T) {
|
||||
// A multi-line value shorter than the threshold must remain escaped.
|
||||
type Cfg struct {
|
||||
Short string `toml:"short"`
|
||||
}
|
||||
out, err := NewEncoder().UseLiteralMultiline(1000).Marshal(Cfg{Short: "one\ntwo"})
|
||||
out, err := NewEncoder().LiteralMultiline(1000).Marshal(Cfg{Short: "one\ntwo"})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
@@ -254,12 +254,12 @@ func TestEncoderUseLiteralMultilineBelowThreshold(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncoderUseLiteralMultilineThresholdZero(t *testing.T) {
|
||||
// UseLiteralMultiline(0) disables the literal form entirely.
|
||||
func TestEncoderLiteralMultilineThresholdZero(t *testing.T) {
|
||||
// LiteralMultiline(0) disables the literal form entirely.
|
||||
type Cfg struct {
|
||||
S string `toml:"s"`
|
||||
}
|
||||
out, err := NewEncoder().UseLiteralMultiline(0).Marshal(Cfg{S: "a\nb\nc\nd"})
|
||||
out, err := NewEncoder().LiteralMultiline(0).Marshal(Cfg{S: "a\nb\nc\nd"})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
@@ -282,7 +282,7 @@ func TestEncoderLiteralMultilineFallsBackWhenUnsafe(t *testing.T) {
|
||||
{"lone carriage return", "first\rsecond\nthird"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
out, err := NewEncoder().UseLiteralMultiline(5).Marshal(map[string]any{"s": c.in})
|
||||
out, err := NewEncoder().LiteralMultiline(5).Marshal(map[string]any{"s": c.in})
|
||||
if err != nil {
|
||||
t.Fatalf("%s: marshal: %v", c.name, err)
|
||||
}
|
||||
@@ -483,9 +483,9 @@ func TestEncoderChainedOptions(t *testing.T) {
|
||||
}
|
||||
long := strings.Repeat("x", 200)
|
||||
out, err := NewEncoder().
|
||||
GroupByKind(false).
|
||||
Layout(LayoutKindDeclaration).
|
||||
OmitEmptyArrays().
|
||||
UseLiteralMultiline(50).
|
||||
LiteralMultiline(50).
|
||||
Marshal(Cfg{S: "short", I: Inner{V: long}})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user