Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

repo_generate_test.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. }