add unit tests and change readme
This commit is contained in:
parent
2374e2b5d1
commit
7abc0dbbc4
@ -17,6 +17,8 @@ node main.js
|
||||
|
||||
Result fill write in <lexer.js> file.
|
||||
|
||||
You can test it:
|
||||
$ node test.js
|
||||
|
||||
|
||||
Report for bugs: rolahd@yandex.ru
|
41
lexer.l
41
lexer.l
@ -279,43 +279,4 @@ var print_f = function() {
|
||||
r_str += next;
|
||||
|
||||
return r_str;
|
||||
};
|
||||
|
||||
console.log("TEST SINGLE");
|
||||
(new Lexer("[")).search();
|
||||
(new Lexer("]")).search();
|
||||
(new Lexer("(")).search();
|
||||
(new Lexer(")").search());
|
||||
(new Lexer(":")).search();
|
||||
(new Lexer(",")).search();
|
||||
(new Lexer(".")).search();
|
||||
(new Lexer("%")).search();
|
||||
(new Lexer(">")).search();
|
||||
(new Lexer(">=")).search();
|
||||
(new Lexer("<")).search();
|
||||
(new Lexer("<=")).search();
|
||||
(new Lexer("==")).search();
|
||||
(new Lexer("!=")).search();
|
||||
(new Lexer("AND")).search();
|
||||
(new Lexer("and")).search();
|
||||
(new Lexer("OR")).search();
|
||||
(new Lexer("or")).search();
|
||||
(new Lexer("NOT")).search();
|
||||
(new Lexer("not")).search();
|
||||
(new Lexer("LIKE")).search();
|
||||
(new Lexer("like")).search();
|
||||
(new Lexer("NLIKE")).search();
|
||||
(new Lexer("nlike")).search();
|
||||
(new Lexer("Address")).search();
|
||||
(new Lexer("Time")).search();
|
||||
(new Lexer("TimeDiff")).search();
|
||||
|
||||
var lex_test_all = new Lexer("[ ] ( ) : , . % > >= < <= == != AND and OR or NOT not LIKE like NLIKE nlike Address Time TimeDiff 'sdfadfasdf' \"asdfasfd\" ")
|
||||
var _lex;
|
||||
while(_lex = lex_test_all.next()){
|
||||
console.log("IN while:", _lex.lexeme);
|
||||
}
|
||||
|
||||
console.log("TEST STRING LITERAL");
|
||||
(new Lexer(' "111\\\"11\\\"1" "222222" ')).search();
|
||||
(new Lexer(" '111\\\'11\\\'1' '222222' ")).search();
|
||||
};
|
7
main.js
7
main.js
@ -39,5 +39,10 @@ var post_process_lexer = function (_string) {
|
||||
|
||||
_string = js_beautify(_string, {indent_size: 4, space_in_empty_paren: true});
|
||||
|
||||
fs.writeFileSync("lexer.js", _string);
|
||||
var output = "lexer.js";
|
||||
if(process.argv[2]){
|
||||
output = process.argv[2];
|
||||
}
|
||||
|
||||
fs.writeFileSync(output, _string);
|
||||
};
|
62
test.js
Normal file
62
test.js
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Created by Aleksey Chichenkov <a.chichenkov@initi.ru> on 1/25/19.
|
||||
*/
|
||||
var fs = require("fs");
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
exec("node main.js lexer_test.js", function(err, stdout, stderr) {
|
||||
err && console.log("ERROR: ", err);
|
||||
err && process.exit(1);
|
||||
|
||||
var file = fs.readFileSync("lexer_test.js", "utf8");
|
||||
file += "\n module.exports = Lexer";
|
||||
fs.writeFileSync("lexer_test.js", file);
|
||||
|
||||
test();
|
||||
|
||||
fs.unlinkSync("lexer_test.js");
|
||||
});
|
||||
|
||||
var test = function() {
|
||||
var Lexer = require("./lexer_test");
|
||||
|
||||
console.log("TEST SINGLE");
|
||||
(new Lexer("[")).search();
|
||||
(new Lexer("]")).search();
|
||||
(new Lexer("(")).search();
|
||||
(new Lexer(")").search());
|
||||
(new Lexer(":")).search();
|
||||
(new Lexer(",")).search();
|
||||
(new Lexer(".")).search();
|
||||
(new Lexer("%")).search();
|
||||
(new Lexer(">")).search();
|
||||
(new Lexer(">=")).search();
|
||||
(new Lexer("<")).search();
|
||||
(new Lexer("<=")).search();
|
||||
(new Lexer("==")).search();
|
||||
(new Lexer("!=")).search();
|
||||
(new Lexer("AND")).search();
|
||||
(new Lexer("and")).search();
|
||||
(new Lexer("OR")).search();
|
||||
(new Lexer("or")).search();
|
||||
(new Lexer("NOT")).search();
|
||||
(new Lexer("not")).search();
|
||||
(new Lexer("LIKE")).search();
|
||||
(new Lexer("like")).search();
|
||||
(new Lexer("NLIKE")).search();
|
||||
(new Lexer("nlike")).search();
|
||||
(new Lexer("Address")).search();
|
||||
(new Lexer("Time")).search();
|
||||
(new Lexer("TimeDiff")).search();
|
||||
|
||||
var lex_test_all = new Lexer("[ ] ( ) : , . % > >= < <= == != AND and OR or NOT not LIKE like NLIKE nlike Address Time TimeDiff 'sdfadfasdf' \"asdfasfd\" ")
|
||||
var _lex;
|
||||
|
||||
console.log("start search");
|
||||
while (_lex = lex_test_all.next());
|
||||
|
||||
console.log("TEST STRING LITERAL");
|
||||
(new Lexer(' "111\\\"11\\\"1" "222222" ')).search();
|
||||
(new Lexer(" '111\\\'11\\\'1' '222222' ")).search();
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user