@@ -36,12 +36,19 @@ void main() {
36
36
assert (streams != null || users != null );
37
37
for (final testCase in testCases) {
38
38
final String urlString = testCase.$1;
39
- final Narrow ? expected = testCase.$2;
40
- test (urlString, () async {
41
- final store = await setupStore (realmUrl: realmUrl, streams: streams, users: users);
42
- final url = store.tryResolveUrl (urlString)! ;
43
- check (parseInternalLink (url, store)).equals (expected);
44
- });
39
+ // This is here to avoid duplicating each test case that contains `#narrow/stream` or `#narrow/channel`
40
+ final urlWithChannelSyntax = urlString.replaceFirst ('#narrow/stream' , '#narrow/channel' );
41
+ final urlWithStreamSyntax = urlString.replaceFirst ('#narrow/channel' , '#narrow/stream' );
42
+ // Using Set instead of List in `{urlWithStreamSyntax, urlWithChannelSyntax}` to avoid any duplicated
43
+ // test urls. Specifically, when url is targeting `pm-with/..` or `dm/..`
44
+ for (final urlString in {urlWithStreamSyntax, urlWithChannelSyntax}) {
45
+ final Narrow ? expected = testCase.$2;
46
+ test (urlString, () async {
47
+ final store = await setupStore (realmUrl: realmUrl, streams: streams, users: users);
48
+ final url = store.tryResolveUrl (urlString)! ;
49
+ check (parseInternalLink (url, store)).equals (expected);
50
+ });
51
+ }
45
52
}
46
53
}
47
54
@@ -52,13 +59,21 @@ void main() {
52
59
final testCases = [
53
60
(true , 'legacy: stream name, no ID' ,
54
61
'#narrow/stream/check' , realmUrl),
62
+ (true , 'legacy: channel name, no ID' ,
63
+ '#narrow/channel/check' , realmUrl),
55
64
(true , 'legacy: stream name, no ID, topic' ,
56
65
'#narrow/stream/check/topic/topic1' , realmUrl),
66
+ (true , 'legacy: channel name, no ID, topic' ,
67
+ '#narrow/channel/check/topic/topic1' , realmUrl),
57
68
58
69
(true , 'with numeric stream ID' ,
59
70
'#narrow/stream/123-check' , realmUrl),
71
+ (true , 'with numeric channel ID' ,
72
+ '#narrow/channel/123-check' , realmUrl),
60
73
(true , 'with numeric stream ID and topic' ,
61
74
'#narrow/stream/123-a/topic/topic1' , realmUrl),
75
+ (true , 'with numeric channel ID and topic' ,
76
+ '#narrow/channel/123-a/topic/topic1' , realmUrl),
62
77
63
78
(true , 'with numeric pm user IDs (new operator)' ,
64
79
'#narrow/dm/123-mark' , realmUrl),
@@ -69,20 +84,33 @@ void main() {
69
84
'#nope' , realmUrl),
70
85
(false , 'wrong path' ,
71
86
'user_uploads/#narrow/stream/check' , realmUrl),
87
+ (false , 'wrong path with channel syntax' ,
88
+ 'user_uploads/#narrow/channel/check' , realmUrl),
72
89
(false , 'wrong domain' ,
73
90
'https://another.com/#narrow/stream/check' , realmUrl),
91
+ (false , 'wrong domain with channel syntax' ,
92
+ 'https://another.com/#narrow/channel/check' , realmUrl),
74
93
75
94
(false , '#narrowly' ,
76
95
'#narrowly/stream/check' , realmUrl),
96
+ (false , '#narrowly with channel syntax' ,
97
+ '#narrowly/channel/check' , realmUrl),
77
98
78
99
(false , 'double slash' ,
79
100
'https://example.com//#narrow/stream/check' , realmUrl),
101
+ (false , 'double slash with channel syntax' ,
102
+ 'https://example.com//#narrow/channel/check' , realmUrl),
80
103
(false , 'triple slash' ,
81
104
'https://example.com///#narrow/stream/check' , realmUrl),
105
+ (false , 'triple slash with channel syntax' ,
106
+ 'https://example.com///#narrow/channel/check' , realmUrl),
82
107
83
108
(true , 'with port' ,
84
109
'https://example.com:444/#narrow/stream/check' ,
85
110
Uri .parse ('https://example.com:444/' )),
111
+ (true , 'with port with channel syntax' ,
112
+ 'https://example.com:444/#narrow/channel/check' ,
113
+ Uri .parse ('https://example.com:444/' )),
86
114
87
115
// Dart's [Uri] currently lacks IDNA or Punycode support:
88
116
// https://github.com/dart-lang/sdk/issues/26284
@@ -95,6 +123,9 @@ void main() {
95
123
(true , 'punycodable host' ,
96
124
'https://example.भारत/#narrow/stream/check' ,
97
125
Uri .parse ('https://example.भारत/' )),
126
+ (true , 'punycodable host with channel syntax' ,
127
+ 'https://example.भारत/#narrow/channel/check' ,
128
+ Uri .parse ('https://example.भारत/' )),
98
129
99
130
// (true, 'same domain, IDNA-mappable',
100
131
// 'https://ℯⅩªm🄿ₗℰ.ℭᴼⓂ/#narrow/stream/check',
@@ -103,6 +134,9 @@ void main() {
103
134
(true , 'ipv4 address' ,
104
135
'http://192.168.0.1/#narrow/stream/check' ,
105
136
Uri .parse ('http://192.168.0.1/' )),
137
+ (true , 'ipv4 address with channel syntax' ,
138
+ 'http://192.168.0.1/#narrow/channel/check' ,
139
+ Uri .parse ('http://192.168.0.1/' )),
106
140
107
141
// (true, 'same IPv4 address, IDNA-mappable',
108
142
// 'http://1𝟗𝟚。①⁶🯸.₀。𝟭/#narrow/stream/check',
@@ -119,12 +153,21 @@ void main() {
119
153
(false , 'wrong domain, realm-like path, narrow-like fragment' ,
120
154
'https://web.archive.org/web/*/${realmUrl .resolve ('#narrow/stream/check' )}' ,
121
155
realmUrl),
156
+ (false , 'wrong domain, realm-like path, narrow-like fragment with channel syntax' ,
157
+ 'https://web.archive.org/web/*/${realmUrl .resolve ('#narrow/channel/check' )}' ,
158
+ realmUrl),
122
159
(false , 'odd scheme, wrong domain, realm-like path, narrow-like fragment' ,
123
160
'ftp://web.archive.org/web/*/${realmUrl .resolve ('#narrow/stream/check' )}' ,
124
161
realmUrl),
162
+ (false , 'odd scheme, wrong domain, realm-like path, narrow-like fragment with channel syntax' ,
163
+ 'ftp://web.archive.org/web/*/${realmUrl .resolve ('#narrow/channel/check' )}' ,
164
+ realmUrl),
125
165
(false , 'same domain, realm-like path, narrow-like fragment' ,
126
166
'web/*/${realmUrl .resolve ('#narrow/stream/check' )}' ,
127
167
realmUrl),
168
+ (false , 'same domain, realm-like path, narrow-like fragment with channel syntax' ,
169
+ 'web/*/${realmUrl .resolve ('#narrow/channel/check' )}' ,
170
+ realmUrl),
128
171
];
129
172
for (final testCase in testCases) {
130
173
final bool expected = testCase.$1;
0 commit comments