forked from finos/rune-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added unit test * Fixes finos#785 * Fixed test * Cleaned
- Loading branch information
1 parent
ef78afb
commit 807477c
Showing
15 changed files
with
268 additions
and
71 deletions.
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
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
67 changes: 67 additions & 0 deletions
67
rosetta-ide/src/test/java/com/regnosys/rosetta/ide/issues/Issue785.xtend
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,67 @@ | ||
package com.regnosys.rosetta.ide.issues | ||
|
||
import com.regnosys.rosetta.ide.tests.AbstractRosettaLanguageServerValidationTest | ||
import org.junit.jupiter.api.Test | ||
|
||
|
||
// Issue https://github.com/finos/rune-dsl/issues/785 | ||
class Issue785 extends AbstractRosettaLanguageServerValidationTest { | ||
@Test | ||
def void testIssue785() { | ||
val reportURI = createModel("foo-report.rosetta", ''' | ||
namespace foo | ||
import bar.* | ||
body Authority Body | ||
corpus Regulations Corpus | ||
report Body Corpus in T+2 | ||
from Event | ||
when Eligible | ||
with type Report | ||
eligibility rule Eligible from Event: | ||
item | ||
reporting rule Thing from Event: | ||
"" | ||
''') | ||
createModel("foo-type.rosetta", ''' | ||
namespace foo | ||
type Report: | ||
thing string (1..1) | ||
[ruleReference Thing] | ||
''') | ||
val barURI = createModel("bar-type.rosetta", ''' | ||
namespace bar | ||
type Event: | ||
''') | ||
|
||
// Initial: there should be no issues. | ||
assertNoIssues | ||
|
||
// Introduce reference errors in `foo-report.rosetta` by changing the name of `bar.Event` to `bar.Even`. | ||
makeChange(barURI, 2, 5, "Event", "Even") | ||
|
||
val issues = diagnostics.get(reportURI) | ||
assertIssues( | ||
''' | ||
Error [[9, 9] .. [9, 14]]: Couldn't resolve reference to RosettaType 'Event'. | ||
Error [[13, 31] .. [13, 36]]: Couldn't resolve reference to RosettaType 'Event'. | ||
Error [[16, 26] .. [16, 31]]: Couldn't resolve reference to RosettaType 'Event'. | ||
Warning [[2, 7] .. [2, 12]]: Unused import bar.* | ||
''', | ||
issues | ||
) | ||
// Change back | ||
makeChange(barURI, 2, 5, "Even", "Event") | ||
// All issues should disappear. | ||
assertNoIssues | ||
} | ||
} |
41 changes: 2 additions & 39 deletions
41
rosetta-ide/src/test/java/com/regnosys/rosetta/ide/server/ChangeDetectionTest.xtend
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
54 changes: 54 additions & 0 deletions
54
...est/java/com/regnosys/rosetta/ide/tests/AbstractRosettaLanguageServerValidationTest.xtend
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,54 @@ | ||
package com.regnosys.rosetta.ide.tests | ||
|
||
import java.util.Map | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.eclipse.xtext.testing.TextDocumentConfiguration | ||
import org.eclipse.lsp4j.DidChangeTextDocumentParams | ||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier | ||
import org.eclipse.lsp4j.TextDocumentContentChangeEvent | ||
import org.eclipse.lsp4j.Range | ||
import org.eclipse.lsp4j.Position | ||
import java.util.List | ||
import org.eclipse.lsp4j.Diagnostic | ||
|
||
abstract class AbstractRosettaLanguageServerValidationTest extends AbstractRosettaLanguageServerTest { | ||
Map<String, Integer> versionMap | ||
|
||
@BeforeEach | ||
def void beforeEach() { | ||
versionMap = newHashMap | ||
|
||
initializeContext(new TextDocumentConfiguration) | ||
} | ||
|
||
protected def String createModel(String fileName, String model) { | ||
val uri = fileName.writeFile(model) | ||
open(uri, model) | ||
versionMap.put(uri, 1) | ||
return uri | ||
} | ||
protected def void makeChange(String uri, int line, int character, String oldText, String newText) { | ||
val newVersion = versionMap.get(uri) + 1 | ||
languageServer.didChange(new DidChangeTextDocumentParams( | ||
new VersionedTextDocumentIdentifier(uri, newVersion), | ||
#[ | ||
new TextDocumentContentChangeEvent( | ||
new Range(new Position(line, character), new Position(line, character + oldText.length)), | ||
newText | ||
) | ||
] | ||
)); | ||
versionMap.put(uri, newVersion) | ||
} | ||
|
||
protected def void assertIssues(String expected, List<Diagnostic> actual) { | ||
assertEquals( | ||
expected, | ||
actual.toExpectation | ||
) | ||
} | ||
|
||
protected def dispatch String toExpectation(Diagnostic it) { | ||
'''«severity» «range.toExpectation»: «message»''' | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
rosetta-lang/src/main/java/com/regnosys/rosetta/cache/IRequestScopedCache.java
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,9 @@ | ||
package com.regnosys.rosetta.cache; | ||
|
||
import javax.inject.Provider; | ||
|
||
public interface IRequestScopedCache { | ||
<T> T get(Object key, Provider<T> provider); | ||
|
||
void clear(); | ||
} |
50 changes: 50 additions & 0 deletions
50
rosetta-lang/src/main/java/com/regnosys/rosetta/cache/RequestScopedCache.java
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,50 @@ | ||
package com.regnosys.rosetta.cache; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
import javax.inject.Singleton; | ||
|
||
/** | ||
* A cache that will clear every time a write request is made. For all subsequent read requests, the cache is reused. | ||
*/ | ||
@Singleton | ||
public class RequestScopedCache implements IRequestScopedCache { | ||
// A special object representing a cached null value. | ||
private final Object NULL = new Object(); | ||
|
||
private final Map<Object, Object> values; | ||
|
||
@Inject | ||
public RequestScopedCache() { | ||
this(500); | ||
} | ||
public RequestScopedCache(int initialCapacity) { | ||
this.values = new ConcurrentHashMap<>(initialCapacity); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> T get(Object key, Provider<T> provider) { | ||
Object v = values.get(key); | ||
if (v == NULL) { | ||
return null; | ||
} | ||
if (v != null) { | ||
return (T)v; | ||
} | ||
|
||
T computed = provider.get(); | ||
if (computed == null) { | ||
values.put(key, NULL); | ||
} else { | ||
values.put(key, computed); | ||
} | ||
return computed; | ||
} | ||
|
||
public void clear() { | ||
values.clear(); | ||
} | ||
} |
Oops, something went wrong.