From 4ba2e91ef9dd93bd9f8ad9b9b1a6ef7d0510823c Mon Sep 17 00:00:00 2001 From: BooksBaum <15612932+Booksbaum@users.noreply.github.com> Date: Wed, 18 Nov 2020 21:21:29 +0100 Subject: [PATCH] Add comparison of xml comments --- .../#368-compare-xml-comments.fail.d.ts | 4 +++ ...#368-compare-xml-comments.fail.expected.fs | 11 ++++++++ .../#368-compare-xml-comments.pass.d.ts | 4 +++ ...#368-compare-xml-comments.pass.expected.fs | 11 ++++++++ test/fsFileTests.fs | 26 +++++++++++++------ 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 test/fragments/regressions/#368-compare-xml-comments.fail.d.ts create mode 100644 test/fragments/regressions/#368-compare-xml-comments.fail.expected.fs create mode 100644 test/fragments/regressions/#368-compare-xml-comments.pass.d.ts create mode 100644 test/fragments/regressions/#368-compare-xml-comments.pass.expected.fs diff --git a/test/fragments/regressions/#368-compare-xml-comments.fail.d.ts b/test/fragments/regressions/#368-compare-xml-comments.fail.d.ts new file mode 100644 index 00000000..45c487d5 --- /dev/null +++ b/test/fragments/regressions/#368-compare-xml-comments.fail.d.ts @@ -0,0 +1,4 @@ +/** + * XML comments are compared + */ +interface SomeInterface {} diff --git a/test/fragments/regressions/#368-compare-xml-comments.fail.expected.fs b/test/fragments/regressions/#368-compare-xml-comments.fail.expected.fs new file mode 100644 index 00000000..8f7b9039 --- /dev/null +++ b/test/fragments/regressions/#368-compare-xml-comments.fail.expected.fs @@ -0,0 +1,11 @@ +// ts2fable 0.8.0 +module rec #368-compare-xml-comments.fail +open System +open Fable.Core +open Fable.Core.JS + +// code comments are ignored + +/// XML comments are compared -- additional text to fail +type [] SomeInterface = + interface end \ No newline at end of file diff --git a/test/fragments/regressions/#368-compare-xml-comments.pass.d.ts b/test/fragments/regressions/#368-compare-xml-comments.pass.d.ts new file mode 100644 index 00000000..45c487d5 --- /dev/null +++ b/test/fragments/regressions/#368-compare-xml-comments.pass.d.ts @@ -0,0 +1,4 @@ +/** + * XML comments are compared + */ +interface SomeInterface {} diff --git a/test/fragments/regressions/#368-compare-xml-comments.pass.expected.fs b/test/fragments/regressions/#368-compare-xml-comments.pass.expected.fs new file mode 100644 index 00000000..d1cc71fb --- /dev/null +++ b/test/fragments/regressions/#368-compare-xml-comments.pass.expected.fs @@ -0,0 +1,11 @@ +// ts2fable 0.8.0 +module rec #368-compare-xml-comments.pass +open System +open Fable.Core +open Fable.Core.JS + +// code comments are ignored + +/// XML comments are compared +type [] SomeInterface = + interface end \ No newline at end of file diff --git a/test/fsFileTests.fs b/test/fsFileTests.fs index cbd9f9ce..9c9ffd25 100644 --- a/test/fsFileTests.fs +++ b/test/fsFileTests.fs @@ -22,6 +22,8 @@ let [] only (msg: string) (f: unit->unit): unit = jsNati let [] timeout (duration: int): unit = jsNative let inline equal (expected: 'T) (actual: 'T): unit = Testing.Assert.AreEqual(expected, actual) +let inline notEqual (expected: 'T) (actual: 'T): unit = + Testing.Assert.NotEqual(expected, actual) let testFsFilesWithExports tsPaths fsPath exports (f: FsFile list -> unit) = @@ -111,25 +113,28 @@ describe "transform tests" <| fun _ -> let sanitizeFsFile (lines:#seq) : string array = lines |> Seq.filter (not << System.String.IsNullOrWhiteSpace) - |> Seq.filter (fun l -> not (l.StartsWith("//"))) + |> Seq.filter (fun l -> not (l.StartsWith("//")) || l.StartsWith("///")) // ignore normal comments, but not xml comments |> Seq.map (fun l -> l.TrimEnd()) |> Seq.toArray + + let fileLinesCompare compare expected actual = + compare (sanitizeFsFile expected) (sanitizeFsFile actual) - let fileLinesEqual expected actual = - equal (sanitizeFsFile expected) (sanitizeFsFile actual) - - let convertAndCompareAgainstExpected tsPaths fsPath expected = + let convertAndCompareAgainstExpectedWithComparison compare tsPaths fsPath expected = testFsFileLines tsPaths fsPath <| fun lines -> let expected = let lines = ts2fable.node.FileSystem.readLines (expected) Seq.toArray lines - fileLinesEqual expected lines + fileLinesCompare compare expected lines + let convertAndCompareAgainstExpected = convertAndCompareAgainstExpectedWithComparison equal - let runRegressionTest name = + let runRegressionTestWithComparison compare name = let tsPaths = [sprintf "test/fragments/regressions/%s.d.ts" name] let fsPath = sprintf "test/fragments/regressions/%s.fs" name let expected = sprintf "test/fragments/regressions/%s.expected.fs" name - convertAndCompareAgainstExpected tsPaths fsPath expected + convertAndCompareAgainstExpectedWithComparison compare tsPaths fsPath expected + let runRegressionTest = runRegressionTestWithComparison equal + // https://github.com/fable-compiler/ts2fable/issues/154 it "duplicated variable exports" <| fun _ -> @@ -457,3 +462,8 @@ describe "transform tests" <| fun _ -> it "regression #303 EmitIndexer" <| fun _ -> runRegressionTest "#303-EmitIndexer" + // https://github.com/fable-compiler/ts2fable/pull/368 + it "regression #368 compare xml comments -- pass" <| fun _ -> + runRegressionTest "#368-compare-xml-comments.pass" + it "regression #368 compare xml comments -- fail" <| fun _ -> + runRegressionTestWithComparison notEqual "#368-compare-xml-comments.fail"