File size: 1,908 Bytes
6a7089a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package bridge

import (
	"testing"
)

func TestAdBlockPatterns(t *testing.T) {
	// Verify we have a good number of patterns
	if len(AdBlockPatterns) < 50 {
		t.Errorf("expected at least 50 ad block patterns, got %d", len(AdBlockPatterns))
	}

	// Check for some essential patterns
	essentialPatterns := []string{
		"*google-analytics.com/*",
		"*doubleclick.net/*",
		"*facebook.com/tr/*",
		"*segment.io/*",
	}

	patternMap := make(map[string]bool)
	for _, p := range AdBlockPatterns {
		patternMap[p] = true
	}

	for _, essential := range essentialPatterns {
		if !patternMap[essential] {
			t.Errorf("missing essential pattern: %s", essential)
		}
	}
}

func TestCombineBlockPatterns(t *testing.T) {
	list1 := []string{"*.jpg", "*.png", "*.gif"}
	list2 := []string{"*.mp4", "*.png", "*.webm"} // .png is duplicate
	list3 := []string{"*.pdf", "*.doc"}

	combined := CombineBlockPatterns(list1, list2, list3)

	// Should have 7 unique patterns
	if len(combined) != 7 {
		t.Errorf("expected 7 unique patterns, got %d", len(combined))
	}

	// Verify all patterns are present
	expected := map[string]bool{
		"*.jpg":  true,
		"*.png":  true,
		"*.gif":  true,
		"*.mp4":  true,
		"*.webm": true,
		"*.pdf":  true,
		"*.doc":  true,
	}

	for _, pattern := range combined {
		if !expected[pattern] {
			t.Errorf("unexpected pattern: %s", pattern)
		}
		delete(expected, pattern)
	}

	if len(expected) > 0 {
		t.Errorf("missing patterns: %v", expected)
	}
}

func TestCombineBlockPatterns_Empty(t *testing.T) {
	// Test with empty lists
	combined := CombineBlockPatterns([]string{}, []string{})
	if len(combined) != 0 {
		t.Errorf("expected empty result for empty inputs, got %d patterns", len(combined))
	}

	// Test with one empty list
	list := []string{"*.jpg", "*.png"}
	combined = CombineBlockPatterns(list, []string{})
	if len(combined) != 2 {
		t.Errorf("expected 2 patterns, got %d", len(combined))
	}
}