github.com/Cloud-Foundations/Dominator@v0.3.4/lib/uncommenter/impl_test.go (about)

     1  package uncommenter
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  	"testing"
     7  )
     8  
     9  var (
    10  	badlyCommentedText = []byte(`First line
    11  ,# A comment
    12  Second line
    13  // Another comment
    14  Third line
    15  ! More commentary
    16  Final statement.
    17  `)
    18  
    19  	badlyCommentedTextExpected = []byte(`First line
    20  ,# A comment
    21  Second line
    22  Third line
    23  Final statement.
    24  `)
    25  
    26  	properlyCommentedText = []byte(`First line
    27  # A comment
    28  Second line
    29  	// Another comment
    30  Third line
    31       ! More commentary
    32  Final statement.
    33  `)
    34  
    35  	uncommentedText = []byte(`First line
    36  Second line
    37  Third line
    38  Final statement.
    39  `)
    40  )
    41  
    42  func TestBad(t *testing.T) {
    43  	reader := New(bytes.NewBuffer(badlyCommentedText), CommentTypeAll)
    44  	result, err := io.ReadAll(reader)
    45  	if err != nil {
    46  		t.Fatal(err)
    47  	}
    48  	if bytes.Equal(result, badlyCommentedTextExpected) {
    49  		return
    50  	}
    51  	t.Errorf("Expected: %s, got: %s",
    52  		string(badlyCommentedTextExpected), string(result))
    53  }
    54  
    55  func TestGood(t *testing.T) {
    56  	reader := New(bytes.NewBuffer(properlyCommentedText), CommentTypeAll)
    57  	result, err := io.ReadAll(reader)
    58  	if err != nil {
    59  		t.Fatal(err)
    60  	}
    61  	if bytes.Equal(result, uncommentedText) {
    62  		return
    63  	}
    64  	t.Errorf("Expected: %s, got: %s",
    65  		string(uncommentedText), string(result))
    66  }