<commit_before>import n1qlFormatter from "xr/sqlFormatter/n1qlFormatter";
import behavesLikeSqlFormatter from "tests/specs/sqlFormatter/behavesLikeSqlFormatter";

describe("n1qlFormatter", function() {
    behavesLikeSqlFormatter(n1qlFormatter);

    it("formats SELECT query with element selection expression", function() {
        const result = n1qlFormatter.format("SELECT orderlines[0].productId FROM orders;");
        expect(result).toBe(
            "SELECT\n" +
            "  orderlines[0].productId\n" +
            "FROM\n" +
            "  orders;\n"
        );
    });

    it("formats SELECT query with primary key quering", function() {
        const result = n1qlFormatter.format(
            "SELECT fname, email FROM tutorial USE KEYS ['dave', 'ian'];"
        );
        expect(result).toBe(
            "SELECT\n" +
            "  fname,\n" +
            "  email\n" +
            "FROM\n" +
            "  tutorial\n" +
            "USE KEYS\n" +
            "  ['dave', 'ian'];\n"
        );
    });

    it("formats INSERT with {} object literal", function() {
        const result = n1qlFormatter.format(
            "INSERT INTO heroes (KEY, VALUE) VALUES ('123', {'id': 1, 'type': 'Tarzan'});"
        );
        expect(result).toBe(
            "INSERT INTO heroes (KEY, VALUE)\n" +
            "VALUES\n" +
            "  (\n" +
            "    '123',\n" +
            "    {'id' : 1, 'type' : 'Tarzan'}\n" +
            "  );\n"
        );
    });

    it("formats SELECT query with UNNEST toplevel reserver word", function() {
        const result = n1qlFormatter.format(
            "SELECT * FROM tutorial UNNEST tutorial.children c;"
        );
        expect(result).toBe(
            "SELECT\n" +
            "  *\n" +
            "FROM\n" +
            "  tutorial\n" +
            "UNNEST\n" +
            "  tutorial.children c;\n"
        );
    });

    it("formats SELECT query with NEST and USE KEYS", function() {
        const result = n1qlFormatter.format(
            "SELECT * FROM usr " +
            "USE KEYS 'Elinor_33313792' NEST orders_with_users orders " +
            "ON KEYS ARRAY s.order_id FOR s IN usr.shipped_order_history END;"
        );
        expect(result).toBe(
            "SELECT\n" +
            "  *\n" +
            "FROM\n" +
            "  usr\n" +
            "USE KEYS\n" +
            "  'Elinor_33313792'\n" +
            "NEST\n" +
            "  orders_with_users orders ON KEYS ARRAY s.order_id FOR s IN usr.shipped_order_history END;\n"
        );
    });

    it("formats explained DELETE query with USE KEYS and RETURNING", function() {
        const result = n1qlFormatter.format(
            "EXPLAIN DELETE FROM tutorial t USE KEYS 'baldwin' RETURNING t"
        );
        expect(result).toBe(
            "EXPLAIN DELETE FROM\n" +
            "  tutorial t\n" +
            "USE KEYS\n" +
            "  'baldwin' RETURNING t\n"
        );
    });

    it("formats UPDATE query with USE KEYS and RETURNING", function() {
        const result = n1qlFormatter.format(
            "UPDATE tutorial USE KEYS 'baldwin' SET type = 'actor' RETURNING tutorial.type"
        );
        expect(result).toBe(
            "UPDATE\n" +
            "  tutorial\n" +
            "USE KEYS\n" +
            "  'baldwin'\n" +
            "SET\n" +
            "  type = 'actor' RETURNING tutorial.type\n"
        );
    });
});
<commit_msg>XR-3710 Add N1QL test with large [] & {} literals<commit_after>import n1qlFormatter from "xr/sqlFormatter/n1qlFormatter";
import behavesLikeSqlFormatter from "tests/specs/sqlFormatter/behavesLikeSqlFormatter";

describe("n1qlFormatter", function() {
    behavesLikeSqlFormatter(n1qlFormatter);

    it("formats SELECT query with element selection expression", function() {
        const result = n1qlFormatter.format("SELECT orderlines[0].productId FROM orders;");
        expect(result).toBe(
            "SELECT\n" +
            "  orderlines[0].productId\n" +
            "FROM\n" +
            "  orders;\n"
        );
    });

    it("formats SELECT query with primary key quering", function() {
        const result = n1qlFormatter.format(
            "SELECT fname, email FROM tutorial USE KEYS ['dave', 'ian'];"
        );
        expect(result).toBe(
            "SELECT\n" +
            "  fname,\n" +
            "  email\n" +
            "FROM\n" +
            "  tutorial\n" +
            "USE KEYS\n" +
            "  ['dave', 'ian'];\n"
        );
    });

    it("formats INSERT with {} object literal", function() {
        const result = n1qlFormatter.format(
            "INSERT INTO heroes (KEY, VALUE) VALUES ('123', {'id': 1, 'type': 'Tarzan'});"
        );
        expect(result).toBe(
            "INSERT INTO heroes (KEY, VALUE)\n" +
            "VALUES\n" +
            "  (\n" +
            "    '123',\n" +
            "    {'id' : 1, 'type' : 'Tarzan'}\n" +
            "  );\n"
        );
    });

    it("formats INSERT with large object and array literals", function() {
        const result = n1qlFormatter.format(
            "INSERT INTO heroes (KEY, VALUE) VALUES ('123', {'id': 1, 'type': 'Tarzan', " +
            "'array': [123456789, 123456789, 123456789, 123456789], 'hello': 'world'});"
        );
        expect(result).toBe(
            "INSERT INTO heroes (KEY, VALUE)\n" +
            "VALUES\n" +
            "  (\n" +
            "    '123',\n" +
            "    {\n" +
            "      'id' : 1,\n" +
            "      'type' : 'Tarzan',\n" +
            "      'array' : [\n" +
            "        123456789,\n" +
            "        123456789,\n" +
            "        123456789,\n" +
            "        123456789\n" +
            "      ],\n" +
            "      'hello' : 'world'\n" +
            "    }\n" +
            "  );\n"
        );
    });

    it("formats SELECT query with UNNEST toplevel reserver word", function() {
        const result = n1qlFormatter.format(
            "SELECT * FROM tutorial UNNEST tutorial.children c;"
        );
        expect(result).toBe(
            "SELECT\n" +
            "  *\n" +
            "FROM\n" +
            "  tutorial\n" +
            "UNNEST\n" +
            "  tutorial.children c;\n"
        );
    });

    it("formats SELECT query with NEST and USE KEYS", function() {
        const result = n1qlFormatter.format(
            "SELECT * FROM usr " +
            "USE KEYS 'Elinor_33313792' NEST orders_with_users orders " +
            "ON KEYS ARRAY s.order_id FOR s IN usr.shipped_order_history END;"
        );
        expect(result).toBe(
            "SELECT\n" +
            "  *\n" +
            "FROM\n" +
            "  usr\n" +
            "USE KEYS\n" +
            "  'Elinor_33313792'\n" +
            "NEST\n" +
            "  orders_with_users orders ON KEYS ARRAY s.order_id FOR s IN usr.shipped_order_history END;\n"
        );
    });

    it("formats explained DELETE query with USE KEYS and RETURNING", function() {
        const result = n1qlFormatter.format(
            "EXPLAIN DELETE FROM tutorial t USE KEYS 'baldwin' RETURNING t"
        );
        expect(result).toBe(
            "EXPLAIN DELETE FROM\n" +
            "  tutorial t\n" +
            "USE KEYS\n" +
            "  'baldwin' RETURNING t\n"
        );
    });

    it("formats UPDATE query with USE KEYS and RETURNING", function() {
        const result = n1qlFormatter.format(
            "UPDATE tutorial USE KEYS 'baldwin' SET type = 'actor' RETURNING tutorial.type"
        );
        expect(result).toBe(
            "UPDATE\n" +
            "  tutorial\n" +
            "USE KEYS\n" +
            "  'baldwin'\n" +
            "SET\n" +
            "  type = 'actor' RETURNING tutorial.type\n"
        );
    });
});

{'fraction_non_alphanumeric': 0.1381757192620307, 'fraction_numerical': 0.02064249774222681, 'mean_word_length': 1.5325057170859195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7235579', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2396, 'n_words': 535}