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

Table.SortBy can't handle empty cells #305

Closed
Skeeve opened this issue Mar 14, 2024 · 1 comment · Fixed by #306
Closed

Table.SortBy can't handle empty cells #305

Skeeve opened this issue Mar 14, 2024 · 1 comment · Fixed by #306

Comments

@Skeeve
Copy link
Contributor

Skeeve commented Mar 14, 2024

Describe the bug

The last column of your test table has no values for two rows. Sorting that column fails.

To Reproduce

Put this into table_test.go:

func TestTable_MoreSort(t *testing.T) {
	table := Table{}
	table.AppendRows(testRows)
	table.AppendHeader(testHeader)
	table.SetStyle(styleTest)
	expectedOut := `(-----^------------^-----------^--------^-----------------------------)
[<#  >|<FIRST NAME>|<LAST NAME>|<SALARY>|<                           >]
{-----+------------+-----------+--------+-----------------------------}
[<20 >|<Jon       >|<Snow     >|<  2000>|<You know nothing, Jon Snow!>]
[<300>|<Tyrion    >|<Lannister>|<  5000>|<                           >]
[<1  >|<Arya      >|<Stark    >|<  3000>|<                           >]
\-----v------------v-----------v--------v-----------------------------/`
	table.SortBy([]SortBy{{Number: 5, Mode: Dsc}, {Name: "Last Name", Mode: Asc}})
	assert.Equal(t, expectedOut, table.Render())
}

Expected behavior

Expactation is that empty cells are sorted according to their string, representation.

The expected output is given in the code.

Screenshots

Actual output:

(-----^------------^-----------^--------^-----------------------------)
[<  #>|<FIRST NAME>|<LAST NAME>|<SALARY>|<                           >]
{-----+------------+-----------+--------+-----------------------------}
[<300>|<Tyrion    >|<Lannister>|<  5000>|<                           >]
[< 20>|<Jon       >|<Snow     >|<  2000>|<You know nothing, Jon Snow!>]
[<  1>|<Arya      >|<Stark    >|<  3000>|<                           >]
\-----v------------v-----------v--------v-----------------------------/

As you see: Column 5 isn't properly sorted.

Software (please complete the following information):

  • OS: Mac OS - But I'm using a dockerized go
  • GoLang Version dockerized golang:latest
@jedib0t
Copy link
Owner

jedib0t commented Mar 14, 2024

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 a pull request may close this issue.

2 participants