| 1 | module main |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | fn test_trim_symlink_command_accepts_forwarded_subcommand() { |
| 6 | assert trim_symlink_command([]string{}) == []string{} |
| 7 | assert trim_symlink_command(['symlink']) == []string{} |
| 8 | assert trim_symlink_command(['symlink', '~/.local/bin']) == ['~/.local/bin'] |
| 9 | assert trim_symlink_command(['~/.local/bin']) == ['~/.local/bin'] |
| 10 | } |
| 11 | |
| 12 | fn test_parse_symlink_options_defaults_to_default_location() { |
| 13 | options := parse_symlink_options([]string{}) or { panic(err) } |
| 14 | assert options == SymlinkOptions{} |
| 15 | } |
| 16 | |
| 17 | fn test_parse_symlink_options_accepts_custom_directory() { |
| 18 | options := parse_symlink_options(['symlink', '~/.local/bin']) or { panic(err) } |
| 19 | assert options.github_ci == false |
| 20 | assert options.link_dir == '~/.local/bin' |
| 21 | } |
| 22 | |
| 23 | fn test_parse_symlink_options_supports_githubci() { |
| 24 | options := parse_symlink_options(['symlink', '-githubci']) or { panic(err) } |
| 25 | assert options.github_ci |
| 26 | assert options.link_dir == '' |
| 27 | } |
| 28 | |
| 29 | fn test_parse_symlink_options_rejects_multiple_arguments() { |
| 30 | if options := parse_symlink_options(['symlink', '/tmp/bin', 'extra']) { |
| 31 | assert false, 'expected an error, got ${options}' |
| 32 | } else { |
| 33 | assert err.msg() == symlink_usage |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | fn test_normalized_link_dir_expands_tilde() { |
| 38 | path := os.join_path('~', '.local', 'bin') |
| 39 | expected := os.join_path(os.home_dir(), '.local', 'bin') |
| 40 | assert normalized_link_dir(path) == expected |
| 41 | } |
| 42 | |
| 43 | fn test_symlink_path_uses_platform_binary_name() { |
| 44 | $if windows { |
| 45 | assert symlink_path(r'C:\tools\vbin') == os.join_path(r'C:\tools\vbin', 'v.exe') |
| 46 | } $else { |
| 47 | assert symlink_path('/tmp/vbin') == os.join_path('/tmp/vbin', 'v') |
| 48 | } |
| 49 | } |
| 50 | |