Skip to content

feat(assertions): stringLikeRegexp() matcher#18491

Merged
mergify[bot] merged 13 commits intomasterfrom
otaviom/string-like-matcher
Jan 20, 2022
Merged

feat(assertions): stringLikeRegexp() matcher#18491
mergify[bot] merged 13 commits intomasterfrom
otaviom/string-like-matcher

Conversation

@otaviomacedo
Copy link
Copy Markdown
Contributor

@otaviomacedo otaviomacedo commented Jan 18, 2022

The logic was partly copied from the function with the same name from assert-internal, but the implementation was changed to use minimatch. This way, we can have a well-known and stable contract for the matcher.

Closes #18051.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Jan 18, 2022

@otaviomacedo otaviomacedo requested a review from kaizencc January 18, 2022 14:26
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 18, 2022
@github-actions github-actions bot added the @aws-cdk/assertions Related to the @aws-cdk/assertv2 package label Jan 18, 2022
@rix0rrr
Copy link
Copy Markdown
Contributor

rix0rrr commented Jan 18, 2022

Can you compare with this implementation and see what's different? Niranjan reimplemented it for Pipelines, I don't know if he changed anything:

class StringLike extends Matcher {
public name = 'StringLike';
constructor(private readonly pattern: string) {
super();
}
public test(actual: any): MatchResult {
if (typeof(actual) !== 'string') {
throw new Error(`Expected string but found ${typeof(actual)} ${JSON.stringify(actual)}`);
}
const re = new RegExp(`^${this.pattern.split('*').map(escapeRegex).join('.*')}$`);
const result = new MatchResult(actual);
if (!re.test(actual)) {
result.push(this, [], `Looking for string with pattern "${this.pattern}" but found "${actual}"`);
}
return result;
function escapeRegex(s: string) {
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
}
}

@otaviomacedo otaviomacedo requested a review from rix0rrr January 19, 2022 09:01
@rix0rrr rix0rrr changed the title feat(assertions): added stringLike() matcher feat(assertions): stringLike() matcher Jan 19, 2022
@otaviomacedo otaviomacedo changed the title feat(assertions): stringLike() matcher feat(assertions): stringLikeRegexp() matcher Jan 19, 2022
@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label Jan 19, 2022
@rix0rrr
Copy link
Copy Markdown
Contributor

rix0rrr commented Jan 19, 2022

Provisional approval after small changes.

Copy link
Copy Markdown
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

I approve as well :). Thanks for this!

@otaviomacedo otaviomacedo removed the pr/do-not-merge This PR should not be merged at this time. label Jan 20, 2022
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jan 20, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 2d586c0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit b49b002 into master Jan 20, 2022
@mergify mergify bot deleted the otaviom/string-like-matcher branch January 20, 2022 15:29
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jan 20, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
The logic was partly copied from the function with the same name from `assert-internal`, but the implementation was changed to use [minimatch](https://github.com/isaacs/minimatch). This way, we can have a well-known and stable contract for the matcher.

Closes aws#18051.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@aws-cdk/assertions Related to the @aws-cdk/assertv2 package contribution/core This is a PR that came from AWS.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@aws-cdk/assertions: add Match.stringLike method

4 participants