Skip to content

Commit

Permalink
test: update unit test
Browse files Browse the repository at this point in the history
for: raw, blob, tree, and edit
  • Loading branch information
ggdaltoso committed Aug 25, 2022
1 parent c256dfd commit 7ee8abd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ function gitUrlParse(url) {
const commitIndex = splits.indexOf("commit", 2);
const srcIndex = splits.indexOf("src", 2);
const rawIndex = splits.indexOf("raw", 2);
const editIndex = splits.indexOf("edit", 2);
nameIndex = dashIndex > 0 ? dashIndex - 1
: blobIndex > 0 ? blobIndex - 1
: treeIndex > 0 ? treeIndex - 1
: commitIndex > 0 ? commitIndex - 1
: srcIndex > 0 ? srcIndex - 1
: rawIndex > 0 ? rawIndex - 1
: editIndex > 0 ? editIndex - 1
: nameIndex;

urlInfo.owner = splits.slice(0, nameIndex).join('/');
Expand All @@ -172,8 +174,9 @@ function gitUrlParse(url) {
urlInfo.filepathtype = "";
urlInfo.filepath = "";
const offsetNameIndex = splits.length > nameIndex && splits[nameIndex+1] === "-" ? nameIndex + 1 : nameIndex;
if ((splits.length > offsetNameIndex + 2) && (["raw","src","blob", "tree"].indexOf(splits[offsetNameIndex + 1]) >= 0)) {
urlInfo.filepathtype = splits[offsetNameIndex + 1];

if ((splits.length > offsetNameIndex + 2) && (["raw", "src", "blob", "tree", "edit"].indexOf(splits[offsetNameIndex + 1]) >= 0)) {
urlInfo.filepathtype = splits[offsetNameIndex + 1];
urlInfo.ref = splits[offsetNameIndex + 2];
if (splits.length > offsetNameIndex + 3) {
urlInfo.filepath = splits.slice(offsetNameIndex + 3).join('/');
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ tester.describe("parse urls", test => {
}

// execute for raw, src, blob, and tree
['blob', 'raw', 'blob', 'tree', 'edit'].forEach(testForFilepathtypeURL);
['raw', 'blob', 'tree', 'edit'].forEach(testForFilepathtypeURL);
});

// shorthand urls
Expand Down

0 comments on commit 7ee8abd

Please sign in to comment.