Browse Source

Merge pull request #4 from oftn/master

merge OFTN version
pull/21/head
Wesley Kerfoot 11 years ago
parent
commit
e5c8baca2b
  1. 42
      test.js
  2. 5
      tokenize.js

42
test.js

@ -9,6 +9,7 @@ var errors = require("./errors.js");
var tokens = require("./tokenize.js"); var tokens = require("./tokenize.js");
var tools = require("./tools.js"); var tools = require("./tools.js");
var typecheck = require("./typecheck.js"); var typecheck = require("./typecheck.js");
var representation = require("./representation.js");
var _ = require("underscore"); var _ = require("underscore");
var qc = require("quickcheck"); var qc = require("quickcheck");
@ -16,6 +17,43 @@ var assert = require("assert");
/* my own generators */ /* my own generators */
function arbChars(n, max, min) {
return function () {
return _.invoke(_.times(_.random(1, n),
_.partial(arbChar, max, min)),
"call");
};
}
function arbChar(max, min) {
return function() {
return String.fromCharCode(_.random(max, min));
};
}
function arbCharRanges(ranges, max) {
return function() {
return _.flatten(
_.shuffle(
_.map(ranges,
function(bound) {
return _.sample(arbChars(max, bound[0], bound[1])(),
bound[1] - bound[0]);
}))).join("");
};
}
var arbName = arbCharRanges([[33, 33],
[35, 39],
[42,43],
[45, 122],
[124, 126]],
200);
var arbCapital = arbChar(65, 90);
function arbArray(gen) { function arbArray(gen) {
return qc.arbArray(gen); return qc.arbArray(gen);
} }
@ -107,5 +145,5 @@ function toolsTests() {
//assert.equal(true, qc.forAll(opMatchProp, arbStrings)); //assert.equal(true, qc.forAll(opMatchProp, arbStrings));
} }
console.log(arbName());
toolsTests(); //toolsTests();

5
tokenize.js

@ -43,7 +43,9 @@ function isIdentifier(c) {
code !== 123 && code !== 123 &&
code !== 93 && code !== 93 &&
code !== 91 && code !== 91 &&
code !== 44); code !== 44 &&
code !== 34 &&
code > 32);
} }
function isUpper(c) { function isUpper(c) {
@ -423,6 +425,5 @@ function tokenizeFull(input) {
return tokenizeHelp(input, matchop, true); return tokenizeHelp(input, matchop, true);
} }
module.exports = {tokenize : tokenizeFull, module.exports = {tokenize : tokenizeFull,
isIdentifier : isIdentifier}; isIdentifier : isIdentifier};

Loading…
Cancel
Save