plugin_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // This file is subject to a 1-clause BSD license.
  2. // Its contents can be found in the enclosed LICENSE file.
  3. package url
  4. import (
  5. "os"
  6. "testing"
  7. )
  8. func TestMain(m *testing.M) {
  9. ret := m.Run()
  10. os.Exit(ret)
  11. }
  12. func TestYoutube(t *testing.T) {
  13. testYoutube(t, "boops", "")
  14. testYoutube(t, "youtube.com", "")
  15. testYoutube(t, "http://youtube.com", "")
  16. testYoutube(t, "https://www.youtube.com", "")
  17. testYoutube(t, "https://www.not-youtube.com", "")
  18. testYoutube(t, "https://www.not-youtube.com?v=boops", "")
  19. testYoutube(t, "https://youtube.com?v=HKNXXpqareI", "HKNXXpqareI")
  20. testYoutube(t, "https://www.youtube.com?v=HKNXXpqareI", "HKNXXpqareI")
  21. testYoutube(t, "http://youtube.com?v=HKNXXpqareI", "HKNXXpqareI")
  22. testYoutube(t, "http://www.youtube.com?v=HKNXXpqareI", "HKNXXpqareI")
  23. testYoutube(t, "https://www.youtube.com/watch?v=gc1VA_W3M-Y&index=2&list=PLJwv6sN_mnF0QsOTcKlFDeyzwXMM0MWru", "gc1VA_W3M-Y")
  24. }
  25. func testYoutube(t *testing.T, in, want string) {
  26. have := isYoutube(in)
  27. if want != have {
  28. t.Fatalf("id mismatch for %q;\nwant: %q\nhave: %q",
  29. in, want, have)
  30. }
  31. }