From 831d0ed44e89a3564c7a99adcf7c351ef6b21a07 Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Wed, 31 Aug 2022 11:32:12 +0200 Subject: [PATCH] Try to reproduce #4844 --- .../tests/src/schemas/primitive-types.ts | 51 +++++++++++++++++++ integration-tests/tests/src/tests/queries.ts | 31 ++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 integration-tests/tests/src/schemas/primitive-types.ts diff --git a/integration-tests/tests/src/schemas/primitive-types.ts b/integration-tests/tests/src/schemas/primitive-types.ts new file mode 100644 index 0000000000..29a0bad65d --- /dev/null +++ b/integration-tests/tests/src/schemas/primitive-types.ts @@ -0,0 +1,51 @@ +//////////////////////////////////////////////////////////////////////////// +// +// Copyright 2022 Realm Inc. +// +// 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. +// +//////////////////////////////////////////////////////////////////////////// + +/* tslint:disable max-classes-per-file */ + +import Realm from "realm"; + +export interface IPrimitive { + s: string; + b: boolean; + i: number; + f: number; + d: number; + t: Date; +} + +export const PrimitiveSchema: Realm.ObjectSchema = { + name: "Primitive", + properties: { + s: "string", + b: "bool", + i: "int", + f: "float", + d: "double", + t: "date", + }, +}; + +export class Primitive extends Realm.Object implements IPrimitive { + s!: string; + b!: boolean; + i!: number; + f!: number; + d!: number; + t!: Date; +} diff --git a/integration-tests/tests/src/tests/queries.ts b/integration-tests/tests/src/tests/queries.ts index 5ee43ae5b7..20d47d2a86 100644 --- a/integration-tests/tests/src/tests/queries.ts +++ b/integration-tests/tests/src/tests/queries.ts @@ -20,15 +20,17 @@ import Realm from "realm"; import { IPerson, Person, PersonSchema } from "../schemas/person-and-dogs"; import { IContact, Contact, ContactSchema } from "../schemas/contact"; +import { IPrimitive, Primitive, PrimitiveSchema } from "../schemas/primitive-types"; describe("Realm Query Language", () => { let realm: Realm; let persons: Realm.Results; let contacts: Realm.Results; + let primitives: Realm.Results; beforeEach(() => { Realm.clearTestState(); - realm = new Realm({ schema: [PersonSchema, ContactSchema] }); + realm = new Realm({ schema: [PersonSchema, ContactSchema, PrimitiveSchema] }); realm.write(() => { const alice = realm.create(PersonSchema.name, { name: "Alice", age: 15 }); const bob = realm.create(PersonSchema.name, { name: "Bob", age: 14, friends: [alice] }); @@ -37,9 +39,27 @@ describe("Realm Query Language", () => { realm.create(ContactSchema.name, { name: "Alice", phones: ["555-1234-567"] }); realm.create(ContactSchema.name, { name: "Bob", phones: ["555-1122-333", "555-1234-567"] }); realm.create(ContactSchema.name, { name: "Charlie" }); + + realm.create(PrimitiveSchema.name, { + s: "foo", + b: true, + i: 2, + f: 3.14, + d: 2.72, + t: new Date("2001-05-11T12:45:05"), + }); + realm.create(PrimitiveSchema.name, { + s: "Here is a Unicorn 🦄 today", + b: false, + i: 44, + f: 1.41, + d: 4.67, + t: new Date("2004-02-26T10:15:02"), + }); }); persons = realm.objects(PersonSchema.name); contacts = realm.objects(ContactSchema.name); + primitives = realm.objects(PrimitiveSchema.name); }); afterEach(() => { @@ -59,6 +79,15 @@ describe("Realm Query Language", () => { expect(contacts[1].phones.length).equal(2); expect(contacts[2].phones.length).equal(0); }); + + // https://github.com/realm/realm-js/issues/4844 + it("emoiji and contains", () => { + expect(primitives.length).equal(2); + const unicorn1 = primitives.filtered("s CONTAINS 'unicorn 🦄 today'"); + const unicorn2 = primitives.filtered("s CONTAINS[c] 'unicorn 🦄 today'"); + expect(unicorn1.length).equal(0); + expect(unicorn2.length).equal(1); + }); }); describe("IN operator", () => {