// Copyright 2013 Apcera Inc. All rights reserved. package termtables import ( "testing" ) func TestCreateTableHTML(t *testing.T) { expected := "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
NameValue
heyyou
ken1234
derek3.14
derek too3.15
\n" table := CreateTable() table.SetModeHTML() table.AddHeaders("Name", "Value") table.AddRow("hey", "you") table.AddRow("ken", 1234) table.AddRow("derek", 3.14) table.AddRow("derek too", 3.1456788) output := table.Render() if output != expected { t.Fatal(DisplayFailedOutput(output, expected)) } } func TestTableWithHeaderHTML(t *testing.T) { expected := "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
Example
NameValue
heyyou
ken1234
derek3.14
derek too3.15
\n" table := CreateTable() table.SetModeHTML() table.AddTitle("Example") table.AddHeaders("Name", "Value") table.AddRow("hey", "you") table.AddRow("ken", 1234) table.AddRow("derek", 3.14) table.AddRow("derek too", 3.1456788) output := table.Render() if output != expected { t.Fatal(DisplayFailedOutput(output, expected)) } } func TestTableTitleWidthAdjustsHTML(t *testing.T) { expected := "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
Example My Foo Bar'd Test
NameValue
heyyou
ken1234
derek3.14
derek too3.15
\n" table := CreateTable() table.SetModeHTML() table.AddTitle("Example My Foo Bar'd Test") table.AddHeaders("Name", "Value") table.AddRow("hey", "you") table.AddRow("ken", 1234) table.AddRow("derek", 3.14) table.AddRow("derek too", 3.1456788) output := table.Render() if output != expected { t.Fatal(DisplayFailedOutput(output, expected)) } } func TestTableWithNoHeadersHTML(t *testing.T) { expected := "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
heyyou
ken1234
derek3.14
derek too3.15
\n" table := CreateTable() table.SetModeHTML() table.AddRow("hey", "you") table.AddRow("ken", 1234) table.AddRow("derek", 3.14) table.AddRow("derek too", 3.1456788) output := table.Render() if output != expected { t.Fatal(DisplayFailedOutput(output, expected)) } } func TestTableUnicodeWidthsHTML(t *testing.T) { expected := "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
NameCost
Currency¤10
US Dollar$30
Euro€27
Thai฿70
\n" table := CreateTable() table.SetModeHTML() table.AddHeaders("Name", "Cost") table.AddRow("Currency", "¤10") table.AddRow("US Dollar", "$30") table.AddRow("Euro", "€27") table.AddRow("Thai", "฿70") output := table.Render() if output != expected { t.Fatal(DisplayFailedOutput(output, expected)) } } func TestTableWithAlignment(t *testing.T) { expected := "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
FooBar
humptydumpty
r<- on right
\n" table := CreateTable() table.SetModeHTML() table.AddHeaders("Foo", "Bar") table.AddRow("humpty", "dumpty") table.AddRow(CreateCell("r", &CellStyle{Alignment: AlignRight}), "<- on right") output := table.Render() if output != expected { t.Fatal(DisplayFailedOutput(output, expected)) } } func TestTableAfterSetAlign(t *testing.T) { expected := "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
AlphabeticalNum
alfa1
bravo2
charlie3
\n" table := CreateTable() table.SetModeHTML() table.AddHeaders("Alphabetical", "Num") table.AddRow("alfa", 1) table.AddRow("bravo", 2) table.AddRow("charlie", 3) table.SetAlign(AlignRight, 1) output := table.Render() if output != expected { t.Fatal(DisplayFailedOutput(output, expected)) } } func TestTableWithAltTitleStyle(t *testing.T) { expected := "" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
Metasyntactic
FooBarBaz
abc
αβγ
\n" table := CreateTable() table.SetModeHTML() table.SetHTMLStyleTitle(TitleAsThSpan) table.AddTitle("Metasyntactic") table.AddHeaders("Foo", "Bar", "Baz") table.AddRow("a", "b", "c") table.AddRow("α", "β", "γ") output := table.Render() if output != expected { t.Fatal(DisplayFailedOutput(output, expected)) } }