Skip to content

Commit

Permalink
Try to reproduce #4844
Browse files Browse the repository at this point in the history
  • Loading branch information
kneth committed Aug 31, 2022
1 parent a276796 commit 831d0ed
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
51 changes: 51 additions & 0 deletions integration-tests/tests/src/schemas/primitive-types.ts
Original file line number Diff line number Diff line change
@@ -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;
}
31 changes: 30 additions & 1 deletion integration-tests/tests/src/tests/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPerson>;
let contacts: Realm.Results<IContact>;
let primitives: Realm.Results<IPrimitive>;

beforeEach(() => {
Realm.clearTestState();
realm = new Realm({ schema: [PersonSchema, ContactSchema] });
realm = new Realm({ schema: [PersonSchema, ContactSchema, PrimitiveSchema] });
realm.write(() => {
const alice = realm.create<IPerson>(PersonSchema.name, { name: "Alice", age: 15 });
const bob = realm.create<IPerson>(PersonSchema.name, { name: "Bob", age: 14, friends: [alice] });
Expand All @@ -37,9 +39,27 @@ describe("Realm Query Language", () => {
realm.create<IContact>(ContactSchema.name, { name: "Alice", phones: ["555-1234-567"] });
realm.create<IContact>(ContactSchema.name, { name: "Bob", phones: ["555-1122-333", "555-1234-567"] });
realm.create<IContact>(ContactSchema.name, { name: "Charlie" });

realm.create<IPrimitive>(PrimitiveSchema.name, {
s: "foo",
b: true,
i: 2,
f: 3.14,
d: 2.72,
t: new Date("2001-05-11T12:45:05"),
});
realm.create<IPrimitive>(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<IPerson>(PersonSchema.name);
contacts = realm.objects<IContact>(ContactSchema.name);
primitives = realm.objects<IPrimitive>(PrimitiveSchema.name);
});

afterEach(() => {
Expand All @@ -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", () => {
Expand Down

0 comments on commit 831d0ed

Please sign in to comment.