From 13e6010d04c7e923429c59c06c415ab8e08b25eb Mon Sep 17 00:00:00 2001 From: Thomas Lindop Date: Thu, 15 May 2025 12:16:10 +0100 Subject: [PATCH] >> remove more complex whitespace behaviour form tests > make restrictRuneset pass tests --- Makefile | 4 +++- main.go | 8 ++++++-- man.md | 20 ++++---------------- owl_test.go | 2 +- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index cf71eca..2b187f7 100644 --- a/Makefile +++ b/Makefile @@ -5,4 +5,6 @@ owl: ${SOURCES} owl.1: man.md pandoc -s --shift-heading-level-by=-1 --to=man man.md > owl.1 build: owl owl.1 -.PHONY: build +test: *.go + go test -v . +.PHONY: build test diff --git a/main.go b/main.go index 62f539d..5201739 100644 --- a/main.go +++ b/main.go @@ -91,13 +91,16 @@ func restrictRuneset(s, strategy string) string { } else { for _, r := range result { if !isFatValid(r) { - toValidSubs[r] = fmt.Sprintf("_U%d_", r) + toValidSubs[r] = fmt.Sprintf("_U%X_", r) } } } for old, new := range toValidSubs { result = strings.ReplaceAll(result, string(old), new) } + if len(result) == 0 { + return "_EMPTY_" + } return result } @@ -159,7 +162,7 @@ func parseCLIArgs(args []string) (context, error) { // TODO: Finish writing options short help. Mention man page where relevant. func printHelp() { - fmt.Println(`Owl - a hunter of bad characters in filenames + fmt.Print(`Owl - a hunter of bad characters in filenames Usage: owl [options] FILES @@ -172,6 +175,7 @@ func printHelp() { -h,--help -v,--version -d,--directory DIRECTORY + `); } diff --git a/man.md b/man.md index 49d314f..4005b78 100644 --- a/man.md +++ b/man.md @@ -9,39 +9,27 @@ not compatible with `FAT` file systems (typically `FAT32` or `exFAT`). owl COMMAND OPTIONS FILE1 FILE2 ... ``` - -## CLEAN COMMAND Rename `FILE`s given at the command line such that all `FAT`-incompatible characters are removed. By default it replaces invalid characters with `_U{Unicode Code Point}_`, but this can be changed, see the `--strategy` flag below. -## Options: +## Options: ### -s, --strategy STRATEGY Change what happens to invalid characters. Choices are: - "remove": just remove the characters. If left with an empty string, rename to "\_empty_". -- "code-point": replace each character with "\_Unum_", where "num" is the +- "represent": replace each character with "\_Unum_", where "num" is the Unicode Code Point of the character. -## HELP COMMAND -Show a small help message. - -## VERSION COMMAND -Show version information. - - -## GENERAL OPTIONS ### -n, --dry-run Causes Owl to just print a representation of what would be done without actually renaming any files. ### -v, --version -Causes the `version` command to be run, regardless of what other arguments -are given. +Show version information. ### -h, --help -Causes the `help` command to be run, regardless of what other arguments are -given. +Show a small help message. diff --git a/owl_test.go b/owl_test.go index 53c3dcc..f67795d 100644 --- a/owl_test.go +++ b/owl_test.go @@ -29,7 +29,7 @@ func TestRestrictRuneset(t *testing.T) { "The Salmon \U0001f41f Of Doubt": "The Salmon \U0001f41f Of Doubt", "Why put questions in file names?": "Why put questions in file names", "This* causes ~problems~": "This causes ~problems~", - "There are* *alot ** of c*veats * here": "There are alot of cveats here", + "There are* *alot ** of c*veats * here": "There are alot of cveats here", } representTCases := map[string]string{ "::?\\": "_U3A__U3A__U3F__U5C_",