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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
use super::*;
#[test]
fn bug_query() {
assert_eq!(
dispatch(&handlers(), &"b/42".into()),
Some("https://b.tvl.fyi/42".to_string())
);
assert_eq!(
dispatch(&handlers(), &"something only mentioning b/42".into()),
None,
);
assert_eq!(dispatch(&handlers(), &"b/invalid".into()), None,);
}
#[test]
fn cl_query() {
assert_eq!(
dispatch(&handlers(), &"cl/42".into()),
Some("https://cl.tvl.fyi/42".to_string())
);
assert_eq!(
dispatch(&handlers(), &"something only mentioning cl/42".into()),
None,
);
assert_eq!(dispatch(&handlers(), &"cl/invalid".into()), None,);
}
#[test]
fn depot_path_cgit_query() {
assert_eq!(
dispatch(&handlers(), &"//web/atward/default.nix".into()),
Some("https://code.tvl.fyi/tree/web/atward/default.nix".to_string()),
);
assert_eq!(
dispatch(&handlers(), &"//nix/readTree/README.md".into()),
Some("https://code.tvl.fyi/about/nix/readTree/README.md".to_string()),
);
assert_eq!(dispatch(&handlers(), &"/not/a/depot/path".into()), None);
}
#[test]
fn depot_root_cgit_query() {
assert_eq!(
dispatch(
&handlers(),
&Query {
query: "//".to_string(),
}
),
Some("https://code.tvl.fyi/tree/".to_string()),
);
}
#[test]
fn plain_host_queries() {
assert_eq!(
dispatch(&handlers(), &"cs".into()),
Some("https://cs.tvl.fyi/".to_string()),
);
assert_eq!(
dispatch(&handlers(), &"cl".into()),
Some("https://cl.tvl.fyi/".to_string()),
);
assert_eq!(
dispatch(&handlers(), &"b".into()),
Some("https://b.tvl.fyi/".to_string()),
);
assert_eq!(
dispatch(&handlers(), &"todo".into()),
Some("https://todo.tvl.fyi/".to_string()),
);
}
#[test]
fn request_to_query() {
assert_eq!(
Query::from_request(&Request::fake_http("GET", "/?q=b%2F42", vec![], vec![]))
.expect("request should parse to a query"),
Query {
query: "b/42".to_string(),
},
);
assert_eq!(
Query::from_request(&Request::fake_http("GET", "/", vec![], vec![])),
None
);
}
#[test]
fn depot_revision_query() {
assert_eq!(
dispatch(&handlers(), &"r/3002".into()),
Some("https://code.tvl.fyi/commit/?id=refs/r/3002".to_string())
);
assert_eq!(
dispatch(&handlers(), &"something only mentioning r/3002".into()),
None,
);
assert_eq!(dispatch(&handlers(), &"r/invalid".into()), None,);
}
|