highlight: add tests for ParseRanges

This commit is contained in:
Kisaragi Hiu 2022-07-25 19:27:11 +09:00
parent ab8d3bc16a
commit a7a960c460
No known key found for this signature in database
GPG key ID: 40ECBEAEA8775FC2

38
org/util_test.go Normal file
View file

@ -0,0 +1,38 @@
package org
import (
"fmt"
"testing"
)
var parseRangesTests = map[string][][2]int{
"3-5": {{3, 5}},
"3 8-10": {{3, 3}, {8, 10}},
"3 5 6": {{3, 3}, {5, 5}, {6, 6}},
" 9-10 5-6 3 ": {{9, 10}, {5, 6}, {3, 3}},
}
func TestParseRanges(t *testing.T) {
for s, expected := range parseRangesTests {
t.Run(s, func(t *testing.T) {
actual := ParseRanges(s)
// If this fails it looks like:
// util_test.go:<line>: 9-10 5-6 3 :
// --- Actual
// +++ Expected
// @@ -1 +1 @@
// -[[9 10] [5 9] [3 3]]
// +[[9 10] [5 6] [3 3]]
if len(actual) != len(expected) {
t.Errorf("%v:\n%v", s, diff(fmt.Sprintf("%v", actual), fmt.Sprintf("%v", expected)))
} else {
for i := range actual {
if actual[i] != expected[i] {
t.Errorf("%v:\n%v", s, diff(fmt.Sprintf("%v", actual), fmt.Sprintf("%v", expected)))
}
}
}
})
}
}