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

Detected and fixed an issue related to -0 #20

Merged
merged 2 commits into from Feb 5, 2019

Conversation

dubzzz
Copy link
Contributor

@dubzzz dubzzz commented Jan 31, 2019

I detected and fixed an issue with -0 by using property based tests.

  • first commit adds the fix and test for the value -0
  • second commit adds the test that discovered the issue.

@coveralls
Copy link

coveralls commented Jan 31, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 41f9386 on dubzzz:master into 9d2b937 on blakeembrey:master.

@dubzzz dubzzz force-pushed the master branch 2 times, most recently from 872a59a to fa059d7 Compare January 31, 2019 21:47
@@ -214,7 +214,10 @@
'string': function (string) {
return "'" + string.replace(ESCAPABLE, escapeChar) + "'";
},
'number': String,
'number': function (val) {
if (val === 0 && 1 / val === -Infinity) return '-0';
Copy link
Owner

Choose a reason for hiding this comment

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

What about using Object.is? I realize this has much better compatibility though, so LGTM!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, I believed Object.is was not part of Node 4, but it is.

@@ -331,4 +334,21 @@ describe('javascript-stringify', function () {
test(obj, '{a:{b:{}}}', null, { maxDepth: 2, references: true })
);
});
describe('property based', function () {
var customEval = function (repr) {
Copy link
Owner

Choose a reason for hiding this comment

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

Would it make sense to just use eval for now? I'm not sure we need the additional wrapper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I had an issue with eval, but I will try again ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling console.log(eval("{}")) prints undefined.
Calling console.log(eval("(function () { return {}; })()")); does work.

So I can either have:

var customEval = function (repr) {
  return eval("(function () { return " + repr + "; })()");
};

or

var customEval = function (repr) {
  return Function("return " + repr)();
};

Copy link
Owner

Choose a reason for hiding this comment

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

That makes sense, since it's a block. All good 👍

@@ -331,4 +334,21 @@ describe('javascript-stringify', function () {
test(obj, '{a:{b:{}}}', null, { maxDepth: 2, references: true })
);
});
describe('property based', function () {
Copy link
Owner

Choose a reason for hiding this comment

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

Whitespace above.

@blakeembrey
Copy link
Owner

I love the idea of fast-check, I'm so glad someone other than me got around to this finally! I'll look more into it and see how else I can better utilize it to test, especially around some of the more complex code possible (e.g. regexps and properties on objects).

@blakeembrey blakeembrey merged commit 3c2fd3b into blakeembrey:master Feb 5, 2019
@dubzzz
Copy link
Contributor Author

dubzzz commented Feb 5, 2019

Concerning the generation of regex, I wrote a snippet doing that few days ago: https://runkit.com/dubzzz/valid-regex-generator

It is still incomplete but it is a good start ^^

I will maybe include such generator in fast-check ;)

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.

None yet

3 participants