Permalink
Browse files

add a new test of sqlparser

  • Loading branch information...
XadillaX committed Oct 23, 2015
1 parent aa90281 commit 58800abfdb55bc78e5871a6e24bfff3e0ad764a6
Showing with 61 additions and 5 deletions.
  1. +5 −5 test/field.js
  2. +56 −0 test/sqlparser.js
@@ -130,10 +130,10 @@ describe("Field",function () {
String.equal("123",123).should.be.true;
});
it("should return false", function () {
String.equal('123',null).should.be.false;
String.equal('123',undefined).should.be.false;
String.equal(NaN,'123').should.be.false;
String.equal('123','1234').should.be.false;
String.equal("123",null).should.be.false;
String.equal("123",undefined).should.be.false;
String.equal(NaN,"123").should.be.false;
String.equal("123","1234").should.be.false;
});
});

@@ -147,7 +147,7 @@ describe("Field",function () {
describe("Json type", function () {
var json = field.Json;
describe("#restore", function () {
it('Json to String', function () {
it("Json to String", function () {
json.restore({a:1}).should.eql("{\"a\":1}");
});
});
@@ -0,0 +1,56 @@
/**
* XadillaX created at 2015-10-23 10:51:54 With ♥
*
* Copyright (c) 2015 Souche.com, all rights
* reserved.
*/
require("should");
var parser = require("../util/sqlparser");

describe("Some SQL Parser", function() {
describe("sql name to column", function() {
it("should be SELECT a FROM b WHERE c = d", function() {
var sql = "SELECT aa FROM b WHERE cc = dd";
var answer = parser.sqlNameToColumn(sql, {
aa: "a",
cc: "c",
dd: "d"
});
answer.should.be.eql("SELECT a FROM b WHERE c = d");
});

it("should be SELECT `a` FROM b WHERE c = \"d\" AND `d` = e", function() {
var sql = "SELECT `aa` FROM b WHERE cc = \"d\" AND `dd` = ee";
var answer = parser.sqlNameToColumn(sql, {
aa: "a",
cc: "c",
dd: "d",
ee: "e"
});
answer.should.be.eql("SELECT `a` FROM b WHERE c = \"d\" AND `d` = e");
});

it("should be SELECT `a` AS k FROM b WHERE c = \"d\" AND `d` + `e` = e + 1", function() {
var sql = "SELECT `aa` AS k FROM b WHERE cc = \"d\" AND `dd` + `ee` = ee + 1";
var answer = parser.sqlNameToColumn(sql, {
aa: "a",
cc: "c",
dd: "d",
ee: "e"
});
answer.should.be.eql("SELECT `a` AS k FROM b WHERE c = \"d\" AND `d` + `e` = e + 1");
});

it("should be SELECT `a` AS k FROM b WHERE c = \"d\" AND `d` + `e` = e + `f`", function() {
var sql = "SELECT `aa` AS k FROM b WHERE cc = \"d\" AND `dd` + `ee` = ee + `f_f`";
var answer = parser.sqlNameToColumn(sql, {
aa: "a",
cc: "c",
dd: "d",
ee: "e",
f_f: "f"
});
answer.should.be.eql("SELECT `a` AS k FROM b WHERE c = \"d\" AND `d` + `e` = e + `f`");
});
});
});

0 comments on commit 58800ab

Please sign in to comment.