8000 Added tests for this binding and fnth · repos-javascript-compilers/ki@d92ead1 · GitHub
[go: up one dir, main page]

Skip to content

Commit d92ead1

Browse files
committed
Added tests for this binding and fnth
1 parent 1c233fa commit d92ead1

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

TODO.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@
4141
* **DONE** atoms
4242
* **DONE** exceptions
4343
* **DONE** allow generated scripts to run in browser (avoid require)
44-
* **DONE** fnth (fn bound to this) **TODO** test
45-
* **DONE** be consistent in binding to this **TODO** test
44+
* **DONE** fnth (fn bound to this)
45+
* **DONE** be consistent in binding to this
4646

4747
* **DONE** testing
4848

4949
* example with node
50-
* example with React
50+
* **DONE** example with React
5151

5252
## 0.3.0 Add the nice to have
5353

5454
* destructuring
55+
* multiline strings
5556
* CPS modeled after tame.js
5657
In tame we would have something like
5758
(await (setTimeout (defer) 100))
@@ -74,7 +75,7 @@
7475
* named parameters and defaults
7576
* optional arguments to functions (catpured in a vector)
7677
* regular expressions
77-
* expression problem
78+
* implement a REPL
7879
* additional functions/forms
7980
* condp case
8081
* for (comprehension)

macros/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ macro _sexpr {
385385
_sexpr $fn.apply(this,_sexpr (clj_to_js $args))
386386
}
387387

388-
rule { (bind $fn $obj) } => {
388+
rule { (bind $obj $fn) } => {
389389
_sexpr $fn.bind($obj)
390390
}
391391

@@ -678,6 +678,10 @@ macro ki {
678678
}());}
679679
}
680680

681+
//case {_ macro ($x ...) ($y ...)} => {
682+
// return #{};
683+
//}
684+
681685
case { $ki ($x ...) } => {
682686

683687
var Token = {

src/ki.sjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ macro _sexpr {
385385
_sexpr $fn.apply(this,_sexpr (clj_to_js $args))
386386
}
387387

388-
rule { (bind $fn $obj) } => {
388+
rule { (bind $obj $fn) } => {
389389
_sexpr $fn.bind($obj)
390390
}
391391

@@ -678,6 +678,10 @@ macro ki {
678678
}());}
679679
}
680680

681+
//case {_ macro ($x ...) ($y ...)} => {
682+
// return #{};
683+
//}
684+
681685
case { $ki ($x ...) } => {
682686

683687
var Token = {

test/core.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ describe("bind", function() {
548548
ki (do
549549
(def a {:a 1 :b 2})
550550
(defn f [] (get this :a)))
551-
expect(ki ((bind f a))).to.eql(1);
552-
expect(ki ((bind (fn [] (get this :a)) a))).to.eql(1);
551+
expect(ki ((bind a f))).to.eql(1);
552+
expect(ki ((bind a (fn [] (get this :a))))).to.eql(1);
553553
});
554554

555555
});
@@ -613,6 +613,41 @@ describe("exceptions", function() {
613613

614614
});
615615

616+
describe("this and fnth", function() {
617+
618+
it("should handle binding this fn-wise correctly from within IIFN", function() {
619+
620+
ki require core
621+
622+
ki (defn somefn [] (letv [a 1] this.someprop));
623+
var bar = {someprop: 1};
624+
var baz = {};
625+
626+
expect(ki ((bind bar somefn))).to.eql(1);
627+
expect(ki ((bind baz somefn))).to.eql(undefined);
628+
expect(ki (somefn)).to.eql(undefined);
629+
630+
});
631+
632+
it("should allow a shorthand notation for defining a fn bound to the enclosing this", function() {
633+
634+
ki require core
635+
636+
var fn1, fn2;
637+
ki (do
638+
(js this.jee = 1)
639+
(letv [a (fn [] this.jee)
640+
b (fnth [] this.jee)]
641+
(js fn1 = a)
642+
(js fn2 = b)));
643+
644+
expect(fn1.bind({jee: 2})()).to.eql(2);
645+
expect(fn2.bind({jee: 2})()).to.eql(1);
646+
647+
});
648+
649+
});
650+
616651
describe("str", function() {
617652

618653
it("should allow to concatenate strings and literals", function() {

0 commit comments

Comments
 (0)
0