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

fix!: update separators #40

Merged
merged 6 commits into from
Oct 5, 2023
Merged

fix!: update separators #40

merged 6 commits into from
Oct 5, 2023

Conversation

jly36963
Copy link
Contributor

@jly36963 jly36963 commented Oct 5, 2023

Should Close #35

src/utils.ts Outdated Show resolved Hide resolved
Comment on lines +84 to +86
const result = subject.words(
'[one] two-three/four.five(six){seven}|eight_nine\\ten',
)
Copy link
Owner

Choose a reason for hiding this comment

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

good one!

describe('with various separators', () => {
const text =
'[one] two-three/four.five(six){seven}|eight_nine\\ten' as const

Copy link
Contributor Author

@jly36963 jly36963 Oct 5, 2023

Choose a reason for hiding this comment

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

I wish for a DRYer way to write this test suite -- they're all the exact same.

There isn't a way to do the following, is there?

const text = 'abc'

const resultExpectedMap = new Map([
  [subject.toUpperCase(text), 'ABC'],
  // ...
]) 

for (const [result, expected] of resultExpectedMap.entries() {
  expect(result).toEqual(expected)
  type test = Expect<Equal<typeof result, typeof expected>>
}

Copy link
Contributor Author

@jly36963 jly36963 Oct 5, 2023

Choose a reason for hiding this comment

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

The closest I could get is this
Screenshot 2023-10-05 at 1 26 26 PM

Try 1

describe('with various separators', () => {
  const text = 'abc'

  const resultExpectedMap = new Map([
    [subject.toUpperCase(text), 'ABC' as const],
    [subject.toLowerCase(text), 'abc' as const],
    // ...
  ])

  for (const [result, expected] of resultExpectedMap.entries()) {
    expect(result).toEqual(expected)
    type test = Expect<Equal<typeof result, typeof expected>>
  }
})

The problem with the above code is that I could switch ABC and abc on the expected side of the map and the type union would still be equal

Try 2

describe('with various separators', () => {
  const text = 'abc'
  const a = {
    [subject.toUpperCase(text)]: 'ABC' as const,
    [subject.toLowerCase(text)]: 'abc' as const,
  } as const

  for (const [result, expected] of Object.entries(a)) {
    expect(result).toEqual(expected)
    type test = Expect<Equal<typeof result, typeof expected>>
  }
})

The problem with this one is that the type assertion fails (string !== 'abc' | 'ABC')

Copy link
Owner

Choose a reason for hiding this comment

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

It could be easier... I personally am not a fan of too much abstractions in tests.. I tend to just repeat LOCs to avoid potential footguns.
But not against the trials

@gustavoguichard
Copy link
Owner

Lemme know when it is ready for review

@jly36963 jly36963 marked this pull request as ready for review October 5, 2023 20:12
@gustavoguichard gustavoguichard merged commit 616a048 into main Oct 5, 2023
1 check passed
@gustavoguichard gustavoguichard deleted the refactor-separators branch October 5, 2023 22:46
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.

toTitleCase is removing full stops .
2 participants