text: // @flow
  
  import test from 'ava';
  import createSqlTag from '../../../../src/factories/createSqlTag';
  import {
    SqlToken,
  } from '../../../../src/tokens';
  
  const sql = createSqlTag();
  
  test('creates an object describing a query', (t) => {
    const query = sql`SELECT 1`;
  
    t.deepEqual(query, {
      sql: 'SELECT 1',
      type: SqlToken,
      values: [],
    });
  });
  
  test('creates an object describing query value bindings', (t) => {
    const query = sql`SELECT ${'foo'}`;
  
    t.deepEqual(query, {
      sql: 'SELECT $1',
      type: SqlToken,
      values: [
        'foo',
      ],
    });
  });
  
  test('creates an object describing query value bindings (multiple)', (t) => {
    const query = sql`SELECT ${'foo'}, ${'bar'}`;
  
    t.deepEqual(query, {
      sql: 'SELECT $1, $2',
      type: SqlToken,
      values: [
        'foo',
        'bar',
      ],
    });
  });
  
  test('nests sql templates', (t) => {
    const query0 = sql`SELECT ${'foo'} FROM bar`;
    const query1 = sql`SELECT ${'baz'} FROM (${query0})`;
  
    t.deepEqual(query1, {
      sql: 'SELECT $1 FROM (SELECT $2 FROM bar)',
      type: SqlToken,
      values: [
        'baz',
        'foo',
      ],
    });
  });
  
  test('throws if bound an undefined value', (t) => {
    t.throws(() => {
      // $FlowFixMe
      sql`SELECT ${undefined}`;
    }, 'SQL tag cannot be bound an undefined value.');
  });
  
  test('the resulting object is immutable', (t) => {
    const query = sql`SELECT 1`;
  
    t.throws(() => {
      // $FlowFixMe
      query.sql = 'SELECT 2';
    });
  });
  