github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/luatesting/linechecker_test.go (about)

     1  package luatesting
     2  
     3  import "testing"
     4  
     5  func TestExtractLineCheckers(t *testing.T) {
     6  	src := `
     7  Hello
     8  --> =abc def
     9  
    10  --> ~ab
    11  sdfa
    12  asdf
    13  --> ~^ab.*yz$
    14  `
    15  	checkers := ExtractLineCheckers([]byte(src))
    16  	if len(checkers) != 3 {
    17  		t.Fatal("expected 3 checkers")
    18  	}
    19  
    20  	checks := []struct {
    21  		i       int
    22  		line    string
    23  		success bool
    24  	}{
    25  		{0, "abc", false},
    26  		{0, "abc def", true},
    27  		{0, "abc def\n", false},
    28  		{1, "abcd", true},
    29  		{1, "xyzab", true},
    30  		{1, "axyb", false},
    31  		{2, "abyz", true},
    32  		{2, "xabyz", false},
    33  		{2, "ab....yz", true},
    34  		{2, "abyz\n", false},
    35  	}
    36  	for i, check := range checks {
    37  		err := checkers[check.i].CheckLine([]byte(check.line))
    38  		if (err != nil && check.success) || (err == nil && !check.success) {
    39  			t.Fatalf("Check #%d failed", i+1)
    40  		}
    41  	}
    42  }