跳到主要内容

pkg/compute/util_format_test.go


Content

// Copyright 2023-2024 daviszhen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package compute

import (
"testing"
)

func TestFormatCtx(t *testing.T) {
ctx := &FormatCtx{}
ctx.Write("test")
if ctx.String() != "test" {
t.Errorf("expected 'test', got '%s'", ctx.String())
}

ctx.Writef("test %d", 1)
if ctx.String() != "testtest 1" {
t.Errorf("expected 'testtest 1', got '%s'", ctx.String())
}

ctx.Writefln("test %d", 2)
if ctx.String() != "testtest 1test 2\n" {
t.Errorf("expected 'testtest 1test 2\n', got '%s'", ctx.String())
}

ctx.Writeln("test", 3)
if ctx.String() != "testtest 1test 2\ntest 3\n" {
t.Errorf("expected 'testtest 1test 2\ntest 3\n', got '%s'", ctx.String())
}
}

func TestPadding(t *testing.T) {
p := &Padding{}
p.AddPad()
if p.pad != defaultIndent {
t.Errorf("expected %d, got %d", defaultIndent, p.pad)
}

p.RestorePad()
if p.pad != 0 {
t.Errorf("expected 0, got %d", p.pad)
}
}