Skip to content

Commit

Permalink
Adding some tests for the quickfix, and fixing some quickfixes not wo…
Browse files Browse the repository at this point in the history
…rking
  • Loading branch information
tesonep committed Aug 17, 2016
1 parent 6bc29c4 commit 301b48e
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AbstractWollokQuickFixTestCase extends AbstractWollokInterpreterTestCase {
])
]

assertEquals("The number of issues should be exactly 1", issues.size, 1)
assertEquals("The number of issues should be exactly 1: " + issues, issues.size, 1)
val testedIssue = issues.get(0)

issueResolutionProvider = new WollokDslQuickfixProvider
Expand All @@ -70,7 +70,7 @@ class AbstractWollokQuickFixTestCase extends AbstractWollokInterpreterTestCase {

issueResolutionProvider.issueResolutionAcceptorProvider = [new IssueResolutionAcceptor[issueModificationContext]]

assertTrue("There is not solution for the issue", issueResolutionProvider.hasResolutionFor(testedIssue.code))
assertTrue("There is not solution for the issue: " + testedIssue, issueResolutionProvider.hasResolutionFor(testedIssue.code))

val resolutions = issueResolutionProvider.getResolutions(testedIssue)
val resolution = resolutions.findFirst[it.label == quickFixDescription]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.uqbar.project.wollok.ui.Messages
class CapitalizeClassQuickFixTest extends AbstractWollokQuickFixTestCase {
@Test
def testCapitalizeName(){
val initial = #['''
val initial = #['''
class myClass{
method someMethod(){
return null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.uqbar.project.wollok.tests.quickfix

import org.junit.Test
import org.uqbar.project.wollok.ui.Messages

class QuickFixTest extends AbstractWollokQuickFixTestCase {
@Test
def changeDeclarationToVar(){
val initial = #['''
object myObj{
method someMethod(){
const x = 23
x = 25
}
}
''']

val result = #['''
object myObj{
method someMethod(){
var x = 23
x = 25
}
}
''']
assertQuickfix(initial, result, Messages.WollokDslQuickfixProvider_changeToVar_name)
}

@Test
def addOverrideToMethod(){
val initial = #['''
class MyClass{
method someMethod(){
}
}
class MySubclass inherits MyClass {
method someMethod(){
}
}
''']

val result = #['''
class MyClass{
method someMethod(){
}
}
class MySubclass inherits MyClass {
override method someMethod(){
}
}
''']
assertQuickfix(initial, result, 'Add "override" keyword')
}

@Test
def removeOverrideToMethod(){
val initial = #['''
class MyClass{
}
class MySubclass inherits MyClass {
override method someMethod(){
}
}
''']

val result = #['''
class MyClass{
}
class MySubclass inherits MyClass {
method someMethod(){
}
}
''']
assertQuickfix(initial, result, 'Remove override keyword')
}
@Test
def addMethodToSuperclass(){
val initial = #['''
class MyClass{
}
class MySubclass inherits MyClass {
override method someMethod(){
}
}
''']

val result = #['''
class MyClass{
method someMethod(){
//TODO: Autogenerated Code !
}
}
class MySubclass inherits MyClass {
override method someMethod(){
}
}
''']
assertQuickfix(initial, result, 'Create method in superclass')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ class WollokDslQuickfixProvider extends DefaultQuickfixProvider {
@Fix(WollokDslValidator.CANNOT_ASSIGN_TO_VAL)
def changeDeclarationToVar(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, Messages.WollokDslQuickfixProvider_changeToVar_name, Messages.WollokDslQuickfixProvider_changeToVar_description, null) [ e, context |
val feature = (e as WAssignment).feature
if (feature instanceof WVariableDeclaration) {
val f = (e as WAssignment).feature.ref.eContainer
if (f instanceof WVariableDeclaration) {
val feature = f as WVariableDeclaration
context.xtextDocument.replace(feature.before, feature.node.length,
VAR + " " + feature.ref.name + " =" + feature.right.node.text)
VAR + " " + feature.variable.name + " =" + feature.right.node.text)
}
]
}
Expand Down Expand Up @@ -131,9 +132,9 @@ class WollokDslQuickfixProvider extends DefaultQuickfixProvider {
val method = e as WMethodDeclaration
val parent = method.wollokClass.parent

val constructor = '''method «method.name»(«method.parameters.map[name].join(",")») {
//TODO: «Messages.WollokDslQuickfixProvider_createMethod_stub»
}'''
val constructor = "\t" + '''method «method.name»(«method.parameters.map[name].join(",")»){
//TODO: «Messages.WollokDslQuickfixProvider_createMethod_stub»
}''' + System.lineSeparator

addConstructor(parent, constructor)
]
Expand All @@ -142,7 +143,7 @@ class WollokDslQuickfixProvider extends DefaultQuickfixProvider {
@Fix(METHOD_DOESNT_OVERRIDE_ANYTHING)
def removeOverrideKeyword(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, 'Remove override keyword', 'Remove override keyword.', null) [ e, it |
xtextDocument.deleteToken(e, OVERRIDE)
xtextDocument.deleteToken(e, OVERRIDE + " ")
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ class WollokDslValidator extends AbstractConfigurableDslValidator {
if(!a.feature.ref.isModifiableFrom(a)) report(WollokDslValidator_CANNOT_MODIFY_VAL, a, WASSIGNMENT__FEATURE, cannotModifyErrorId(a.feature))
}
def dispatch String cannotModifyErrorId(WReferenciable it) { CANNOT_ASSIGN_TO_NON_MODIFIABLE }
def dispatch String cannotModifyErrorId(WVariableDeclaration it) { CANNOT_ASSIGN_TO_VAL }
def dispatch String cannotModifyErrorId(WVariable it) { CANNOT_ASSIGN_TO_VAL }
def dispatch String cannotModifyErrorId(WVariableDeclaration it) { CANNOT_ASSIGN_TO_NON_MODIFIABLE }
def dispatch String cannotModifyErrorId(WVariableReference it) { cannotModifyErrorId(ref) }

@Check
Expand Down

0 comments on commit 301b48e

Please sign in to comment.