From 63c59308e6ece788084374c4fc393576684992a7 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 17 Dec 2019 13:50:08 +0800 Subject: Add tests --- .../code/src/test/utils/diagnotics/rust.test.ts | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'editors/code/src/test/utils/diagnotics') diff --git a/editors/code/src/test/utils/diagnotics/rust.test.ts b/editors/code/src/test/utils/diagnotics/rust.test.ts index 0222dbbaa..9acd319b3 100644 --- a/editors/code/src/test/utils/diagnotics/rust.test.ts +++ b/editors/code/src/test/utils/diagnotics/rust.test.ts @@ -199,4 +199,38 @@ describe('mapRustDiagnosticToVsCode', () => { // There are no suggested fixes assert.strictEqual(suggestedFixes.length, 0); }); + + it('should map a macro invocation location to normal file path', () => { + const { location, diagnostic, suggestedFixes } = mapFixtureToVsCode( + 'error/E0277', + ); + + assert.strictEqual( + diagnostic.severity, + vscode.DiagnosticSeverity.Error, + ); + assert.strictEqual( + diagnostic.message, + [ + 'can\'t compare `{integer}` with `&str`', + 'the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`', + ].join('\n'), + ); + assert.strictEqual(diagnostic.code, 'E0277'); + assert.strictEqual(diagnostic.source, 'rustc'); + assert.deepStrictEqual(diagnostic.tags, []); + + // No related information + assert.deepStrictEqual(diagnostic.relatedInformation, []); + + // There are no suggested fixes + assert.strictEqual(suggestedFixes.length, 0); + + // The file url should be normal file + // Ignore the first part because it depends on vs workspace location + assert.strictEqual( + true, + location.uri.toString().endsWith('src/main.rs'), + ); + }); }); -- cgit v1.2.3 From bb9c60d90863b21a0e981f00e354d02b0e9fb584 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 17 Dec 2019 21:43:19 +0800 Subject: Use substr instead of endswith --- editors/code/src/test/utils/diagnotics/rust.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'editors/code/src/test/utils/diagnotics') diff --git a/editors/code/src/test/utils/diagnotics/rust.test.ts b/editors/code/src/test/utils/diagnotics/rust.test.ts index 9acd319b3..358325cc8 100644 --- a/editors/code/src/test/utils/diagnotics/rust.test.ts +++ b/editors/code/src/test/utils/diagnotics/rust.test.ts @@ -212,7 +212,7 @@ describe('mapRustDiagnosticToVsCode', () => { assert.strictEqual( diagnostic.message, [ - 'can\'t compare `{integer}` with `&str`', + "can't compare `{integer}` with `&str`", 'the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`', ].join('\n'), ); @@ -229,8 +229,8 @@ describe('mapRustDiagnosticToVsCode', () => { // The file url should be normal file // Ignore the first part because it depends on vs workspace location assert.strictEqual( - true, - location.uri.toString().endsWith('src/main.rs'), + location.uri.path.substr(-'src/main.rs'.length), + 'src/main.rs', ); }); }); -- cgit v1.2.3