diff options
Diffstat (limited to 'spec/inputs/test/stub_spec.yue')
| -rw-r--r-- | spec/inputs/test/stub_spec.yue | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/spec/inputs/test/stub_spec.yue b/spec/inputs/test/stub_spec.yue new file mode 100644 index 0000000..99345c7 --- /dev/null +++ b/spec/inputs/test/stub_spec.yue | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | describe "function stub", -> | ||
| 2 | it "should create empty function", -> | ||
| 3 | stub_fn! | ||
| 4 | assert.is_true true | ||
| 5 | |||
| 6 | it "should support stub in table", -> | ||
| 7 | obj = { | ||
| 8 | stub: stub_fn! | ||
| 9 | } | ||
| 10 | assert.is_true true | ||
| 11 | |||
| 12 | it "should work with method stub", -> | ||
| 13 | obj = | ||
| 14 | method: stub_fn! | ||
| 15 | assert.is_true true | ||
| 16 | |||
| 17 | it "should handle stub in assignment", -> | ||
| 18 | my_func = stub_fn! | ||
| 19 | assert.is_true true | ||
| 20 | |||
| 21 | it "should support stub in return", -> | ||
| 22 | get_stub = -> stub_fn! | ||
| 23 | fn = get_stub! | ||
| 24 | assert.is_true true | ||
| 25 | |||
| 26 | it "should work in conditional", -> | ||
| 27 | if stub_fn! | ||
| 28 | assert.is_true true | ||
| 29 | |||
| 30 | it "should support stub as callback", -> | ||
| 31 | call_fn = (fn) -> fn! | ||
| 32 | result = call_fn stub_fn! | ||
| 33 | assert.is_true true | ||
| 34 | |||
| 35 | it "should handle stub in table literal", -> | ||
| 36 | tb = { | ||
| 37 | on_click: stub_fn! | ||
| 38 | on_hover: stub_fn! | ||
| 39 | } | ||
| 40 | assert.is_true true | ||
| 41 | |||
| 42 | it "should work with fat arrow stub", -> | ||
| 43 | obj = | ||
| 44 | value: 10 | ||
| 45 | method: stub_fn! | ||
| 46 | |||
| 47 | result = obj\method! | ||
| 48 | assert.is_true true | ||
| 49 | |||
| 50 | it "should support stub in array", -> | ||
| 51 | callbacks = [stub_fn!, stub_fn!, stub_fn!] | ||
| 52 | assert.same #callbacks, 3 | ||
| 53 | |||
| 54 | it "should handle stub in expression", -> | ||
| 55 | result = stub_fn! and true or false | ||
| 56 | assert.is_true result | ||
| 57 | |||
| 58 | it "should work with chained stub calls", -> | ||
| 59 | stub_fn! | ||
| 60 | stub_fn! | ||
| 61 | stub_fn! | ||
| 62 | assert.is_true true | ||
| 63 | |||
| 64 | it "should support stub in comprehension", -> | ||
| 65 | result = [stub_fn! for i = 1, 3] | ||
| 66 | assert.same #result, 3 | ||
| 67 | |||
| 68 | it "should handle stub in switch", -> | ||
| 69 | value = "test" | ||
| 70 | result = switch value | ||
| 71 | when "test" | ||
| 72 | stub_fn! | ||
| 73 | "matched" | ||
| 74 | else | ||
| 75 | "not matched" | ||
| 76 | assert.same result, "matched" | ||
| 77 | |||
| 78 | it "should work in with statement", -> | ||
| 79 | obj = {stub: stub_fn!} | ||
| 80 | with obj | ||
| 81 | .stub! | ||
| 82 | assert.is_true true | ||
| 83 | |||
| 84 | it "should support stub as argument default", -> | ||
| 85 | fn = (callback = stub_fn!) -> | ||
| 86 | callback! | ||
| 87 | |||
| 88 | result = fn! | ||
| 89 | assert.is_true true | ||
| 90 | |||
| 91 | it "should handle stub in varargs", -> | ||
| 92 | collect = (...) -> | ||
| 93 | {...} | ||
| 94 | |||
| 95 | result = collect stub_fn!, stub_fn! | ||
| 96 | assert.same #result, 2 | ||
| 97 | |||
| 98 | it "should work in do block", -> | ||
| 99 | do | ||
| 100 | stub_fn! | ||
| 101 | assert.is_true true | ||
| 102 | |||
| 103 | it "should support stub in try block", -> | ||
| 104 | success = try | ||
| 105 | stub_fn! | ||
| 106 | true | ||
| 107 | catch err | ||
| 108 | false | ||
| 109 | assert.is_true success | ||
