{"size": 2143, "ext": "js", "max_stars_repo_path": "test/data.SqlError.js", "max_stars_repo_name": "abap-weasel/node-hdb", "max_stars_repo_stars_event_min_datetime": "2015-01-31T14:26:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T16:11:24.000Z", "max_issues_repo_path": "test/data.SqlError.js", "max_issues_repo_name": "abap-weasel/node-hdb", "max_issues_repo_issues_event_min_datetime": "2015-01-05T11:24:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T13:59:22.000Z", "max_forks_repo_path": "test/data.SqlError.js", "max_forks_repo_name": "abap-weasel/node-hdb", "max_forks_repo_forks_event_min_datetime": "2015-01-10T14:21:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T18:50:18.000Z"}
{"max_stars_count": 265, "max_issues_count": 136, "max_forks_count": 107, "avg_line_length": 29.7638888889, "max_line_length": 68, "alphanum_fraction": 0.6551563229}
// Copyright 2013 SAP AG.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http: //www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
'use strict';

var lib = require('../lib');
var normalize = require('./normalize');
var PartKind = lib.common.PartKind;
var ErrorLevel = lib.common.ErrorLevel;
var SqlError = lib.data[PartKind.ERROR];

function serializeError(error) {
  var length = Buffer.byteLength(error.message);
  var buffer = new Buffer(18 + length);
  buffer.writeInt32LE(error.code, 0);
  buffer.writeInt32LE(error.position, 4);
  buffer.writeInt32LE(length, 8);
  buffer.writeInt8(error.level, 12);
  buffer.write(error.sqlState, 13, 5);
  buffer.write(error.message, 18, length);
  return buffer;
}
describe('Data', function () {

  describe('#SqlError', function () {

    it('should deserialize warning from buffer', function () {
      var warning = {
        message: 'foo',
        code: 1,
        position: 2,
        level: ErrorLevel.WARNING,
        sqlState: 'HY001'
      };
      var sqlError = SqlError.read({
        buffer: serializeError(warning),
        argumentCount: 1
      });
      normalize(sqlError).should.eql(warning);
      SqlError.getArgumentCount(sqlError).should.equal(1);
      SqlError.getByteLength(sqlError).should.equal(21);
    });

    it('should deserialize fatal error from buffer', function () {
      var fatal = {
        message: 'bar',
        code: 1,
        position: 2,
        level: ErrorLevel.FATAL,
        fatal: true,
        sqlState: 'HY001'
      };
      var sqlError = SqlError.read({
        buffer: serializeError(fatal),
        argumentCount: 1
      });
      normalize(sqlError).should.eql(fatal);
    });

  });

});