forked from nao1215/filesql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_test.go
More file actions
147 lines (120 loc) · 3.41 KB
/
table_test.go
File metadata and controls
147 lines (120 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package filesql
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewTable(t *testing.T) {
t.Parallel()
t.Run("Create table with header and records", func(t *testing.T) {
t.Parallel()
header := newHeader([]string{"col1", "col2"})
records := []Record{
newRecord([]string{"val1", "val2"}),
newRecord([]string{"val3", "val4"}),
}
table := newTable("test", header, records)
assert.Equal(t, "test", table.getName(), "Table name mismatch")
assert.True(t, table.getHeader().equal(header), "Header mismatch")
assert.Len(t, table.getRecords(), 2, "Record count mismatch")
assert.True(t, table.getRecords()[0].equal(records[0]), "First record mismatch")
})
}
func TestTable_Equal(t *testing.T) {
t.Parallel()
header := newHeader([]string{"col1", "col2"})
records := []Record{
newRecord([]string{"val1", "val2"}),
newRecord([]string{"val3", "val4"}),
}
table1 := newTable("test", header, records)
table2 := newTable("test", header, records)
table3 := newTable("different", header, records)
t.Run("Equal tables", func(t *testing.T) {
t.Parallel()
assert.True(t, table1.equal(table2), "Tables should be equal")
})
t.Run("Different names", func(t *testing.T) {
t.Parallel()
assert.False(t, table1.equal(table3), "Tables with different names should not be equal")
})
t.Run("Different header", func(t *testing.T) {
t.Parallel()
differentHeader := newHeader([]string{"col1", "col3"})
table4 := newTable("test", differentHeader, records)
assert.False(t, table1.equal(table4), "Tables with different headers should not be equal")
})
t.Run("Different record count", func(t *testing.T) {
t.Parallel()
differentRecords := []Record{
newRecord([]string{"val1", "val2"}),
}
table5 := newTable("test", header, differentRecords)
assert.False(t, table1.equal(table5), "Tables with different record count should not be equal")
})
t.Run("Different record values", func(t *testing.T) {
t.Parallel()
differentValueRecords := []Record{
newRecord([]string{"val1", "val2"}),
newRecord([]string{"val3", "different"}),
}
table6 := newTable("test", header, differentValueRecords)
assert.False(t, table1.equal(table6), "Tables with different record values should not be equal")
})
}
func TestTableFromFilePath_Additional(t *testing.T) {
t.Parallel()
tests := []struct {
name string
filePath string
expected string
}{
{
name: "Simple file with extension",
filePath: "data.csv",
expected: "data",
},
{
name: "File with path",
filePath: filepath.Join("home", "user", "documents", "data.csv"),
expected: "data",
},
{
name: "File with multiple dots",
filePath: "data.backup.csv",
expected: "data.backup",
},
{
name: "File without extension",
filePath: "data",
expected: "data",
},
{
name: "File with path and no extension",
filePath: filepath.Join("home", "user", "data"),
expected: "data",
},
{
name: "Hidden file",
filePath: ".hidden",
expected: "",
},
{
name: "Hidden file with extension",
filePath: ".gitignore",
expected: "",
},
{
name: "Compressed file",
filePath: "data.csv.gz",
expected: "data",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := tableFromFilePath(tt.filePath)
assert.Equal(t, tt.expected, result, "tableFromFilePath failed for %s", tt.filePath)
})
}
}