1 package com.atlassian.gzipfilter.selector;
2
3 import junit.framework.TestCase;
4
5 public class TestPatternMatcher extends TestCase
6 {
7 PatternMatcher p = new PatternMatcher();
8
9 public void testSimple()
10 {
11 assertTrue(p.matches("text/html", "text/html"));
12 assertTrue(p.matches("text/plain", "text/plain"));
13
14 assertFalse(p.matches("text/plain", "text/html"));
15 assertFalse(p.matches("text/plain", ""));
16 assertFalse(p.matches("text/plain", ",,,,"));
17 }
18
19 public void testMultipleInputs()
20 {
21 assertTrue(p.matches("text/html", "text/plain,text/html"));
22 assertTrue(p.matches("text/plain", "text/plain,text/html"));
23 assertTrue(p.matches("text/plain", "text/plain,text/html,application/x-javascript"));
24
25 assertFalse(p.matches("application/msword", "text/plain,text/html,application/x-javascript"));
26 assertFalse(p.matches("text/javascript", "text/plain,text/html,application/x-javascript"));
27 }
28
29 public void testRegularExpressions()
30 {
31 assertTrue(p.matches("text/html", "text/.*"));
32 assertTrue(p.matches("text/html", "application/x-javascript,text/.*"));
33 assertTrue(p.matches("text/plain", "application/x-javascript,text/.*"));
34 assertTrue(p.matches("application/javascript", "application/.?.?javascript,text/.*"));
35 assertTrue(p.matches("application/x-javascript", "application/.?.?javascript,text/.*"));
36
37 assertFalse(p.matches("application/msword", "application/??javascript,text/.*"));
38 assertFalse(p.matches("application/msword", "application/??javascript,text/.*"));
39 }
40
41 static final String TYPES_TO_GZIP = "text/.*,application/.?.?javascript,application/xml";
42
43 public void testForRealWorldUsage()
44 {
45
46
47 assertTrue(p.matches("text/html", TYPES_TO_GZIP));
48 assertTrue(p.matches("text/plain", TYPES_TO_GZIP));
49 assertTrue(p.matches("text/css", TYPES_TO_GZIP));
50 assertTrue(p.matches("text/javascript", TYPES_TO_GZIP));
51 assertTrue(p.matches("application/javascript", TYPES_TO_GZIP));
52 assertTrue(p.matches("application/x-javascript", TYPES_TO_GZIP));
53 assertTrue(p.matches("application/xml", TYPES_TO_GZIP));
54
55 assertFalse(p.matches("application/msword", TYPES_TO_GZIP));
56 assertFalse(p.matches("application/octet-stream", TYPES_TO_GZIP));
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
83
84
85
86
87
88
89
90
91
92 }