Skip to content

Commit

Permalink
Fix broken tests + add some more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Aug 6, 2023
1 parent 1a2d922 commit d6ac5a5
Show file tree
Hide file tree
Showing 18 changed files with 2,671 additions and 1,756 deletions.
27 changes: 24 additions & 3 deletions test/Esprima.Tests/Fixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,27 @@ public void ExecuteTestCase(string fixture)
expected = File.ReadAllText(failureFilePath);
if (WriteBackExpectedTree && conversionOptions.TestCompatibilityMode == AstToJsonTestCompatibilityMode.None)
{
var actual = ParseAndFormat(sourceType, script, parserOptions, parserFactory, conversionOptions);
if (!CompareTrees(actual, expected, metadata))
File.WriteAllText(failureFilePath, actual);
try
{
ParseAndFormat(sourceType, script, parserOptions, parserFactory, conversionOptions);
}
catch (ParserException ex)
{
var expectedJsonObject = JObject.Parse(expected);

var parseError = ex.Error!;
var actualJsonObject = new JObject
{
["index"] = parseError.Index,
["lineNumber"] = parseError.LineNumber,
["column"] = parseError.Column,
["message"] = ex.Message,
["description"] = parseError.Description,
};

if (!JToken.DeepEquals(expectedJsonObject, actualJsonObject))
File.WriteAllText(failureFilePath, actualJsonObject.ToString(Formatting.None));
}
}
}
else
Expand Down Expand Up @@ -292,6 +310,7 @@ private static FixtureMetadata CreateFrom(HashSet<string> flags)
IncludesLocation = flags.Contains("IncludesLocation"),
IncludesRange = flags.Contains("IncludesRange"),
IncludesLocationSource = flags.Contains("IncludesLocationSource"),
IncludesTokens = flags.Contains("IncludesTokens"),
IgnoresRegex = flags.Contains("IgnoresRegex"),
Skip = flags.Contains("Skip"),
};
Expand All @@ -303,6 +322,7 @@ private FixtureMetadata() { }
public bool IncludesLocation { get; init; }
public bool IncludesRange { get; init; }
public bool IncludesLocationSource { get; init; }
public bool IncludesTokens { get; init; }
public bool IgnoresRegex { get; init; }
public bool Skip { get; init; }

Expand All @@ -311,6 +331,7 @@ public AstToJsonOptions CreateConversionOptions(AstToJsonOptions defaultOptions)
TestCompatibilityMode = TestCompatibilityMode,
IncludeLineColumn = IncludesLocation,
IncludeRange = IncludesRange,
IncludeTokens = IncludesTokens,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":8,"lineNumber":1,"column":9,"message":"Line 1: Invalid optional chain from new expression","description":"Invalid optional chain from new expression"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
new a?.b()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":8,"lineNumber":1,"column":9,"message":"Line 1: Invalid optional chain from new expression","description":"Invalid optional chain from new expression"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
new a?.b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":7,"lineNumber":1,"column":8,"message":"Line 1: Unexpected token (","description":"Unexpected token ("}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
new a?.()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":14,"lineNumber":1,"column":15,"message":"Line 1: Invalid optional chain from new expression","description":"Invalid optional chain from new expression"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
new (a?.b)?.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":46,"lineNumber":2,"column":26,"message":"Line 2: 'super' keyword unexpected here","description":"'super' keyword unexpected here"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class B extends A {
constructor() { super?.(); }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":50,"lineNumber":2,"column":30,"message":"Line 2: 'super' keyword unexpected here","description":"'super' keyword unexpected here"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class B extends A {
get prop() { return super?.a; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
a?.['b'].c
a.b?.['c']
new a?.['b'].c
new a.b?.['c']
new (a?.['b'].c)
new (a?.['b']).c
new (a.b?.['c'])
Loading

0 comments on commit d6ac5a5

Please sign in to comment.