| 1 |
dojo.provide("util.docscripts.tests.basic"); |
| 2 |
(function(){ |
| 3 |
|
| 4 |
var url = dojo.moduleUrl("util.docscripts", "dumpObj.php") + ""; |
| 5 |
function getdata(file){ |
| 6 |
|
| 7 |
var r; |
| 8 |
dojo.xhrGet({ |
| 9 |
url: url + "?f=" + file, |
| 10 |
sync: true, |
| 11 |
handleAs:"json", |
| 12 |
handle: function(response){ |
| 13 |
r = response; |
| 14 |
} |
| 15 |
}); |
| 16 |
return r; |
| 17 |
|
| 18 |
} |
| 19 |
|
| 20 |
var docs; |
| 21 |
function getmember(key, obj){ |
| 22 |
obj = obj || docs; |
| 23 |
return obj[key]; |
| 24 |
} |
| 25 |
|
| 26 |
doh.register("doctests.basic", [ |
| 27 |
|
| 28 |
function actual_fetching(t){ |
| 29 |
docs = getdata("util/docscripts/tests/simple.js"); |
| 30 |
t.t(docs); |
| 31 |
t.t(typeof docs == "object"); |
| 32 |
t.is(docs["#provides"], "util.docscripts.tests.simple", "provide() object found"); |
| 33 |
t.is(docs["#resource"], "docscripts/tests/simple.js", "filename expansion"); |
| 34 |
t.t(docs["util.docscripts.tests"], "provide() expansion"); |
| 35 |
}, |
| 36 |
|
| 37 |
function simple_requires(t){ |
| 38 |
t.t(dojo.isArray(docs['#requires'][0]), "populated require"); |
| 39 |
t.t(~dojo.indexOf(docs["#requires"][0], "dojo.cookie"), "found cookie require"); |
| 40 |
}, |
| 41 |
|
| 42 |
function module_level_docs(t){ |
| 43 |
var fb = getmember("util.docscripts.tests.simple"); |
| 44 |
t.is("Module level summary", fb.summary, "summary from psuedo on module obj"); |
| 45 |
}, |
| 46 |
|
| 47 |
function basic_class(t){ |
| 48 |
|
| 49 |
var fb = getmember("dojo.FooBar"); |
| 50 |
|
| 51 |
t.t(fb, "dojo.FooBar docs exist"); |
| 52 |
t.t(fb.classlike, "classlike thinger found"); |
| 53 |
t.is("A Class", fb.summary, "picked up summary from post-decalre docs"); |
| 54 |
t.is("Function", fb.type, "inference"); |
| 55 |
t.is("A Class description", fb.description, "description from post-declare docs"); |
| 56 |
|
| 57 |
t.t(dojo.isArray(fb.examples), "found examples"); |
| 58 |
t.is(1, fb.examples.length, "found one example exactly"); |
| 59 |
|
| 60 |
var fbc = getmember("dojo.FooBar.constructor"); |
| 61 |
t.is(fbc.prototype, "dojo.FooBar", "prototype binding"); |
| 62 |
t.is(fbc.parameters.args.name, fb.parameters.args.name, "params from constructor implied on class"); |
| 63 |
|
| 64 |
var mf = getmember("dojo.FooBar.memberFn"); |
| 65 |
t.t(mf, "member function picked out of declaration"); |
| 66 |
|
| 67 |
var params = mf.parameters; |
| 68 |
t.is("String", params.a.type); |
| 69 |
t.f(params.b.optional); |
| 70 |
t.is("String", params.b.type); |
| 71 |
t.f(params.b.optional); |
| 72 |
t.is("Boolean", params.c.type); |
| 73 |
t.t(params.c.optional, "last arg optional"); |
| 74 |
t.is("Integer", mf.returns); |
| 75 |
t.is("A member function", mf.summary); |
| 76 |
|
| 77 |
}, |
| 78 |
|
| 79 |
function inherited_class(t){ |
| 80 |
var fb2 = getmember("dojo.FooBar2"); |
| 81 |
t.t(fb2); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
}, |
| 88 |
|
| 89 |
function mixin_docs(t){ |
| 90 |
var mv = getmember("dojo.mixedValue"); |
| 91 |
t.is("External doc block, mixed", mv.summary, "summary found for mixed value"); |
| 92 |
t.is("Integer", mv.type, "type infered from mixed value"); |
| 93 |
t.is("dojo", mv.attached, "alias lookup in d.mixin"); |
| 94 |
|
| 95 |
var mf = getmember("dojo.mixedFunction"); |
| 96 |
t.is("dojo", mf.attached, "alias lookup in d.mixin"); |
| 97 |
t.is("Integer", mf.returns, "returns from return line"); |
| 98 |
t.is("From mixin", mf.summary, "basic summary"); |
| 99 |
t.is("a", mf.parameters.a.name, "parameter picked up"); |
| 100 |
t.t(mf.parameters.a.optional, "param is optional"); |
| 101 |
t.is(mf.parameters.a.summary, "Some number or not", "parameter description picked up"); |
| 102 |
}, |
| 103 |
|
| 104 |
function basic_function(t){ |
| 105 |
|
| 106 |
var fb = getmember("dojo.thisIsAtestFunction"); |
| 107 |
t.t(fb, "testFunction docs exist"); |
| 108 |
t.is("Testing a function", fb.summary); |
| 109 |
t.is("String", fb.returns, "return value determined"); |
| 110 |
t.is("Testing a string parameter", fb.parameters.a.summary, "parameter summary picked out"); |
| 111 |
}, |
| 112 |
|
| 113 |
function testfunction2(t){ |
| 114 |
var tf = getmember("dojo.testFunction2"); |
| 115 |
t.is("Simple summary", tf.summary); |
| 116 |
t.is("Simple Description.\nOn Multiple lines.", tf.description); |
| 117 |
t.t(tf.parameters.id.optional); |
| 118 |
t.is("Duplicate matched in signature and in line", tf.parameters.id.summary); |
| 119 |
t.is("String", tf.parameters.id.type); |
| 120 |
}, |
| 121 |
|
| 122 |
function test_returner(t){ |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
var r = getmember("dojo.returner"); |
| 132 |
t.t(r); |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
t.is("String|Integer\nThis should be description", r.return_summary); |
| 140 |
t.f(r.returns); |
| 141 |
}, |
| 142 |
|
| 143 |
function test_multireturner(t){ |
| 144 |
var r = getmember("dojo.multiReturns"); |
| 145 |
t.t(r); |
| 146 |
t.is("String|Integer", r.returns, "found all return statement types in block"); |
| 147 |
t.is("Simple multireturn check", r.summary); |
| 148 |
}, |
| 149 |
|
| 150 |
function aliased_query(t){ |
| 151 |
var dq = getmember("dojo.query.stub"); |
| 152 |
t.t(dq, "$ -> dojo.query unwrapped from closure"); |
| 153 |
t.is("Integer", dq.returns); |
| 154 |
t.is("aliased to `dojo.query`", dq.summary, "FIX: requires undone <code>"); |
| 155 |
}, |
| 156 |
|
| 157 |
function kwarg_test(t){ |
| 158 |
var kw = getmember("util.docscripts.tests.simple.__kwArgs"); |
| 159 |
var args = kw.parameters; |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
var kwf = getmember("dojo.kwArgFunction"); |
| 164 |
var kwp = kwf.parameters.args; |
| 165 |
|
| 166 |
t.is("util.docscripts.tests.simple.__kwArgs", kwp.type); |
| 167 |
|
| 168 |
}, |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
function functional(t){ |
| 181 |
|
| 182 |
docs = getdata("util/docscripts/tests/functional.js"); |
| 183 |
var hasit = getmember("util.docscripts.tests.FunctionalThinger"); |
| 184 |
t.t(hasit, "object exists in parsed output, meaning parsing happened"); |
| 185 |
}, |
| 186 |
|
| 187 |
function raw_declare_init(t){ |
| 188 |
docs = getdata("util/docscripts/tests/extend_declare.js"); |
| 189 |
t.t(true); |
| 190 |
}, |
| 191 |
|
| 192 |
function raw_declare(t){ |
| 193 |
var barbaz = getmember("dojo.BarBaz"); |
| 194 |
t.t(barbaz, "raw declare() call defined a named class"); |
| 195 |
}, |
| 196 |
|
| 197 |
function lang_extend(t){ |
| 198 |
var someprop = getmember("dojo.BarBaz.someProp"); |
| 199 |
t.t(someprop, "lang.extend worked"); |
| 200 |
t.is("String", someprop.type, "lang.extend unwrapped innards"); |
| 201 |
}, |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
function winning(t){ |
| 216 |
var prop = getmember("dojo.BarBaz.winning"); |
| 217 |
console.warn(prop); |
| 218 |
t.t(prop, "aliased extend() call resolves properly"); |
| 219 |
t.is("Boolean", prop.type); |
| 220 |
t.is("Always true.", prop.summary, "are we? rad.") |
| 221 |
} |
| 222 |
|
| 223 |
]); |
| 224 |
|
| 225 |
})(); |