Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

feat(dateparser): Allow overriding of parsers. #6373

Closed

Conversation

dougludlow
Copy link
Contributor

Proof of concept for #6370.

expect(dateParser.parse('31', 'yy').getFullYear()).toEqual(1931);
expect(dateParser.parse('30', 'yy').getFullYear()).toEqual(2030);
}
finally {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary to wrap in a try-finally - this factory gets reinstantiated with each test execution due to the whole beforeEach running of module('ui.bootstrap.dateparser')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh cool, didn't realize that. I'll pull that out then.

var original = dateParser.getParser('yy');
try {
expect(dateParser.parse('67', 'yy').getFullYear()).toEqual(2067);
expect(dateParser.parse('68', 'yy').getFullYear()).toEqual(2068);
Copy link
Contributor

Choose a reason for hiding this comment

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

These two lines probably aren't necessary, as they should already be covered by tests for the format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One reason I had these here was because the dateParser appears to cache a parser instance for a particular format once it's already been used.

@wesleycho
Copy link
Contributor

This mostly LGTM, just needs a little cleanup.

@dougludlow
Copy link
Contributor Author

@wesleycho how's that? I split the original test out into a few to better articulate the intent.

@wesleycho
Copy link
Contributor

I think the test cases can be simplified - what is mainly of concern is whether you can grab the current parser (and thus the original one), and whether you can override the parser used. That way if a failure in the overriding is present, it is easily isolated by the tests.

@dougludlow
Copy link
Contributor Author

So basically remove the "clears cached parsers when overridden" and we're good as it is implied in "can set a parser back to the original"?

@wesleycho
Copy link
Contributor

The two specs should read
it('should get the current parser'
And
it('should override the parser'
Or something like that, and test those scenarios

@dougludlow
Copy link
Contributor Author

Ok, simplified. I still think it's important to have a test for making sure that the parsers are cleared when a parser is overridden. Basically guarding against this line (https://github.com/dougludlow/bootstrap/blob/b02815b446ad03df6eeb8a7ac054b13d9669f579/src/dateparser/dateparser.js#L258) being removed. If they aren't cleared the overridden parser will not be used.

@dougludlow
Copy link
Contributor Author

@wesleycho any other feedback here?

@wesleycho wesleycho added this to the 2.4.0 milestone Dec 27, 2016
@wesleycho
Copy link
Contributor

LGTM, going to schedule for 2.4.0

@wesleycho wesleycho closed this in 5a3e44a Dec 30, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants