strings_test.go 761 B

1234567891011121314151617181920212223242526272829303132
  1. package utils
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. // TestStripHTML tests the StripHTML function.
  7. func TestStripHTML(t *testing.T) {
  8. requestedString := `<p><img src="img.png"/>Some text</p>`
  9. expectedResult := `Some text`
  10. result := StripHTML(requestedString)
  11. fmt.Println(result)
  12. if result != expectedResult {
  13. t.Errorf("Expected %s, got %s", expectedResult, result)
  14. }
  15. }
  16. // TestSafeString tests the TestSafeString function.
  17. func TestSafeString(t *testing.T) {
  18. requestedString := `<p><img src="img.png"/> Some text blah blah blah blah blah blahb albh</p>`
  19. expectedResult := `Some te`
  20. result := MakeSafeStringOfLength(requestedString, 10)
  21. fmt.Println(result)
  22. if result != expectedResult {
  23. t.Errorf("Expected %s, got %s", expectedResult, result)
  24. }
  25. }