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
Conversation
872a59a
to
fa059d7
Compare
javascript-stringify.js
Outdated
@@ -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'; |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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)();
};
There was a problem hiding this comment.
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 () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace above.
I love the idea of |
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 ;) |
I detected and fixed an issue with -0 by using property based tests.