{"size": 2613, "ext": "js", "max_stars_repo_path": "node_modules/sql-ddl-sync/test/integration/postgresql.js", "max_stars_repo_name": "cszhjh/BMS-API", "max_stars_repo_stars_event_min_datetime": "2020-11-12T08:37:07.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T13:42:49.000Z", "max_issues_repo_path": "node_modules/sql-ddl-sync/test/integration/postgresql.js", "max_issues_repo_name": "cszhjh/BMS-API", "max_issues_repo_issues_event_min_datetime": "2021-05-11T16:52:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T16:52:01.000Z", "max_forks_repo_path": "node_modules/sql-ddl-sync/test/integration/postgresql.js", "max_forks_repo_name": "cszhjh/BMS-API", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 33.5, "max_line_length": 114, "alphanum_fraction": 0.656333716}
var common  = require("../common");
var Dialect = require("../../lib/Dialects/postgresql");

var should  = require("should");

describe("PostgreSQL.getType", function () {
	it("should detect text", function (done) {
		Dialect.getType(null, null, { type: "text" }).value.should.equal("TEXT");
		Dialect.getType(null, null, { type: "text", size: 150 }).value.should.equal("TEXT");
		Dialect.getType(null, null, { type: "text", size: 1000 }).value.should.equal("TEXT");

		return done();
	});

	it("should detect numbers", function (done) {
		Dialect.getType(null, null, { type: "number" }).value.should.equal("INTEGER");
		Dialect.getType(null, null, { type: "number", size: 4 }).value.should.equal("INTEGER");
		Dialect.getType(null, null, { type: "number", size: 2 }).value.should.equal("SMALLINT");
		Dialect.getType(null, null, { type: "number", size: 8 }).value.should.equal("BIGINT");

		return done();
	});

	it("should detect rational numbers", function (done) {
		Dialect.getType(null, null, { type: "number", rational: true }).value.should.equal("REAL");
		Dialect.getType(null, null, { type: "number", rational: true, size: 4 }).value.should.equal("REAL");
		Dialect.getType(null, null, { type: "number", rational: true, size: 8 }).value.should.equal("DOUBLE PRECISION");

		return done();
	});

	it("should detect booleans", function (done) {
		Dialect.getType(null, null, { type: "boolean" }).value.should.equal("BOOLEAN");

		return done();
	});

	it("should detect dates", function (done) {
		Dialect.getType(null, null, { type: "date" }).value.should.equal("DATE");

		return done();
	});

	it("should detect dates with times", function (done) {
		Dialect.getType(null, null, { type: "date", time: true }).value.should.equal("TIMESTAMP WITHOUT TIME ZONE");

		return done();
	});

	it("should detect binary", function (done) {
		Dialect.getType(null, null, { type: "binary" }).value.should.equal("BYTEA");

		return done();
	});

	it("should detect required items", function (done) {
		Dialect.getType(null, null, { type: "boolean", required: true }).value.should.match(/NOT NULL/);

		return done();
	});

	it("should detect default values", function (done) {
		Dialect.getType(null, null, { type: "number", defaultValue: 3 }).value.should.match(/DEFAULT 3/);

		return done();
	});
});

describe("PostgreSQL.escapeId", function () {
	it("should correctly escape identifiers", function (done) {
		Dialect.escapeId("my_id").should.equal('"my_id"');
		Dialect.escapeId("my_\"id").should.equal('"my_""id"');
		Dialect.escapeId("my_id", "sub").should.equal('"my_id"."sub"');

		return done();
	});
});
