From 3160b5cfcc7325df0ff0e5b748c59abc00355bb9 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 17 Dec 2020 09:45:49 -0800 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20require=20fourslash=20completio?= =?UTF-8?q?ns=20tests=20to=20specify=20replacementSpan=20when=20it?= =?UTF-8?q?=E2=80=99s=20zero-length=20(#42013)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/harness/fourslashImpl.ts | 12 +++++++----- .../fourslash/completionsWithGenericStringLiteral.ts | 7 ++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index a14c75bf3cc..2e0c9c4dc63 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -907,11 +907,13 @@ namespace FourSlash { this.raiseError(`Expected completion insert text to be ${expected.insertText}, got ${actual.insertText}`); } const convertedReplacementSpan = expected.replacementSpan && ts.createTextSpanFromRange(expected.replacementSpan); - try { - assert.deepEqual(actual.replacementSpan, convertedReplacementSpan); - } - catch { - this.raiseError(`Expected completion replacementSpan to be ${stringify(convertedReplacementSpan)}, got ${stringify(actual.replacementSpan)}`); + if (convertedReplacementSpan?.length) { + try { + assert.deepEqual(actual.replacementSpan, convertedReplacementSpan); + } + catch { + this.raiseError(`Expected completion replacementSpan to be ${stringify(convertedReplacementSpan)}, got ${stringify(actual.replacementSpan)}`); + } } if (expected.kind !== undefined || expected.kindModifiers !== undefined) { diff --git a/tests/cases/fourslash/completionsWithGenericStringLiteral.ts b/tests/cases/fourslash/completionsWithGenericStringLiteral.ts index d9e331a29a5..e8c5c5fbd80 100644 --- a/tests/cases/fourslash/completionsWithGenericStringLiteral.ts +++ b/tests/cases/fourslash/completionsWithGenericStringLiteral.ts @@ -2,12 +2,9 @@ // @strict: true //// declare function get(obj: T, key: K): T[K]; -//// get({ hello: 123, world: 456 }, "[|/**/|]"); +//// get({ hello: 123, world: 456 }, "/**/"); verify.completions({ marker: "", - includes: [ - { name: 'hello', replacementSpan: test.ranges()[0] }, - { name: 'world', replacementSpan: test.ranges()[0] } - ] + includes: ["hello", "world"] });