Skip to content

Commit 0e26490

Browse files
authored
Merge pull request #368 from Booksbaum/compare-xml-comments
Add comparison of xml comments for tests
2 parents 233a323 + 4ba2e91 commit 0e26490

5 files changed

Lines changed: 48 additions & 8 deletions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* XML comments are compared
3+
*/
4+
interface SomeInterface {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ts2fable 0.8.0
2+
module rec #368-compare-xml-comments.fail
3+
open System
4+
open Fable.Core
5+
open Fable.Core.JS
6+
7+
// code comments are ignored
8+
9+
/// XML comments are compared -- additional text to fail
10+
type [<AllowNullLiteral>] SomeInterface =
11+
interface end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* XML comments are compared
3+
*/
4+
interface SomeInterface {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ts2fable 0.8.0
2+
module rec #368-compare-xml-comments.pass
3+
open System
4+
open Fable.Core
5+
open Fable.Core.JS
6+
7+
// code comments are ignored
8+
9+
/// XML comments are compared
10+
type [<AllowNullLiteral>] SomeInterface =
11+
interface end

test/fsFileTests.fs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ let [<Emit("it.only($0,$1)")>] only (msg: string) (f: unit->unit): unit = jsNati
2222
let [<Emit("this.timeout($0)")>] timeout (duration: int): unit = jsNative
2323
let inline equal (expected: 'T) (actual: 'T): unit =
2424
Testing.Assert.AreEqual(expected, actual)
25+
let inline notEqual (expected: 'T) (actual: 'T): unit =
26+
Testing.Assert.NotEqual(expected, actual)
2527

2628
let testFsFilesWithExports tsPaths fsPath exports (f: FsFile list -> unit) =
2729

@@ -111,25 +113,28 @@ describe "transform tests" <| fun _ ->
111113
let sanitizeFsFile (lines:#seq<string>) : string array =
112114
lines
113115
|> Seq.filter (not << System.String.IsNullOrWhiteSpace)
114-
|> Seq.filter (fun l -> not (l.StartsWith("//")))
116+
|> Seq.filter (fun l -> not (l.StartsWith("//")) || l.StartsWith("///")) // ignore normal comments, but not xml comments
115117
|> Seq.map (fun l -> l.TrimEnd())
116118
|> Seq.toArray
119+
120+
let fileLinesCompare compare expected actual =
121+
compare (sanitizeFsFile expected) (sanitizeFsFile actual)
117122

118-
let fileLinesEqual expected actual =
119-
equal (sanitizeFsFile expected) (sanitizeFsFile actual)
120-
121-
let convertAndCompareAgainstExpected tsPaths fsPath expected =
123+
let convertAndCompareAgainstExpectedWithComparison compare tsPaths fsPath expected =
122124
testFsFileLines tsPaths fsPath <| fun lines ->
123125
let expected =
124126
let lines = ts2fable.node.FileSystem.readLines (expected)
125127
Seq.toArray lines
126-
fileLinesEqual expected lines
128+
fileLinesCompare compare expected lines
129+
let convertAndCompareAgainstExpected = convertAndCompareAgainstExpectedWithComparison equal
127130

128-
let runRegressionTest name =
131+
let runRegressionTestWithComparison compare name =
129132
let tsPaths = [sprintf "test/fragments/regressions/%s.d.ts" name]
130133
let fsPath = sprintf "test/fragments/regressions/%s.fs" name
131134
let expected = sprintf "test/fragments/regressions/%s.expected.fs" name
132-
convertAndCompareAgainstExpected tsPaths fsPath expected
135+
convertAndCompareAgainstExpectedWithComparison compare tsPaths fsPath expected
136+
let runRegressionTest = runRegressionTestWithComparison equal
137+
133138

134139
// https://github.com/fable-compiler/ts2fable/issues/154
135140
it "duplicated variable exports" <| fun _ ->
@@ -457,3 +462,8 @@ describe "transform tests" <| fun _ ->
457462
it "regression #303 EmitIndexer" <| fun _ ->
458463
runRegressionTest "#303-EmitIndexer"
459464

465+
// https://github.com/fable-compiler/ts2fable/pull/368
466+
it "regression #368 compare xml comments -- pass" <| fun _ ->
467+
runRegressionTest "#368-compare-xml-comments.pass"
468+
it "regression #368 compare xml comments -- fail" <| fun _ ->
469+
runRegressionTestWithComparison notEqual "#368-compare-xml-comments.fail"

0 commit comments

Comments
 (0)