repogen/internal/testutils/multilines_test.go

73 lines
1.9 KiB
Go
Raw Normal View History

2021-01-23 13:03:16 +00:00
package testutils_test
import (
"testing"
2023-05-24 11:01:50 +00:00
"git.kmsign.com/royalcat/repogen/internal/testutils"
2021-01-23 13:03:16 +00:00
)
func TestExpectMultiLineString(t *testing.T) {
t.Run("same string should return nil", func(t *testing.T) {
text := ` Hello world
this is a test text `
err := testutils.ExpectMultiLineString(text, text)
if err != nil {
t.Errorf("Expected = <nil>\nReceived = %s", err.Error())
}
})
t.Run("different string with same number of lines", func(t *testing.T) {
expectedText := ` Hello world
this is an expected text
how are you?`
actualText := ` Hello world
this is a real text
How are you?`
err := testutils.ExpectMultiLineString(expectedText, actualText)
expectedError := "at line 2\nexpected: this is an expected text\nreceived: this is a real text"
2021-01-23 13:03:16 +00:00
if err == nil || err.Error() != expectedError {
t.Errorf("expected = %s\nreceived = %s", expectedError, err.Error())
2021-01-23 13:03:16 +00:00
}
})
t.Run("expected text longer than actual text", func(t *testing.T) {
expectedText := ` Hello world
this is an expected text
how are you?
I'm fine...
Thank you...`
actualText := ` Hello world
this is an expected text
how are you?`
err := testutils.ExpectMultiLineString(expectedText, actualText)
expectedError := "missing lines:\nI'm fine...\nThank you..."
2021-01-23 13:03:16 +00:00
if err == nil || err.Error() != expectedError {
t.Errorf("expected = %s\nreceived = %s", expectedError, err.Error())
2021-01-23 13:03:16 +00:00
}
})
t.Run("actual text longer than expected text", func(t *testing.T) {
expectedText := ` Hello world
this is an expected text
how are you?`
actualText := ` Hello world
this is an expected text
how are you?
I'm fine...
Thank you...`
err := testutils.ExpectMultiLineString(expectedText, actualText)
expectedError := "unexpected lines:\nI'm fine...\nThank you..."
2021-01-23 13:03:16 +00:00
if err == nil || err.Error() != expectedError {
t.Errorf("expected = %s\nreceived = %s", expectedError, err.Error())
2021-01-23 13:03:16 +00:00
}
})
}