|
| 1 | +import pytest |
| 2 | +from file_utils import get_file_name, github_file_url, github_folder_url |
| 3 | + |
| 4 | +def test_get_file_name_with_delimiter(): |
| 5 | + assert get_file_name("example.txt") == "example.md" |
| 6 | + |
| 7 | +def test_get_file_name_without_delimiter(): |
| 8 | + assert get_file_name("example") == "example.md" |
| 9 | + |
| 10 | +def test_get_file_name_custom_delimiter(): |
| 11 | + assert get_file_name("example-text", delimiter="-") == "example.md" |
| 12 | + |
| 13 | +def test_get_file_name_no_delimiter_custom_extension(): |
| 14 | + assert get_file_name("example", extension=".txt") == "example.txt" |
| 15 | + |
| 16 | +def test_get_file_name_with_delimiter_custom_extension(): |
| 17 | + assert get_file_name("example.txt", extension=".txt") == "example.txt" |
| 18 | + |
| 19 | +def test_get_file_name_with_multiple_delimiters(): |
| 20 | + assert get_file_name("my.example.txt") == "my.example.md" |
| 21 | + |
| 22 | +def test_get_file_name_with_no_delimiter_and_no_extension(): |
| 23 | + assert get_file_name("example", extension="") == "example" |
| 24 | + |
| 25 | +def test_get_file_name_with_delimiter_and_no_extension(): |
| 26 | + assert get_file_name("example.txt", extension="") == "example" |
| 27 | + |
| 28 | +def test_get_file_name_empty_input(): |
| 29 | + assert get_file_name("") == ".md" |
| 30 | + |
| 31 | +def test_get_file_name_delimiter_not_in_input(): |
| 32 | + assert get_file_name("example", delimiter="/") == "example.md" |
| 33 | + |
| 34 | +def test_get_file_name_delimiter_at_end(): |
| 35 | + assert get_file_name("example.", delimiter=".") == "example.md" |
| 36 | + |
| 37 | +def test_get_file_name_delimiter_at_start(): |
| 38 | + assert get_file_name(".example", delimiter=".") == ".md" |
| 39 | + |
| 40 | +def test_get_file_name_delimiter_multiple_occurrences(): |
| 41 | + assert get_file_name("my.file.name.txt") == "my.file.name.md" |
| 42 | + |
| 43 | +def test_github_file_url_link_hosted_true(): |
| 44 | + github_root = "https://github.com/user/repo" |
| 45 | + input_root = "/home/user/project" |
| 46 | + file_path = "/home/user/project/docs/file.md" |
| 47 | + link_hosted = True |
| 48 | + expected_url = f"{github_root}/{file_path[len(input_root)-1:]}" |
| 49 | + assert github_file_url(github_root, input_root, file_path, link_hosted) == expected_url |
| 50 | + |
| 51 | +def test_github_file_url_link_hosted_false(): |
| 52 | + github_root = "https://github.com/user/repo" |
| 53 | + input_root = "/home/user/project" |
| 54 | + file_path = "/home/user/project/docs/file.md" |
| 55 | + link_hosted = False |
| 56 | + expected_url = f"{github_root}/blob/master/{file_path[len(input_root)-1:]}" |
| 57 | + assert github_file_url(github_root, input_root, file_path, link_hosted) == expected_url |
| 58 | + |
| 59 | +def test_github_file_url_empty_input_root(): |
| 60 | + github_root = "https://github.com/user/repo" |
| 61 | + input_root = "" |
| 62 | + file_path = "/docs/file.md" |
| 63 | + link_hosted = False |
| 64 | + expected_url = f"{github_root}/blob/master/{file_path[-1:]}" |
| 65 | + assert github_file_url(github_root, input_root, file_path, link_hosted) == expected_url |
| 66 | + |
| 67 | +def test_github_file_url_empty_file_path(): |
| 68 | + github_root = "https://github.com/user/repo" |
| 69 | + input_root = "/home/user/project" |
| 70 | + file_path = "" |
| 71 | + link_hosted = False |
| 72 | + expected_url = f"{github_root}/blob/master/{file_path[len(input_root)-1:]}" |
| 73 | + assert github_file_url(github_root, input_root, file_path, link_hosted) == expected_url |
| 74 | + |
| 75 | +def test_github_folder_url_link_hosted_true(): |
| 76 | + github_root = "https://github.com/user/repo" |
| 77 | + input_root = "/home/user/project" |
| 78 | + folder_path = "/home/user/project/docs/" |
| 79 | + link_hosted = True |
| 80 | + expected_url = f"{github_root}/{folder_path[len(input_root)-1:]}" |
| 81 | + assert github_folder_url(github_root, input_root, folder_path, link_hosted) == expected_url |
| 82 | + |
| 83 | +def test_github_folder_url_link_hosted_false(): |
| 84 | + github_root = "https://github.com/user/repo" |
| 85 | + input_root = "/home/user/project" |
| 86 | + folder_path = "/home/user/project/docs/" |
| 87 | + link_hosted = False |
| 88 | + expected_url = f"{github_root}/tree/master/{folder_path[len(input_root)-1:]}" |
| 89 | + assert github_folder_url(github_root, input_root, folder_path, link_hosted) == expected_url |
| 90 | + |
| 91 | +def test_github_folder_url_empty_input_root(): |
| 92 | + github_root = "https://github.com/user/repo" |
| 93 | + input_root = "" |
| 94 | + folder_path = "/docs/" |
| 95 | + link_hosted = False |
| 96 | + expected_url = f"{github_root}/tree/master/{folder_path[-1:]}" |
| 97 | + assert github_folder_url(github_root, input_root, folder_path, link_hosted) == expected_url |
| 98 | + |
| 99 | +def test_github_folder_url_empty_folder_path(): |
| 100 | + github_root = "https://github.com/user/repo" |
| 101 | + input_root = "/home/user/project" |
| 102 | + folder_path = "" |
| 103 | + link_hosted = False |
| 104 | + expected_url = f"{github_root}/tree/master/{folder_path[len(input_root)-1:]}" |
| 105 | + assert github_folder_url(github_root, input_root, folder_path, link_hosted) == expected_url |
0 commit comments