CLI interface to medialist (fossil mirror)
Revision | 02fbb03cffc415f6ce44968d65646761afea14d2 (tree) |
---|---|
Zeit | 2023-03-09 14:50:21 |
Autor | mio <stigma@disr...> |
Commiter | mio |
Fix ml_fetch_item with index 0 "finding" an item when it's not a valid item ID (d247886e46)
FossilOrigin-Name: 8494404e36d073561578a3ca7ddddee6c7bf7aea3d9b707940abf0e08a158611
@@ -747,6 +747,7 @@ MediaListItem ml_fetch_item(MediaList* list, size_t id) | ||
747 | 747 | string line; |
748 | 748 | size_t currentLine = 0; |
749 | 749 | bool found = false; |
750 | + bool pastHeader = false; | |
750 | 751 | |
751 | 752 | while ((line = listFile.readln()) !is null) { |
752 | 753 | if (0 >= line.length) |
@@ -755,6 +756,13 @@ MediaListItem ml_fetch_item(MediaList* list, size_t id) | ||
755 | 756 | if ('#' == line[0]) |
756 | 757 | continue; |
757 | 758 | |
759 | + /* First non-comment line in medialist mTSV file is header */ | |
760 | + if (false == pastHeader) { | |
761 | + pastHeader = true; | |
762 | + currentLine += 1; | |
763 | + continue; | |
764 | + } | |
765 | + | |
758 | 766 | if (id == currentLine) { |
759 | 767 | found = true; |
760 | 768 | break; |
@@ -947,3 +947,40 @@ unittest | ||
947 | 947 | assert(items.length == 1, "Returned item array doesn't contain one item"); |
948 | 948 | assert(items[0].title == "Item 2", "First (idx:1 was idx:2) item title doesn't match."); |
949 | 949 | } |
950 | + | |
951 | + | |
952 | +/* | |
953 | + * Ticket d247886e46 | |
954 | + * | |
955 | + * Since all the commands expect a 1-based index (with medialist | |
956 | + * automatically adjusting) passing an index of 0 should either set the | |
957 | + * error to MLError.itemNotFound or throw an MLException -- depending | |
958 | + * on whether it's the nothrow variant. | |
959 | + * | |
960 | + * Basically, there is an error when reading each line where we don't | |
961 | + * check if we've past the header line. | |
962 | + */ | |
963 | +@(`ml_fetch_item doesn't work with index 0 (d247886e46)`) | |
964 | +unittest | |
965 | +{ | |
966 | + enum listName = __FUNCTION__; | |
967 | + enum fileName = listName ~ ".tsv"; | |
968 | + | |
969 | + MediaList* list = ml_open_list(fileName); | |
970 | + scope(exit) { | |
971 | + ml_send_command(list, MLCommand.delete_, []); | |
972 | + ml_free_list(list); | |
973 | + } | |
974 | + | |
975 | + MediaListItem item; | |
976 | + MLError error; | |
977 | + | |
978 | + item = ml_fetch_item(list, 0, error); | |
979 | + assert(MLError.success != error, | |
980 | + "ml_fetch_item with index 0 (0 items) returned \"successfully\" when expected error."); | |
981 | + | |
982 | + ml_send_command(list, MLCommand.add, ["Item 1"]); | |
983 | + item = ml_fetch_item(list, 0, error); | |
984 | + assert(MLError.success != error, | |
985 | + "ml_fetch_item with index 0 (1 item) returned \"successfully\" when expected error."); | |
986 | +} |