From 50328747687d8742795de28bee41f8d42eb64924 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Thu, 18 Nov 2021 10:52:00 +1100 Subject: [PATCH] test private_field_presence --- cli/tests/integration/run_tests.rs | 10 ++++++++++ cli/tests/testdata/import_type.ts | 5 +++++ cli/tests/testdata/import_type.ts.out | 2 ++ cli/tests/testdata/private_field_presence.ts | 20 +++++++++++++++++++ .../testdata/private_field_presence.ts.out | 3 +++ cli/tests/testdata/subdir/export_types.ts | 11 ++++++++++ 6 files changed, 51 insertions(+) create mode 100644 cli/tests/testdata/import_type.ts create mode 100644 cli/tests/testdata/import_type.ts.out create mode 100644 cli/tests/testdata/private_field_presence.ts create mode 100644 cli/tests/testdata/private_field_presence.ts.out create mode 100644 cli/tests/testdata/subdir/export_types.ts diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 33c1507c84018a..47ad7841e70fec 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -573,6 +573,16 @@ itest!(import_type_no_check { output: "import_type.ts.out", }); +itest!(private_field_presence { + args: "run --reload private_field_presence.ts", + output: "private_field_presence.ts.out", +}); + +itest!(private_field_presence_no_check { + args: "run --reload --no-check private_field_presence.ts", + output: "private_field_presence.ts.out", +}); + itest!(lock_write_requires_lock { args: "run --lock-write some_file.ts", output: "lock_write_requires_lock.out", diff --git a/cli/tests/testdata/import_type.ts b/cli/tests/testdata/import_type.ts new file mode 100644 index 00000000000000..851ebad86ac43e --- /dev/null +++ b/cli/tests/testdata/import_type.ts @@ -0,0 +1,5 @@ +import { type B, create } from "./subdir/export_types.ts"; + +const b: B = create(); + +console.log(b); diff --git a/cli/tests/testdata/import_type.ts.out b/cli/tests/testdata/import_type.ts.out new file mode 100644 index 00000000000000..188c5e25db796e --- /dev/null +++ b/cli/tests/testdata/import_type.ts.out @@ -0,0 +1,2 @@ +[WILDCARD] +B { a: "a" } diff --git a/cli/tests/testdata/private_field_presence.ts b/cli/tests/testdata/private_field_presence.ts new file mode 100644 index 00000000000000..7ce2840d8e3edd --- /dev/null +++ b/cli/tests/testdata/private_field_presence.ts @@ -0,0 +1,20 @@ +export class Person { + #name: string; + constructor(name: string) { + this.#name = name; + } + + equals(other: unknown) { + return other && + typeof other === "object" && + #name in other && + this.#name === other.#name; + } +} + +const a = new Person("alice"); +const b = new Person("bob"); +const c = new Person("alice"); + +console.log(a.equals(b)); +console.log(a.equals(c)); diff --git a/cli/tests/testdata/private_field_presence.ts.out b/cli/tests/testdata/private_field_presence.ts.out new file mode 100644 index 00000000000000..f582fb47ad4388 --- /dev/null +++ b/cli/tests/testdata/private_field_presence.ts.out @@ -0,0 +1,3 @@ +[WILDCARD] +false +true diff --git a/cli/tests/testdata/subdir/export_types.ts b/cli/tests/testdata/subdir/export_types.ts new file mode 100644 index 00000000000000..18c8ed8810f7aa --- /dev/null +++ b/cli/tests/testdata/subdir/export_types.ts @@ -0,0 +1,11 @@ +export interface A { + a: string; +} + +export class B implements A { + a = "a"; +} + +export function create(): B { + return new B(); +}