Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.

Commit 8741db7

Browse files
author
Joonas Koivunen
committed
add: port tests for ipfspath
1 parent 6ead780 commit 8741db7

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

http/src/v0/refs/path.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,65 @@ impl ExactSizeIterator for IpfsPath {
326326
self.path.len()
327327
}
328328
}
329+
330+
#[cfg(test)]
331+
mod tests {
332+
use super::IpfsPath;
333+
use std::convert::TryFrom;
334+
335+
// good_paths, good_but_unsupported, bad_paths from https://github.com/ipfs/go-path/blob/master/path_test.go
336+
337+
#[test]
338+
fn good_paths() {
339+
let good = [
340+
("/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n", 0),
341+
("/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a", 1),
342+
(
343+
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f",
344+
6,
345+
),
346+
(
347+
"QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f",
348+
6,
349+
),
350+
("QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n", 0),
351+
];
352+
353+
for &(good, len) in &good {
354+
let p = IpfsPath::try_from(good).unwrap();
355+
assert_eq!(p.len(), len);
356+
}
357+
}
358+
359+
#[test]
360+
#[ignore]
361+
fn good_but_unsupported() {
362+
let _unsupported = [
363+
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
364+
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a",
365+
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f",
366+
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f",
367+
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
368+
];
369+
}
370+
371+
#[test]
372+
fn bad_paths() {
373+
let bad = [
374+
"/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
375+
"/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a",
376+
"/ipfs/foo",
377+
"/ipfs/",
378+
"ipfs/",
379+
"ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
380+
"/ipld/foo",
381+
"/ipld/",
382+
"ipld/",
383+
"ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
384+
];
385+
386+
for &bad in &bad {
387+
IpfsPath::try_from(bad).unwrap_err();
388+
}
389+
}
390+
}

0 commit comments

Comments
 (0)