Skip to content

Commit

Permalink
broken WIP tests and public testdata
Browse files Browse the repository at this point in the history
  • Loading branch information
pbnjay committed Feb 22, 2021
1 parent 8439b8d commit 88aeec7
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 32 deletions.
6 changes: 6 additions & 0 deletions testdata/basic.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a b c d
1 Hello 42.0 0.0
2 World 99.1 0.01
3 This 7e8 0.001
4 Tests 2.4e-8 0.0001
5 Text 0.0001 0.00001
Binary file added testdata/basic.xls
Binary file not shown.
Binary file added testdata/basic.xlsx
Binary file not shown.
6 changes: 6 additions & 0 deletions testdata/basic2.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a b c d
1 Hello 42.0 0.00000
2 World 99.1 0.01000
3 This 7E+08 0.00100
4 Tests 2.4E-08 0.00010
5 Text 0.0001 0.00001
Binary file added testdata/basic2.xls
Binary file not shown.
Binary file added testdata/basic2.xlsx
Binary file not shown.
18 changes: 18 additions & 0 deletions testdata/multi_test.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Integers Floats Fractions Dates v1
One 1 1.234 1/2 "July 11, 2004" TRUE
Two 4 1.2345678 42 1/3 11 Jul 00 TRUE
Three 6 1.0 1/5 9-Sep FALSE
Two Words 99 -42.1 -4 1/5 Jun-42 TRUE
Three Small Words 123456789 123456789.0 9999 9/10 1-1-01 FALSE
This is a longer sentence that fills the cell and overflows 1000000000000 1000000000000.0
Some merged cells (tall version) 123456789 7 38 2/15 "July 12, 2004"
5 123456790.234 1/5 22 Aug 00
1000000000001 1111 1/10

Merged columns (single row)

Merged cells again (big box) custom yes/no bools!
A yes
B no
C
D
Binary file added testdata/multi_test.xls
Binary file not shown.
Binary file added testdata/multi_test.xlsx
Binary file not shown.
116 changes: 95 additions & 21 deletions xls/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import (
)

var testFiles = []string{
"../testdata/test.xls",
"../testdata/test2.xls",
"../testdata/test3.xls",
"../testdata/test4.xls",
"../testdata/multi_test.xls",
"../testdata/basic.xls",
"../testdata/basic2.xls",
}
Expand Down Expand Up @@ -44,42 +41,119 @@ func TestLoading(t *testing.T) {
}
}

func noTestBasic(t *testing.T) {
func TestBasic(t *testing.T) {
trueFile, err := os.ReadFile("../testdata/basic.tsv")
if err != nil {
t.Skip()
}
lines := strings.Split(string(trueFile), "\n")

for _, fn := range testFiles {
wb, err := Open(fn)
fn := "../testdata/basic.xls"
wb, err := Open(fn)
if err != nil {
t.Fatal(err)
}

sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
sheet, err := wb.Get(s)
if err != nil {
t.Fatal(err)
}

sheets, err := wb.List()
i := 0
for sheet.Next() {
row := strings.Join(sheet.Strings(), "\t")
if lines[i] != row {
t.Fatalf("line %d mismatch: '%s' <> '%s'", i, row, lines[i])
}
i++
}
}

err = wb.Close()
if err != nil {
t.Fatal(err)
}
}

func TestBasic2(t *testing.T) {
trueFile, err := os.ReadFile("../testdata/basic2.tsv")
if err != nil {
t.Skip()
}
lines := strings.Split(string(trueFile), "\n")

fn := "../testdata/basic2.xls"
wb, err := Open(fn)
if err != nil {
t.Fatal(err)
}

sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
sheet, err := wb.Get(s)
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
sheet, err := wb.Get(s)
if err != nil {
t.Fatal(err)
}

i := 0
for sheet.Next() {
row := strings.Join(sheet.Strings(), "\t")
if lines[i] != row {
t.Fatalf("line %d mismatch: '%s' <> '%s'", i, row, lines[i])
}
i++
i := 0
for sheet.Next() {
row := strings.Join(sheet.Strings(), "\t")
if lines[i] != row {
t.Fatalf("line %d mismatch: '%s' <> '%s'", i, row, lines[i])
}
i++
}
}

err = wb.Close()
err = wb.Close()
if err != nil {
t.Fatal(err)
}
}

func TestMulti(t *testing.T) {
trueFile, err := os.ReadFile("../testdata/multi_test.tsv")
if err != nil {
t.Skip()
}
lines := strings.Split(string(trueFile), "\n")

fn := "../testdata/multi_test.xls"
wb, err := Open(fn)
if err != nil {
t.Fatal(err)
}

sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
sheet, err := wb.Get(s)
if err != nil {
t.Fatal(err)
}

i := 0
for sheet.Next() {
row := strings.Join(sheet.Strings(), "\t")
if lines[i] != row {
t.Fatalf("line %d mismatch: '%s' <> '%s'", i, row, lines[i])
}
i++
}
}

err = wb.Close()
if err != nil {
t.Fatal(err)
}
}
129 changes: 118 additions & 11 deletions xlsx/simple_test.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,159 @@
package xlsx

import (
"log"
"os"
"strings"
"testing"
)

func noTestOpen(t *testing.T) {
wb, err := Open("test.xlsx")
var testFiles = []string{
"../testdata/multi_test.xlsx",
"../testdata/basic.xlsx",
"../testdata/basic2.xlsx",
}

func TestLoading(t *testing.T) {
for _, fn := range testFiles {
wb, err := Open(fn)
if err != nil {
t.Fatal(err)
}

sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
sheet, err := wb.Get(s)
if err != nil {
t.Fatal(err)
}

for sheet.Next() {
sheet.Strings()
}
}

err = wb.Close()
if err != nil {
t.Fatal(err)
}
}
}

func TestBasic(t *testing.T) {
trueFile, err := os.ReadFile("../testdata/basic.tsv")
if err != nil {
t.Skip()
}
lines := strings.Split(string(trueFile), "\n")

fn := "../testdata/basic.xlsx"
wb, err := Open(fn)
if err != nil {
t.Fatal(err)
}

sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
sheet, err := wb.Get(s)
if err != nil {
t.Fatal(err)
}

i := 0
for sheet.Next() {
row := strings.Join(sheet.Strings(), "\t")
if lines[i] != row {
t.Fatalf("line %d mismatch: '%s' <> '%s'", i, row, lines[i])
}
i++
}
}

err = wb.Close()
if err != nil {
t.Fatal(err)
}
}

func TestBasic2(t *testing.T) {
trueFile, err := os.ReadFile("../testdata/basic2.tsv")
if err != nil {
t.Skip()
}
lines := strings.Split(string(trueFile), "\n")

fn := "../testdata/basic2.xlsx"
wb, err := Open(fn)
if err != nil {
log.Fatal(err)
t.Fatal(err)
}

sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
//log.Println(s)
sheet, err := wb.Get(s)
if err != nil {
t.Fatal(err)
}

i := 0
for sheet.Next() {
sheet.Strings()
row := strings.Join(sheet.Strings(), "\t")
if lines[i] != row {
t.Fatalf("line %d mismatch: '%s' <> '%s'", i, row, lines[i])
}
i++
}
}

err = wb.Close()
if err != nil {
t.Fatal(err)
}
}

func TestOpen2(t *testing.T) {
wb, err := Open("test2.xlsx")
func TestMulti(t *testing.T) {
trueFile, err := os.ReadFile("../testdata/multi_test.tsv")
if err != nil {
log.Fatal(err)
t.Skip()
}
lines := strings.Split(string(trueFile), "\n")

fn := "../testdata/multi_test.xlsx"
wb, err := Open(fn)
if err != nil {
t.Fatal(err)
}

sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
//log.Println(s)
sheet, err := wb.Get(s)
if err != nil {
t.Fatal(err)
}

i := 0
for sheet.Next() {
sheet.Strings()
row := strings.Join(sheet.Strings(), "\t")
if lines[i] != row {
t.Fatalf("line %d mismatch: '%s' <> '%s'", i, row, lines[i])
}
i++
}
}

err = wb.Close()
if err != nil {
t.Fatal(err)
}
}

0 comments on commit 88aeec7

Please sign in to comment.