You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.1 KiB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. var giteaTemplate = []byte(`
  10. # Header
  11. # All .go files
  12. **.go
  13. # All text files in /text/
  14. text/*.txt
  15. # All files in modules folders
  16. **/modules/*
  17. `)
  18. func TestGiteaTemplate(t *testing.T) {
  19. gt := GiteaTemplate{Content: giteaTemplate}
  20. assert.Equal(t, len(gt.Globs()), 3)
  21. tt := []struct {
  22. Path string
  23. Match bool
  24. }{
  25. {Path: "main.go", Match: true},
  26. {Path: "a/b/c/d/e.go", Match: true},
  27. {Path: "main.txt", Match: false},
  28. {Path: "a/b.txt", Match: false},
  29. {Path: "text/a.txt", Match: true},
  30. {Path: "text/b.txt", Match: true},
  31. {Path: "text/c.json", Match: false},
  32. {Path: "a/b/c/modules/README.md", Match: true},
  33. {Path: "a/b/c/modules/d/README.md", Match: false},
  34. }
  35. for _, tc := range tt {
  36. t.Run(tc.Path, func(t *testing.T) {
  37. match := false
  38. for _, g := range gt.Globs() {
  39. if g.Match(tc.Path) {
  40. match = true
  41. break
  42. }
  43. }
  44. assert.Equal(t, tc.Match, match)
  45. })
  46. }
  47. }