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

feat(assertions): stringLikeRegexp() matcher #18491

Merged
merged 13 commits into from
Jan 20, 2022
Merged

Conversation

otaviomacedo
Copy link
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

gitpod-io bot commented Jan 18, 2022

@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
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
}
}
}

@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
packages/@aws-cdk/assertions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/assertions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/assertions/lib/template.ts Outdated Show resolved Hide resolved
@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label Jan 19, 2022
@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 19, 2022

Provisional approval after small changes.

Copy link
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!

packages/@aws-cdk/assertions/test/match.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/assertions/lib/match.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/assertions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/assertions/README.md Outdated Show resolved Hide resolved
@otaviomacedo otaviomacedo removed the pr/do-not-merge This PR should not be merged at this time. label Jan 20, 2022
@mergify
Copy link
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
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
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