|
@@ -12,6 +12,7 @@ import (
|
|
|
|
|
|
const testDir = "testfiles"
|
|
|
const negativeTestDir = "testfiles-negative"
|
|
|
+const testFileLineInfo = "testfile-line/Dockerfile"
|
|
|
|
|
|
func getDirs(t *testing.T, dir string) []string {
|
|
|
f, err := os.Open(dir)
|
|
@@ -117,3 +118,37 @@ func TestParseWords(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestLineInformation(t *testing.T) {
|
|
|
+ df, err := os.Open(testFileLineInfo)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("Dockerfile missing for %s: %v", testFileLineInfo, err)
|
|
|
+ }
|
|
|
+ defer df.Close()
|
|
|
+
|
|
|
+ ast, err := Parse(df)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("Error parsing dockerfile %s: %v", testFileLineInfo, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if ast.StartLine != 4 || ast.EndLine != 30 {
|
|
|
+ fmt.Fprintf(os.Stderr, "Wrong root line information: expected(%d-%d), actual(%d-%d)\n", 4, 30, ast.StartLine, ast.EndLine)
|
|
|
+ t.Fatalf("Root line information doesn't match result.")
|
|
|
+ }
|
|
|
+ if len(ast.Children) != 3 {
|
|
|
+ fmt.Fprintf(os.Stderr, "Wrong number of child: expected(%d), actual(%d)\n", 3, len(ast.Children))
|
|
|
+ t.Fatalf("Root line information doesn't match result.")
|
|
|
+ }
|
|
|
+ expected := [][]int{
|
|
|
+ {4, 4},
|
|
|
+ {10, 11},
|
|
|
+ {16, 30},
|
|
|
+ }
|
|
|
+ for i, child := range ast.Children {
|
|
|
+ if child.StartLine != expected[i][0] || child.EndLine != expected[i][1] {
|
|
|
+ fmt.Fprintf(os.Stderr, "Wrong line information for child %d: expected(%d-%d), actual(%d-%d)\n",
|
|
|
+ i, expected[i][0], expected[i][1], child.StartLine, child.EndLine)
|
|
|
+ t.Fatalf("Root line information doesn't match result.")
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|