Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add abbreviations for title case #41

Merged
merged 7 commits into from
Oct 3, 2023
Merged

Conversation

amoghrajesh
Copy link
Contributor

@amoghrajesh amoghrajesh commented Oct 1, 2023

Description

Adding support for title casing.
Running example:

➜  abbreviate git:(title-casing) ✗ ./abbreviate pascal prestrategy-limitedment
PrstgLtdmnt
➜  abbreviate git:(title-casing) ✗ ./abbreviate title prestrategy-limitedment   
Prstg Ltdmnt

Fixes #39

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Running existing tests
  • Created new tests

Checklist:

  • My code has been linted (make lint)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have rebased my branch to include the latest changes from master

@ghost
Copy link

ghost commented Oct 1, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@amoghrajesh
Copy link
Contributor Author

@dnnrly I was unable to set up godog locally. So i created this PR so that the CI runs here.

@amoghrajesh
Copy link
Contributor Author

@dnnrly how is it supposed to work without the code?

  Scenario: Title case                                                  # features/cli.feature:46
    When the app runs with parameters "title --max 15 strategy_limited" # features_test.go:30 -> *testContext
    Then the app exits without error                                    # features_test.go:41 -> *testContext
    
	Error Trace:	features_test.go:42
	            				value.go:476
	            				value.go:337
	            				stepdef.go:159
	            				suite.go:138
	            				suite.go:225
	            				suite.go:284
	            				run.go:111
	            				asm_amd64.s:1371
	Error:      	Received unexpected error:
	            	exit status 1

    And the app output contains exactly "Strategy-Ltd"                  # features_test.go:57 -> *testContext
Command line output for "Title case"
Using parameters: title --max 15 strategy_limited
Error: unknown command "title" for "abbreviate"
Run 'abbreviate --help' for usage.
unknown command "title" for "abbreviate"

@amoghrajesh amoghrajesh changed the title WIP: Add abbreviations for title case Add abbreviations for title case Oct 1, 2023
@dnnrly
Copy link
Owner

dnnrly commented Oct 2, 2023

I have merged a change to master that should fix the problems you were having with Godog. I'm not sure why the title sub-command isn't working. That'll take a little more investigation.

@dnnrly
Copy link
Owner

dnnrly commented Oct 2, 2023

I did some more checking on a rebased version of your branch - I think it might be the length is set wrong. Try --max 14.

@amoghrajesh
Copy link
Contributor Author

amoghrajesh commented Oct 3, 2023

@dnnrly fixed it. Can you have a look today?

cmd/title.go Outdated
Comment on lines 31 to 44
abbr := domain.AsPascal(abbreviator, args[0], optMax, optFrmFront, optRemoveStopwords)

if len(abbr) > 0 {
s := string(abbr[0])
for i := 1; i < len(abbr); i++ {
if string(abbr[i]) == strings.ToUpper(string(abbr[i])) {
s += " "
}
s += string(abbr[i])
}

fmt.Printf("%s", s)

}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is decent implementation. I think to make it align with the the rest of the codebase it might be worth creating a new function ToTitle in the domain package that returns a string. That way we use unit tests to validate the behaviour and just have to print it out in this command function - this would be a great thing to see here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I just pushed a fix after refactoring and adding unit tests. Can you take a look now?

@amoghrajesh amoghrajesh requested a review from dnnrly October 3, 2023 15:39
@dnnrly
Copy link
Owner

dnnrly commented Oct 3, 2023

I think there's an error in the title command file:
https://github.com/dnnrly/abbreviate/actions/runs/6395253163/job/17358471652?pr=41#step:4:24

@amoghrajesh
Copy link
Contributor Author

@dnnrly copy paste errors :)
Fixed!

@dnnrly dnnrly merged commit 958e2cc into dnnrly:master Oct 3, 2023
4 checks passed
@dnnrly
Copy link
Owner

dnnrly commented Oct 3, 2023

As is my tradition, you've earned a follow on Twitter. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add abbreviations for title case
2 participants