Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(system): refactor test system #505

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 4 additions & 24 deletions area_printer_test.go
Expand Up @@ -18,6 +18,10 @@ func TestAreaPrinter_NilPrint(t *testing.T) {
os.Stdout = originalStdout // Restore original os.Stdout
}

func TestAreaPrinter_WithMethods(t *testing.T) {
testWithMethods(t, pterm.AreaPrinter{})
}

func TestAreaPrinter_GenericStart(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
Expand Down Expand Up @@ -90,30 +94,6 @@ func TestAreaPrinter_GetContent(t *testing.T) {
os.Stdout = originalStdout // Restore original os.Stdout
}

func TestAreaPrinter_WithRemoveWhenDone(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area

p := pterm.AreaPrinter{}
p2 := p.WithRemoveWhenDone()

testza.AssertTrue(t, p2.RemoveWhenDone)

os.Stdout = originalStdout // Restore original os.Stdout
}

func TestAreaPrinter_WithFullscreen(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area

p := pterm.AreaPrinter{}
p2 := p.WithFullscreen()

testza.AssertTrue(t, p2.Fullscreen)

os.Stdout = originalStdout // Restore original os.Stdout
}

func TestAreaPrinter_Clear(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
Expand Down
40 changes: 3 additions & 37 deletions atoms_test.go
@@ -1,44 +1,10 @@
package pterm_test

import (
"testing"

"github.com/MarvinJWendt/testza"
"github.com/pterm/pterm"
"testing"
)

func TestBar_WithLabel(t *testing.T) {
p := pterm.Bar{}
s := "X"
p2 := p.WithLabel(s)

testza.AssertEqual(t, s, p2.Label)
testza.AssertZero(t, p.Label)
}

func TestBar_WithStyle(t *testing.T) {
p := pterm.Bar{}
s := pterm.NewStyle(pterm.FgRed, pterm.BgBlue, pterm.Bold)
p2 := p.WithStyle(s)

testza.AssertEqual(t, s, p2.Style)
testza.AssertZero(t, p.Style)
}

func TestBar_WithValue(t *testing.T) {
p := pterm.Bar{}
s := 1337
p2 := p.WithValue(s)

testza.AssertEqual(t, s, p2.Value)
testza.AssertZero(t, p.Value)
}

func TestBar_WithLabelStyle(t *testing.T) {
p := pterm.Bar{}
s := pterm.NewStyle(pterm.FgRed, pterm.BgBlue, pterm.Bold)
p2 := p.WithLabelStyle(s)

testza.AssertEqual(t, s, p2.LabelStyle)
testza.AssertZero(t, p.LabelStyle)
func TestBar_WithMethods(t *testing.T) {
testWithMethods(t, pterm.Bar{})
}
89 changes: 4 additions & 85 deletions barchart_test.go
@@ -1,10 +1,8 @@
package pterm_test

import (
"os"
"testing"

"github.com/MarvinJWendt/testza"
"github.com/pterm/pterm"
)

Expand All @@ -17,6 +15,10 @@ func TestBarChartPrinterNilPrint(t *testing.T) {
}
}

func TestBarChartPrinter_WithMethods(t *testing.T) {
testWithMethods(t, pterm.BarChartPrinter{})
}

func TestBarChartPrinter_NilStylePrint(t *testing.T) {
bars := pterm.Bars{
pterm.Bar{
Expand Down Expand Up @@ -364,86 +366,3 @@ func TestBarChartPrinter_Render(t *testing.T) {
},
}).Render()
}

func TestBarChartPrinter_WithHorizontalBarCharacter(t *testing.T) {
p := pterm.BarChartPrinter{}
s := "X"
p2 := p.WithHorizontalBarCharacter(s)

testza.AssertEqual(t, s, p2.HorizontalBarCharacter)
testza.AssertZero(t, p.HorizontalBarCharacter)
}

func TestBarChartPrinter_WithVerticalBarCharacter(t *testing.T) {
p := pterm.BarChartPrinter{}
s := "X"
p2 := p.WithVerticalBarCharacter(s)

testza.AssertEqual(t, s, p2.VerticalBarCharacter)
testza.AssertZero(t, p.VerticalBarCharacter)
}

func TestBarChartPrinter_WithBars(t *testing.T) {
p := pterm.BarChartPrinter{}
s := pterm.Bars{
pterm.Bar{
Label: "Test",
Value: 1337,
Style: pterm.NewStyle(pterm.FgRed, pterm.BgBlue, pterm.Bold),
},
pterm.Bar{
Label: "Test",
Value: 1337,
Style: pterm.NewStyle(pterm.FgRed, pterm.BgBlue, pterm.Bold),
},
}
p2 := p.WithBars(s)

testza.AssertEqual(t, s, p2.Bars)
testza.AssertZero(t, p.Bars)
}

func TestBarChartPrinter_WithHeight(t *testing.T) {
p := pterm.BarChartPrinter{}
s := 1337
p2 := p.WithHeight(s)

testza.AssertEqual(t, s, p2.Height)
testza.AssertZero(t, p.Height)
}

func TestBarChartPrinter_WithHorizontal(t *testing.T) {
p := pterm.BarChartPrinter{}
s := true
p2 := p.WithHorizontal(s)

testza.AssertEqual(t, s, p2.Horizontal)
testza.AssertZero(t, p.Horizontal)
}

func TestBarChartPrinter_WithShowValue(t *testing.T) {
p := pterm.BarChartPrinter{}
s := true
p2 := p.WithShowValue(s)

testza.AssertEqual(t, s, p2.ShowValue)
testza.AssertZero(t, p.ShowValue)
}

func TestBarChartPrinter_WithWidth(t *testing.T) {
p := pterm.BarChartPrinter{}
s := 1337
p2 := p.WithWidth(s)

testza.AssertEqual(t, s, p2.Width)
testza.AssertZero(t, p.Width)
}

func TestBarChartPrinter_WithWriter(t *testing.T) {
p := pterm.BarChartPrinter{}
s := os.Stderr
p2 := p.WithWriter(s)

testza.AssertEqual(t, s, p2.Writer)
testza.AssertZero(t, p.Writer)
}
22 changes: 4 additions & 18 deletions basic_text_printer_test.go
Expand Up @@ -3,7 +3,6 @@ package pterm_test
import (
"errors"
"io"
"os"
"testing"

"github.com/MarvinJWendt/testza"
Expand All @@ -17,6 +16,10 @@ func TestBasicTextPrinterNilPrint(t *testing.T) {
p.Println("Hello, World!")
}

func TestBasicTextPrinter_WithMethods(t *testing.T) {
testWithMethods(t, pterm.BasicTextPrinter{})
}

func TestBasicTextPrinterPrintMethods(t *testing.T) {
p := pterm.DefaultBasicText

Expand Down Expand Up @@ -96,20 +99,3 @@ func TestBasicTextPrinterPrintMethods(t *testing.T) {
testza.AssertZero(t, result)
})
}

func TestBasicTextPrinter_WithStyle(t *testing.T) {
s := pterm.NewStyle(pterm.FgRed, pterm.BgBlue, pterm.Bold)
p := pterm.BasicTextPrinter{}
p2 := p.WithStyle(s)

testza.AssertEqual(t, s, p2.Style)
}

func TestBasicTextPrinter_WithWriter(t *testing.T) {
p := pterm.BasicTextPrinter{}
s := os.Stderr
p2 := p.WithWriter(s)

testza.AssertEqual(t, s, p2.Writer)
testza.AssertZero(t, p.Writer)
}
68 changes: 4 additions & 64 deletions bigtext_printer_test.go
Expand Up @@ -2,7 +2,6 @@ package pterm_test

import (
"fmt"
"os"
"strings"
"testing"

Expand All @@ -16,6 +15,10 @@ func TestBigTextPrinterNilPrint(t *testing.T) {
p.Render()
}

func TestBigTextPrinter_WithMethods(t *testing.T) {
testWithMethods(t, pterm.BigTextPrinter{})
}

func TestBigTextPrinter_Render(t *testing.T) {
printer := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString("Hello"))
content, err := printer.Srender()
Expand Down Expand Up @@ -43,60 +46,6 @@ func TestBigTextPrinter_RenderRawOutput(t *testing.T) {
testza.AssertNotZero(t, content)
}

func TestBigTextPrinter_WithBigCharacters(t *testing.T) {
e := map[string]string{"a": "b", "c": "d"}
p := pterm.BigTextPrinter{}
p2 := p.WithBigCharacters(e)

testza.AssertEqual(t, e, p2.BigCharacters)
testza.AssertZero(t, p.BigCharacters)
}

func TestBigTextPrinter_WithLetters(t *testing.T) {
e := pterm.Letters{
pterm.Letter{
String: "test",
Style: pterm.NewStyle(pterm.FgRed, pterm.BgBlue, pterm.Bold),
},
pterm.Letter{
String: "test2",
Style: pterm.NewStyle(pterm.FgRed, pterm.BgBlue, pterm.Bold),
},
}
p := pterm.BigTextPrinter{}
p2 := p.WithLetters(e)

testza.AssertEqual(t, e, p2.Letters)
testza.AssertZero(t, p.Letters)
}

func TestLetter_WithString(t *testing.T) {
e := "Hello, World!"
p := pterm.Letter{}
p2 := p.WithString(e)

testza.AssertEqual(t, e, p2.String)
testza.AssertZero(t, p.String)
}

func TestLetter_WithStyle(t *testing.T) {
p := pterm.Letter{}
s := pterm.NewStyle(pterm.FgRed, pterm.BgRed, pterm.Bold)
p2 := p.WithStyle(s)

testza.AssertEqual(t, s, p2.Style)
testza.AssertZero(t, p.Style)
}

func TestLetter_WithRGB(t *testing.T) {
p := pterm.Letter{}
rgb := pterm.NewRGB(0, 0, 0)
p2 := p.WithRGB(rgb)

testza.AssertEqual(t, rgb, p2.RGB)
testza.AssertZero(t, p.RGB)
}

func TestNewLettersFromText(t *testing.T) {
e := pterm.Letters{
pterm.Letter{
Expand Down Expand Up @@ -155,12 +104,3 @@ func TestDefaultLettersMaxHeight(t *testing.T) {
testza.AssertTrue(t, h <= maxHeight, fmt.Sprintf("'%s' is too high", s))
}
}

func TestBigTextPrinter_WithWriter(t *testing.T) {
p := pterm.BigTextPrinter{}
s := os.Stderr
p2 := p.WithWriter(s)

testza.AssertEqual(t, s, p2.Writer)
testza.AssertZero(t, p.Writer)
}