github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/preprocessor/parse_include_list_test.go (about)

     1  package preprocessor
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestParseIncludeList(t *testing.T) {
     9  	testCases := []struct {
    10  		inputLine string
    11  		list      []string
    12  	}{
    13  		{
    14  			inputLine: ` exit.o: exit.c tests.h `,
    15  			list:      []string{"exit.c", "tests.h"},
    16  		},
    17  		{
    18  
    19  			inputLine: ` exit.o: exit.c /usr/include/stdlib.h /usr/include/features.h \
    20    /usr/include/stdc-predef.h /usr/include/x86_64-linux-gnu/sys/cdefs.h \
    21    /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
    22    /usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include/stddef.h
    23    `,
    24  			list: []string{"exit.c", "/usr/include/stdlib.h", "/usr/include/features.h",
    25  				"/usr/include/stdc-predef.h", "/usr/include/x86_64-linux-gnu/sys/cdefs.h",
    26  				"/usr/include/x86_64-linux-gnu/gnu/stubs-64.h",
    27  				"/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include/stddef.h",
    28  			},
    29  		},
    30  		{
    31  			inputLine: ` main.o: \
    32    /home/Глава\ 6/6\ .2/main.c  /home/e\ 1.c`,
    33  			list: []string{"/home/Глава 6/6 .2/main.c", "/home/e 1.c"},
    34  		},
    35  		{
    36  			inputLine: ` main.o: \
    37    /home/lepricon/go/src/github.com/Konstantin8105/c4go/build/git-source/VasielBook/Глава\ 6/6.2/main.c`,
    38  			list: []string{"/home/lepricon/go/src/github.com/Konstantin8105/c4go/build/git-source/VasielBook/Глава 6/6.2/main.c"},
    39  		},
    40  		{
    41  			inputLine: ` shell.o: /tmp/SQLITE/sqlite-amalgamation-3220000/shell.c \
    42    /tmp/SQLITE/sqlite-amalgamation-3220000/sqlite3.h
    43  sqlite3.o: /tmp/SQLITE/sqlite-amalgamation-3220000/sqlite3.c /tmp/1.h \
    44   /tmp/2.h`,
    45  			list: []string{
    46  				"/tmp/SQLITE/sqlite-amalgamation-3220000/shell.c",
    47  				"/tmp/SQLITE/sqlite-amalgamation-3220000/sqlite3.h",
    48  				"/tmp/SQLITE/sqlite-amalgamation-3220000/sqlite3.c",
    49  				"/tmp/1.h",
    50  				"/tmp/2.h",
    51  			},
    52  		},
    53  	}
    54  	for i, tc := range testCases {
    55  		t.Run(fmt.Sprintf("Test:%d", i), func(t *testing.T) {
    56  			actual, err := parseIncludeList(tc.inputLine)
    57  			if err != nil {
    58  				t.Fatal(err)
    59  			}
    60  			if len(actual) != len(tc.list) {
    61  				t.Fatalf("Cannot parse line : %s.\nActual result : %#v.\nExpected: %#v", tc.inputLine, actual, tc.list)
    62  			}
    63  			for i := range actual {
    64  				if actual[i] != tc.list[i] {
    65  					t.Fatalf("Cannot parse 'include' in line : %s.\nActual result : %#v.\nExpected: %#v", tc.inputLine, actual[i], tc.list[i])
    66  				}
    67  			}
    68  		})
    69  	}
    70  }
    71  
    72  func TestIncludeListFail(t *testing.T) {
    73  	_, err := parseIncludeList("without index")
    74  	if err == nil {
    75  		t.Fatalf("Cannot error withou :")
    76  	}
    77  }