42 lines
882 B
Go
42 lines
882 B
Go
package model
|
|
|
|
import "testing"
|
|
|
|
func TestSegmentReferenceUsesSourceAndIndexWhenAvailable(t *testing.T) {
|
|
index := 3
|
|
segment := Segment{
|
|
Source: "input.json",
|
|
SourceSegmentIndex: &index,
|
|
SourceRef: "word-run:1:2:3",
|
|
}
|
|
|
|
got := SegmentReference(segment)
|
|
want := "input.json#3"
|
|
if got != want {
|
|
t.Fatalf("reference = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestSegmentReferenceFallsBackToSourceRef(t *testing.T) {
|
|
segment := Segment{
|
|
Source: "input.json",
|
|
SourceRef: "coalesce:2",
|
|
}
|
|
|
|
got := SegmentReference(segment)
|
|
want := "coalesce:2"
|
|
if got != want {
|
|
t.Fatalf("reference = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestSegmentReferenceReturnsEmptyWhenNoReferenceFieldsPresent(t *testing.T) {
|
|
segment := Segment{
|
|
Source: "input.json",
|
|
}
|
|
|
|
if got := SegmentReference(segment); got != "" {
|
|
t.Fatalf("reference = %q, want empty", got)
|
|
}
|
|
}
|