74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
package terrace
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseLine(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
line string
|
|
lineData *LineData
|
|
expected *LineData
|
|
expectError bool
|
|
}{
|
|
{
|
|
name: "empty line",
|
|
line: "",
|
|
lineData: NewLineData(' '),
|
|
expected: &LineData{Indent: ' ', Level: 0, OffsetHead: 0, OffsetTail: 0},
|
|
},
|
|
{
|
|
name: "no indentation",
|
|
line: "hello world",
|
|
lineData: NewLineData(' '),
|
|
expected: &LineData{Indent: ' ', Level: 0, OffsetHead: 0, OffsetTail: 5},
|
|
},
|
|
{
|
|
name: "with indentation",
|
|
line: " hello world",
|
|
lineData: NewLineData(' '),
|
|
expected: &LineData{Indent: ' ', Level: 2, OffsetHead: 2, OffsetTail: 7},
|
|
},
|
|
{
|
|
name: "only head",
|
|
line: "hello",
|
|
lineData: NewLineData(' '),
|
|
expected: &LineData{Indent: ' ', Level: 0, OffsetHead: 0, OffsetTail: 5},
|
|
},
|
|
{
|
|
name: "nil lineData",
|
|
line: "hello",
|
|
lineData: nil,
|
|
expectError: true,
|
|
},
|
|
{
|
|
name: "invalid indent",
|
|
line: "hello",
|
|
lineData: &LineData{Indent: 0},
|
|
expectError: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := ParseLine(tt.line, tt.lineData)
|
|
|
|
if tt.expectError {
|
|
if err == nil {
|
|
t.Errorf("Expected an error, but got nil")
|
|
}
|
|
return
|
|
}
|
|
|
|
if err != nil {
|
|
t.Errorf("Unexpected error: %v", err)
|
|
}
|
|
|
|
if *tt.lineData != *tt.expected {
|
|
t.Errorf("Expected %v, but got %v", *tt.expected, *tt.lineData)
|
|
}
|
|
})
|
|
}
|
|
}
|