From 94f8b9f16e9f3d423225b28619281a5ecf877275 Mon Sep 17 00:00:00 2001 From: Raphael Speyer Date: Wed, 6 Jul 2011 11:46:53 +1000 Subject: [PATCH] added doctests for with and parseInt --- testsrc/doctests/parseint.doctest | 18 ++++++++++++++++++ testsrc/doctests/with.doctest | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 testsrc/doctests/parseint.doctest create mode 100644 testsrc/doctests/with.doctest diff --git a/testsrc/doctests/parseint.doctest b/testsrc/doctests/parseint.doctest new file mode 100644 index 0000000000..a36519e0c0 --- /dev/null +++ b/testsrc/doctests/parseint.doctest @@ -0,0 +1,18 @@ +js> parseInt +function parseInt() { [native code for parseInt, arity=2] } +js> parseInt("0"); +0 +js> parseInt("1") +1 +js> parseInt("-1") +-1 +js> parseInt(" 2") +2 +js> parseInt("3then some other chars") +3 +js> parseInt('0xF') +15 +js> parseInt('0xf') +15 +js> parseInt('010') +8 diff --git a/testsrc/doctests/with.doctest b/testsrc/doctests/with.doctest new file mode 100644 index 0000000000..daeee63c53 --- /dev/null +++ b/testsrc/doctests/with.doctest @@ -0,0 +1,22 @@ +js> load('testsrc/doctests/util.js'); + +js> // when the variable is not in the with-object, it'll be set on the outer scope +js> (function() { with ({}) { var foo = 1; }; return foo; })() +1 + +js> // when the function is not in the with-object, it'll be set on the outer scope +js> (function() { with ({}) { function foo() { return 2; } }; return foo(); })() +2 + +js> // when the variable is in the with-object, it will be updated on the with-object +js> (function() { var obj = {foo:0}; with (obj) { var foo = 3; }; return obj.foo; })() +3 + +js> // functions declared inside with blocks are always bound to the closest enclosing function +js> (function() { function foo(){ return 0; }; with ({}) { function foo() { return 4; } }; return foo(); })() +4 + +js> // functions declared inside with blocks do not affect the properties of the with-obj +js> (function() { var obj = {foo:5}; with (obj) { function foo() { return 0; } }; return obj.foo; })() +5 +