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

Initializing t.data with new content instead of leaving it as nil #329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zveinn
Copy link

@zveinn zveinn commented Jul 10, 2024

leaving t.data as nil causes a panic if the table is re-rendered again without adding new rows

leaving t.data as nil causes a panic if the table is re-rendered again
without adding new rows
@aymanbagabas
Copy link
Member

@zveinn Could you please add a test case?

@zveinn
Copy link
Author

zveinn commented Jul 10, 2024

Not really, I´m too busy to write that for you :S sorry @aymanbagabas

@siennathesane
Copy link

Here's the test code to be added...

func TestEmptyTable(t *testing.T) {
	table := New().
		StyleFunc(TableStyle).
		Headers("Fruit", "Color", "Code")

	expected := strings.TrimSpace(`
┌───────┬───────┬──────┐
│ Fruit │ Color │ Code │
├───────┼───────┼──────┤
└───────┴───────┴──────┘
`)

	if stripString(table.String()) != expected {
		t.Fatalf("expected:\n\n%s\n\ngot:\n\n%s", expected, stripString(table.String()))
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants