-
-
Notifications
You must be signed in to change notification settings - Fork 560
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
fix interface methods #1638
Merged
Merged
fix interface methods #1638
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4d08a91
fix interface methods
hyzx86 0323190
update use lambada
hyzx86 276daca
use sample foreach
091ed98
add UnitTest
hyzx86 eeb9661
Add InterfaceTests
hyzx86 2040a04
rename InterfaceTests to InteropInterfaceExtendTests
3095eb6
reformat
lahma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
using Jint.Runtime; | ||
|
||
namespace Jint.Tests.Runtime | ||
{ | ||
public class InterfaceTests | ||
{ | ||
public interface I0 | ||
{ | ||
string NameI0 { get; } | ||
string OverloadSuperMethod(); | ||
string SubPropertySuperMethod(); | ||
} | ||
|
||
public interface I1 : I0 | ||
{ | ||
string Name { get; } | ||
string OverloadSuperMethod(int x); | ||
new string SubPropertySuperMethod { get; } | ||
} | ||
public class Super | ||
{ | ||
public string Name { get; } = "Super"; | ||
} | ||
|
||
public class CI1 : Super, I1 | ||
{ | ||
public new string Name { get; } = "CI1"; | ||
|
||
public string NameI0 { get; } = "I0.Name"; | ||
|
||
string I1.Name { get; } = "CI1 as I1"; | ||
|
||
string I1.SubPropertySuperMethod { get; } = "I1.SubPropertySuperMethod"; | ||
|
||
public string OverloadSuperMethod() | ||
{ | ||
return "I0.OverloadSuperMethod()"; | ||
} | ||
|
||
public string OverloadSuperMethod(int x) | ||
{ | ||
return $"I1.OverloadSuperMethod(int {x})"; | ||
} | ||
|
||
public string SubPropertySuperMethod() | ||
{ | ||
return "I0.SubPropertySuperMethod()"; | ||
} | ||
} | ||
|
||
public class Indexer<T> | ||
{ | ||
private readonly T t; | ||
public Indexer(T t) | ||
{ | ||
this.t = t; | ||
} | ||
public T this[int index] | ||
{ | ||
get { return t; } | ||
} | ||
} | ||
|
||
public class InterfaceHolder | ||
{ | ||
public InterfaceHolder() | ||
{ | ||
var ci1 = new CI1(); | ||
this.ci1 = ci1; | ||
this.i1 = ci1; | ||
this.super = ci1; | ||
|
||
this.IndexerCI1 = new Indexer<CI1>(ci1); | ||
this.IndexerI1 = new Indexer<I1>(ci1); | ||
this.IndexerSuper = new Indexer<Super>(ci1); | ||
} | ||
|
||
public readonly CI1 ci1; | ||
public readonly I1 i1; | ||
public readonly Super super; | ||
|
||
public CI1 CI1 { get => ci1; } | ||
public I1 I1 { get => i1; } | ||
public Super Super { get => super; } | ||
|
||
public CI1 GetCI1() => ci1; | ||
public I1 GetI1() => i1; | ||
public Super GetSuper() => super; | ||
|
||
public Indexer<CI1> IndexerCI1 { get; } | ||
public Indexer<I1> IndexerI1 { get; } | ||
public Indexer<Super> IndexerSuper { get; } | ||
|
||
} | ||
|
||
private readonly Engine _engine; | ||
private readonly InterfaceHolder holder; | ||
|
||
public InterfaceTests() | ||
{ | ||
holder = new InterfaceHolder(); | ||
_engine = new Engine(cfg => cfg.AllowClr( | ||
typeof(CI1).Assembly, | ||
typeof(Console).Assembly, | ||
typeof(File).Assembly)) | ||
.SetValue("log", new Action<object>(Console.WriteLine)) | ||
.SetValue("assert", new Action<bool>(Assert.True)) | ||
.SetValue("equal", new Action<object, object>(Assert.Equal)) | ||
.SetValue("holder", holder) | ||
; | ||
} | ||
|
||
[Fact] | ||
public void CallSuperPropertyFromInterface() | ||
{ | ||
Assert.Equal(holder.I1.NameI0, _engine.Evaluate("holder.I1.NameI0")); | ||
} | ||
|
||
[Fact] | ||
public void CallOverloadSuperMethod() | ||
{ | ||
Assert.Equal( | ||
holder.I1.OverloadSuperMethod(1), | ||
_engine.Evaluate("holder.I1.OverloadSuperMethod(1)")); | ||
Assert.Equal( | ||
holder.I1.OverloadSuperMethod(), | ||
_engine.Evaluate("holder.I1.OverloadSuperMethod()")); | ||
} | ||
|
||
[Fact] | ||
public void CallSubPropertySuperMethod_SubProperty() | ||
{ | ||
Assert.Equal( | ||
holder.I1.SubPropertySuperMethod, | ||
_engine.Evaluate("holder.I1.SubPropertySuperMethod")); | ||
} | ||
|
||
[Fact] | ||
public void CallSubPropertySuperMethod_SuperMethod() | ||
{ | ||
var ex = Assert.Throws<JavaScriptException>(() => | ||
{ | ||
Assert.Equal( | ||
holder.I1.SubPropertySuperMethod(), | ||
_engine.Evaluate("holder.I1.SubPropertySuperMethod()")); | ||
}); | ||
Assert.Equal("Property 'SubPropertySuperMethod' of object is not a function", ex.Message); | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you please remove this change from the PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to rename the class to a clearer name like
InteropInterfaceExtendTests
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done