golib/helper/table/render_bidi_test.go

61 lines
2.4 KiB
Go
Raw Normal View History

//
// render_bidi_test.go
// Copyright (C) 2023 tiglog <me@tiglog.com>
//
// Distributed under terms of the MIT license.
//
2023-08-20 13:50:39 +08:00
package table
import (
"testing"
"git.hexq.cn/tiglog/golib/helper/text"
2023-08-20 13:50:39 +08:00
)
func TestTable_Render_BiDiText(t *testing.T) {
table := Table{}
table.AppendHeader(Row{"תאריך", "סכום", "מחלקה", "תגים"})
table.AppendRow(Row{"2020-01-01", 5.0, "מחלקה1", []string{"תג1", "תג2"}})
table.AppendRow(Row{"2021-02-01", 5.0, "מחלקה1", []string{"תג1"}})
table.AppendRow(Row{"2022-03-01", 5.0, "מחלקה2", []string{"תג1"}})
table.AppendFooter(Row{"סהכ", 30})
table.SetAutoIndex(true)
//table.Style().Format.Direction = text.Default
compareOutput(t, table.Render(), `
+---+------------+------+--------+-----------+
| | תאריך | סכום | מחלקה | תגים |
+---+------------+------+--------+-----------+
| 1 | 2020-01-01 | 5 | מחלקה1 | [תג1 תג2] |
| 2 | 2021-02-01 | 5 | מחלקה1 | [תג1] |
| 3 | 2022-03-01 | 5 | מחלקה2 | [תג1] |
+---+------------+------+--------+-----------+
| | סהכ | 30 | | |
+---+------------+------+--------+-----------+`)
table.Style().Format.Direction = text.LeftToRight
compareOutput(t, table.Render(), `
+---+------------+------+--------+-----------+
| | תאריך | סכום | מחלקה | תגים |
+---+------------+------+--------+-----------+
| 1 | 2020-01-01 | 5 | מחלקה1 | [תג1 תג2] |
| 2 | 2021-02-01 | 5 | מחלקה1 | [תג1] |
| 3 | 2022-03-01 | 5 | מחלקה2 | [תג1] |
+---+------------+------+--------+-----------+
| | סהכ | 30 | | |
+---+------------+------+--------+-----------+`)
table.Style().Format.Direction = text.RightToLeft
compareOutput(t, table.Render(), `
+---+------------+------+--------+-----------+
| | תאריך | סכום | מחלקה | תגים |
+---+------------+------+--------+-----------+
| 1 | 2020-01-01 | 5 | מחלקה1 | [תג1 תג2] |
| 2 | 2021-02-01 | 5 | מחלקה1 | [תג1] |
| 3 | 2022-03-01 | 5 | מחלקה2 | [תג1] |
+---+------------+------+--------+-----------+
| | סהכ | 30 | | |
+---+------------+------+--------+-----------+`)
}