Debian Codegraph @

esniff/test/index.js

raw
1 "use strict";
2
3 var readFile = require("fs").readFile
4 , ast = require("./_ast-index")
5 , pg = __dirname + "/__playground";
6
7 module.exports = {
8 "Common": function (t, a, d) {
9 readFile(pg + "/index.js", "utf-8", function (err, str) {
10 if (err) {
11 d(err);
12 return;
13 }
14 var plainR = t(str, function (emitter) {
15 emitter.on("trigger:f", function (accessor) {
16 if (accessor.previousToken === ".") return;
17 if (!accessor.skipCodePart("foo")) return;
18 accessor.skipWhitespace();
19 if (!accessor.skipCodePart(".")) return;
20 accessor.skipWhitespace();
21 if (!accessor.skipCodePart("bar")) return;
22 accessor.skipWhitespace();
23 accessor.collectScope();
24 });
25 });
26 var astR = ast(str);
27 a(plainR.length, astR.length, "Length");
28 astR.forEach(function (val, i) {
29 if (!plainR[i]) return;
30 delete plainR[i].raw;
31 a.deep(plainR[i], val, i);
32 });
33 d();
34 });
35 },
36 "Observe control character": function (t, a) {
37 var argsStartIndex
38 , argsEndIndex
39 , bodyStartIndex
40 , bodyEndReverseIndex = -1
41 , shouldTrimArgs = false
42 , str = "foo=> { marko; }";
43
44 t(str, function (emitter, accessor) {
45 emitter.once("trigger:=", function () {
46 argsStartIndex = 0;
47 argsEndIndex = accessor.index;
48 shouldTrimArgs = true;
49 if (!accessor.skipCodePart("=>")) {
50 throw new Error("Unexpected function string: " + str);
51 }
52 accessor.skipWhitespace();
53 if (!accessor.skipCodePart("{")) bodyEndReverseIndex = Infinity;
54 bodyStartIndex = accessor.index;
55 });
56 });
57 var argsString = str.slice(argsStartIndex, argsEndIndex);
58 if (shouldTrimArgs) argsString = argsString.trim();
59 a.deep(
60 { args: argsString, body: str.slice(bodyStartIndex, bodyEndReverseIndex) },
61 { args: "foo", body: " marko; " }
62 );
63 }
64 };