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

Commit a99f274

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

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

http/src/v0/refs/path.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,59 @@ 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+
("/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f", 6),
343+
("QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f", 6),
344+
("QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n", 0),
345+
];
346+
347+
for &(good, len) in &good {
348+
let p = IpfsPath::try_from(good).unwrap();
349+
assert_eq!(p.len(), len);
350+
}
351+
}
352+
353+
#[test]
354+
#[ignore]
355+
fn good_but_unsupported() {
356+
let _unsupported = [
357+
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
358+
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a",
359+
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f",
360+
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f",
361+
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
362+
];
363+
}
364+
365+
#[test]
366+
fn bad_paths() {
367+
let bad = [
368+
"/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
369+
"/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a",
370+
"/ipfs/foo",
371+
"/ipfs/",
372+
"ipfs/",
373+
"ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
374+
"/ipld/foo",
375+
"/ipld/",
376+
"ipld/",
377+
"ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
378+
];
379+
380+
for &bad in &bad {
381+
IpfsPath::try_from(bad).unwrap_err();
382+
}
383+
}
384+
}

0 commit comments

Comments
 (0)