-
-
Notifications
You must be signed in to change notification settings - Fork 643
/
toml.go
51 lines (44 loc) · 1.22 KB
/
toml.go
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
package gen
import (
"bufio"
"fmt"
"os"
"strings"
)
// getExcludedTestCases reads the file at tomlFilePath and manually parses the toml
// as no third party libraries are currently available (https://github.com/exercism/go/issues/2055).
func getExcludedTestCases(tomlFilePath string) (map[string]struct{}, error) {
if _, err := os.Stat(tomlFilePath); err != nil {
return nil, fmt.Errorf("tests.toml can't be found (%q)", err)
}
file, err := os.Open(tomlFilePath)
if err != nil {
return nil, fmt.Errorf("failed to open %s: %w", tomlFilePath, err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
excludedList := map[string]struct{}{}
var currentCaseUUID string
for scanner.Scan() {
line := scanner.Text()
line = strings.TrimSpace(line)
switch {
case line == "" || strings.HasPrefix(line, "#"):
continue
case strings.HasPrefix(line, "["):
currentCaseUUID = strings.Trim(line, "[]")
case isExcluded(line):
excludedList[currentCaseUUID] = struct{}{}
}
}
return excludedList, nil
}
func isExcluded(line string) bool {
parts := strings.Split(line, "=")
key := strings.TrimSpace(parts[0])
value := strings.TrimSpace(parts[1])
if key == "include" {
return value == "false"
}
return false
}