Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comparison of xml comments for tests #368

Merged
merged 1 commit into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* XML comments are compared
*/
interface SomeInterface {}
Original file line number Diff line number Diff line change
@@ -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 [<AllowNullLiteral>] SomeInterface =
interface end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* XML comments are compared
*/
interface SomeInterface {}
Original file line number Diff line number Diff line change
@@ -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 [<AllowNullLiteral>] SomeInterface =
interface end
26 changes: 18 additions & 8 deletions test/fsFileTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ let [<Emit("it.only($0,$1)")>] only (msg: string) (f: unit->unit): unit = jsNati
let [<Emit("this.timeout($0)")>] 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) =

Expand Down Expand Up @@ -111,25 +113,28 @@ describe "transform tests" <| fun _ ->
let sanitizeFsFile (lines:#seq<string>) : 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 _ ->
Expand Down Expand Up @@ -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"