waterline-utils
Version:
Various utilities for working with Waterline queries and adapters.
56 lines (49 loc) • 1.46 kB
JavaScript
var Analyzer = require('../../../index').query.analyzer;
var tokenize = require('../../support/tokenize');
var assert = require('assert');
describe('Analyzer ::', function() {
describe('SELECT statements', function() {
it('should generate a valid group for select "*"', function() {
var tokens = tokenize({
select: ['*'],
from: 'books'
});
var result = Analyzer(tokens);
assert.deepEqual(result, [
[
{ type: 'IDENTIFIER', value: 'SELECT' },
{ type: 'VALUE', value: '*' }
],
[
{ type: 'IDENTIFIER', value: 'FROM' },
{ type: 'VALUE', value: 'books' }
]
]);
});
it('should generate a valid group for select when defined columns are used', function() {
var tokens = tokenize({
select: ['title', 'author', 'year'],
from: 'books'
});
var result = Analyzer(tokens);
assert.deepEqual(result, [
[
{ type: 'IDENTIFIER', value: 'SELECT' },
{ type: 'VALUE', value: 'title' }
],
[
{ type: 'IDENTIFIER', value: 'SELECT' },
{ type: 'VALUE', value: 'author' }
],
[
{ type: 'IDENTIFIER', value: 'SELECT' },
{ type: 'VALUE', value: 'year' }
],
[
{ type: 'IDENTIFIER', value: 'FROM' },
{ type: 'VALUE', value: 'books' }
]
]);
});
});
});