File: util_test.go

package info (click to toggle)
golang-github-niklasfasching-go-org 1.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 872 kB
  • sloc: sh: 142; makefile: 42
file content (38 lines) | stat: -rw-r--r-- 914 bytes parent folder | download | duplicates (3)
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
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)))
					}
				}
			}
		})
	}

}