|
|
|
@ -1111,34 +1111,38 @@ function generateJS(ast, options) {
|
|
|
|
|
' return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);',
|
|
|
|
|
' }',
|
|
|
|
|
'',
|
|
|
|
|
' var expectedDescs = new Array(expected.length),',
|
|
|
|
|
' expectedDesc, foundDesc, i, j;',
|
|
|
|
|
' function describeExpected(expected) {',
|
|
|
|
|
' var descriptions = new Array(expected.length),',
|
|
|
|
|
' i, j;',
|
|
|
|
|
'',
|
|
|
|
|
' for (i = 0; i < expected.length; i++) {',
|
|
|
|
|
' expectedDescs[i] = describeExpectation(expected[i]);',
|
|
|
|
|
' }',
|
|
|
|
|
' for (i = 0; i < expected.length; i++) {',
|
|
|
|
|
' descriptions[i] = describeExpectation(expected[i]);',
|
|
|
|
|
' }',
|
|
|
|
|
'',
|
|
|
|
|
' expectedDescs.sort();',
|
|
|
|
|
' descriptions.sort();',
|
|
|
|
|
'',
|
|
|
|
|
' if (expectedDescs.length > 0) {',
|
|
|
|
|
' for (i = 1, j = 1; i < expectedDescs.length; i++) {',
|
|
|
|
|
' if (expectedDescs[i - 1] !== expectedDescs[i]) {',
|
|
|
|
|
' expectedDescs[j] = expectedDescs[i];',
|
|
|
|
|
' j++;',
|
|
|
|
|
' if (descriptions.length > 0) {',
|
|
|
|
|
' for (i = 1, j = 1; i < descriptions.length; i++) {',
|
|
|
|
|
' if (descriptions[i - 1] !== descriptions[i]) {',
|
|
|
|
|
' descriptions[j] = descriptions[i];',
|
|
|
|
|
' j++;',
|
|
|
|
|
' }',
|
|
|
|
|
' }',
|
|
|
|
|
' descriptions.length = j;',
|
|
|
|
|
' }',
|
|
|
|
|
' expectedDescs.length = j;',
|
|
|
|
|
' }',
|
|
|
|
|
'',
|
|
|
|
|
' expectedDesc = expectedDescs.length > 1',
|
|
|
|
|
' ? expectedDescs.slice(0, -1).join(", ")',
|
|
|
|
|
' + " or "',
|
|
|
|
|
' + expectedDescs[expectedDescs.length - 1]',
|
|
|
|
|
' : expectedDescs[0];',
|
|
|
|
|
' return descriptions.length > 1',
|
|
|
|
|
' ? descriptions.slice(0, -1).join(", ")',
|
|
|
|
|
' + " or "',
|
|
|
|
|
' + descriptions[descriptions.length - 1]',
|
|
|
|
|
' : descriptions[0];',
|
|
|
|
|
' }',
|
|
|
|
|
'',
|
|
|
|
|
' foundDesc = found ? "\\"" + literalEscape(found) + "\\"" : "end of input";',
|
|
|
|
|
' function describeFound(found) {',
|
|
|
|
|
' return found ? "\\"" + literalEscape(found) + "\\"" : "end of input";',
|
|
|
|
|
' }',
|
|
|
|
|
'',
|
|
|
|
|
' return "Expected " + expectedDesc + " but " + foundDesc + " found.";',
|
|
|
|
|
' return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";',
|
|
|
|
|
' }',
|
|
|
|
|
'',
|
|
|
|
|
' return new peg$SyntaxError(',
|
|
|
|
|