parse_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. Copyright 2016 The Rook Authors. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package sys
  14. import (
  15. "testing"
  16. "github.com/stretchr/testify/assert"
  17. )
  18. func TestGrep(t *testing.T) {
  19. // single line
  20. testGrep(t, "", "", "")
  21. testGrep(t, "foo", "", "")
  22. testGrep(t, "food", "foo", "food")
  23. testGrep(t, "have you ever seen such a sight?", "^have", "have you ever seen such a sight?")
  24. testGrep(t, "have you ever seen such a sight?", "you", "have you ever seen such a sight?")
  25. testGrep(t, "have you ever seen such a sight?", "^you", "")
  26. // multi-line
  27. input := `This is a test
  28. of the emergency broadcast system.
  29. If the test fails,
  30. you need to fix it! `
  31. testGrep(t, input, "test", "This is a test")
  32. testGrep(t, input, "broadcast", " of the emergency broadcast system.")
  33. testGrep(t, input, "fix", " you need to fix it! ")
  34. }
  35. func testGrep(t *testing.T, input, searchFor, expected string) {
  36. output := Grep(input, searchFor)
  37. assert.Equal(t, expected, output)
  38. }