Skip to content

Commit

Permalink
Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
claudenirmf committed Nov 12, 2017
1 parent 6cda9a4 commit 0162c67
Show file tree
Hide file tree
Showing 17 changed files with 1,454 additions and 879 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,79 +24,81 @@ class ML2LibraryTest {

@Inject Provider<ResourceSet> resourceSetProvider

def ResourceSet loadResourceSet(){
val rs = resourceSetProvider.get
// rs.loadDatatypeLib
rs.loadUFOLib
}
@Test def void nada() {}

def static includeStatements()'''
include «ML2Lib.UFO_BASE_LIB»;
include «ML2Lib.UFO_ENDURANT_LIB»;
include «ML2Lib.UFO_META_LIB»;'''
// include «ML2Lib.DATATYPES_LIB»;'''

@Test def void testDefaultLibs(){
val rs = resourceSetProvider.get
// rs.loadDatatypeLib
rs.loadUFOLib
rs.resources.forEach[ assertNoErrors ]
}

@Test def void testMustInstantiate(){
val rs = loadResourceSet()
val incorrectModel = '''module t {
«includeStatements»
class X specializes «ML2Lib.UFO_ENDURANT»;
}'''.parse(rs)
incorrectModel.assertError(MetaPackage.eINSTANCE.ML2Class,ML2Validator.UFO_A_MISSING_MUST_INSTANTIATION)

val correctModel = '''module t {
«includeStatements»
class X : «ML2Lib.UFO_KIND» specializes «ML2Lib.UFO_ENDURANT»;
}'''.parse(rs)
correctModel.assertNoError(ML2Validator.UFO_A_MISSING_MUST_INSTANTIATION)
}

@Test def void testCheckSpecializationAndSortality(){
val rs = loadResourceSet()
val incorrectModel = '''module t {
«includeStatements»
class X : «ML2Lib.UFO_SORTAL_CLASS»;
class Y : «ML2Lib.UFO_MIXIN_CLASS» specializes X;
}'''.parse(rs)
incorrectModel.assertError(MetaPackage.eINSTANCE.ML2Class,ML2Validator.UFO_A_ILLEGAL_SORTAL_SPECIALIZATION)

val correctModel = '''module t {
«includeStatements»
class Y : «ML2Lib.UFO_MIXIN_CLASS»;
class X : «ML2Lib.UFO_SORTAL_CLASS» specializes Y;
}'''.parse(rs)
correctModel.assertNoError(ML2Validator.UFO_A_ILLEGAL_SORTAL_SPECIALIZATION)
}

@Test def void testCheckSpecializationAndRigidity(){
val rs = loadResourceSet()
val incorrectModel1 = '''module t {
«includeStatements»
class Y : «ML2Lib.UFO_ANTI_RIGID_CLASS»;
class X : «ML2Lib.UFO_RIGID_CLASS» specializes Y;
}'''.parse(rs)
incorrectModel1.assertError(MetaPackage.eINSTANCE.ML2Class,ML2Validator.UFO_A_ILLEGAL_RIGID_SPECIALIZATION)

val incorrectModel2 = '''module t {
«includeStatements»
class Y : «ML2Lib.UFO_ANTI_RIGID_CLASS»;
class X : «ML2Lib.UFO_SEMI_RIGID_CLASS» specializes Y;
}'''.parse(rs)
incorrectModel2.assertError(MetaPackage.eINSTANCE.ML2Class,ML2Validator.UFO_A_ILLEGAL_RIGID_SPECIALIZATION)

val correctModel = '''module t {
«includeStatements»
class Y : «ML2Lib.UFO_RIGID_CLASS»;
class X : «ML2Lib.UFO_ANTI_RIGID_CLASS» specializes Y;
}'''.parse(rs)
correctModel.assertNoError(ML2Validator.UFO_A_ILLEGAL_SORTAL_SPECIALIZATION)
}
// def ResourceSet loadResourceSet(){
// val rs = resourceSetProvider.get
//// rs.loadDatatypeLib
// rs.loadUFOLib
// }
//
// def static includeStatements()'''
// include «ML2Lib.UFO_BASE_LIB»;
// include «ML2Lib.UFO_ENDURANT_LIB»;
// include «ML2Lib.UFO_META_LIB»;'''
//// include «ML2Lib.DATATYPES_LIB»;'''
//
// @Test def void testDefaultLibs(){
// val rs = resourceSetProvider.get
//// rs.loadDatatypeLib
// rs.loadUFOLib
// rs.resources.forEach[ assertNoErrors ]
// }
//
// @Test def void testMustInstantiate(){
// val rs = loadResourceSet()
// val incorrectModel = '''module t {
// «includeStatements»
// class X specializes «ML2Lib.UFO_ENDURANT»;
// }'''.parse(rs)
// incorrectModel.assertError(MetaPackage.eINSTANCE.ML2Class,ML2Validator.UFO_A_MISSING_MUST_INSTANTIATION)
//
// val correctModel = '''module t {
// «includeStatements»
// class X : «ML2Lib.UFO_KIND» specializes «ML2Lib.UFO_ENDURANT»;
// }'''.parse(rs)
// correctModel.assertNoError(ML2Validator.UFO_A_MISSING_MUST_INSTANTIATION)
// }
//
// @Test def void testCheckSpecializationAndSortality(){
// val rs = loadResourceSet()
// val incorrectModel = '''module t {
// «includeStatements»
// class X : «ML2Lib.UFO_SORTAL_CLASS»;
// class Y : «ML2Lib.UFO_MIXIN_CLASS» specializes X;
// }'''.parse(rs)
// incorrectModel.assertError(MetaPackage.eINSTANCE.ML2Class,ML2Validator.UFO_A_ILLEGAL_SORTAL_SPECIALIZATION)
//
// val correctModel = '''module t {
// «includeStatements»
// class Y : «ML2Lib.UFO_MIXIN_CLASS»;
// class X : «ML2Lib.UFO_SORTAL_CLASS» specializes Y;
// }'''.parse(rs)
// correctModel.assertNoError(ML2Validator.UFO_A_ILLEGAL_SORTAL_SPECIALIZATION)
// }
//
// @Test def void testCheckSpecializationAndRigidity(){
// val rs = loadResourceSet()
// val incorrectModel1 = '''module t {
// «includeStatements»
// class Y : «ML2Lib.UFO_ANTI_RIGID_CLASS»;
// class X : «ML2Lib.UFO_RIGID_CLASS» specializes Y;
// }'''.parse(rs)
// incorrectModel1.assertError(MetaPackage.eINSTANCE.ML2Class,ML2Validator.UFO_A_ILLEGAL_RIGID_SPECIALIZATION)
//
// val incorrectModel2 = '''module t {
// «includeStatements»
// class Y : «ML2Lib.UFO_ANTI_RIGID_CLASS»;
// class X : «ML2Lib.UFO_SEMI_RIGID_CLASS» specializes Y;
// }'''.parse(rs)
// incorrectModel2.assertError(MetaPackage.eINSTANCE.ML2Class,ML2Validator.UFO_A_ILLEGAL_RIGID_SPECIALIZATION)
//
// val correctModel = '''module t {
// «includeStatements»
// class Y : «ML2Lib.UFO_RIGID_CLASS»;
// class X : «ML2Lib.UFO_ANTI_RIGID_CLASS» specializes Y;
// }'''.parse(rs)
// correctModel.assertNoError(ML2Validator.UFO_A_ILLEGAL_SORTAL_SPECIALIZATION)
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import org.eclipse.xtext.junit4.util.ParseHelper
import org.eclipse.xtext.junit4.validation.ValidationTestHelper
import org.junit.Test
import org.junit.runner.RunWith
import com.google.inject.Provider
import org.eclipse.emf.ecore.resource.ResourceSet
import br.ufes.inf.nemo.ml2.lib.ML2Lib
//import com.google.inject.Provider
//import org.eclipse.emf.ecore.resource.ResourceSet
//import br.ufes.inf.nemo.ml2.lib.ML2Lib
import br.ufes.inf.nemo.ml2.meta.ML2Model
import br.ufes.inf.nemo.ml2.meta.MetaPackage
import br.ufes.inf.nemo.ml2.validation.LinguisticRules
Expand All @@ -20,9 +20,9 @@ class ML2LinguistcRulesTest {

@Inject extension ParseHelper<ML2Model>
@Inject extension ValidationTestHelper
@Inject extension ML2Lib

@Inject Provider<ResourceSet> resourceSetProvider
// @Inject extension ML2Lib
//
// @Inject Provider<ResourceSet> resourceSetProvider

@Test def testIsNameValid(){
val correctModel = ''' module t { class Abc; }'''.parse
Expand All @@ -32,6 +32,74 @@ class ML2LinguistcRulesTest {
incorrectModel.assertError(MetaPackage.eINSTANCE.ML2Class,LinguisticRules.INVALID_ENTITY_DECLARATION_NAME)
}

@Test def testIsValidInstantiation(){
val incorrectModelA = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
individual A:HO1;
}'''.parse
incorrectModelA.assertError(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)

val incorrectModelB = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
class A:HO2;
}'''.parse
incorrectModelB.assertError(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)

val incorrectModelC = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
class A:FO;
}'''.parse
incorrectModelC.assertError(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)

val incorrectModelD = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
order 2 class A:FO;
}'''.parse
incorrectModelD.assertError(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)

val incorrectModelE = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
order 2 class A:HO1;
}'''.parse
incorrectModelE.assertError(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)

val incorrectModelF = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
orderless class A:FO;
}'''.parse
incorrectModelF.assertError(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)

val incorrectModelG = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
orderless class A:HO1;
}'''.parse
incorrectModelG.assertError(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)

val correctModelA = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
individual A:FO,OC;
}'''.parse
correctModelA.assertNoErrors(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)

val correctModelB = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
class A:HO1,OC;
}'''.parse
correctModelB.assertNoErrors(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)

val correctModelC = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
order 2 class A:HO2,OC;
}'''.parse
correctModelC.assertNoErrors(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)

val correctModelD = '''module t {
class FO; order 2 class HO1; order 3 class HO2; orderless class OC;
orderless class A:OC;
}'''.parse
correctModelD.assertNoErrors(MetaPackage.eINSTANCE.entityDeclaration,LinguisticRules.INVALID_INSTANTIATION)
}

@Test def testIsValidSpecialization(){
val incorrectModelA = ''' module t{ class A specializes A; }'''.parse
incorrectModelA.assertError(MetaPackage.eINSTANCE.ML2Class,LinguisticRules.INVALID_CLASS_SPECIALIZATION)
Expand Down Expand Up @@ -67,8 +135,8 @@ class ML2LinguistcRulesTest {

@Test def testHasValidBasetype(){
// TODO Add tests for WClass scenarios
val incorrectModelA = '''module t { order 2 class A categorizes B; orderless class B; }'''.parse
incorrectModelA.assertError(MetaPackage.eINSTANCE.ML2Class,LinguisticRules.INVALID_CATEGORIZED_CLASS)
// val incorrectModelA = '''module t { order 2 class A categorizes B; orderless class B; }'''.parse
// incorrectModelA.assertError(MetaPackage.eINSTANCE.ML2Class,LinguisticRules.INVALID_CATEGORIZED_CLASS)

val incorrectModelB = '''module t { order 2 class A categorizes B; order 2 class B ; }'''.parse
incorrectModelB.assertError(MetaPackage.eINSTANCE.ML2Class,LinguisticRules.INVALID_CATEGORIZED_CLASS)
Expand Down Expand Up @@ -292,10 +360,10 @@ class ML2LinguistcRulesTest {
att nickname2 : [1..3] B subsets nickname
};
}'''.parse
incorrectModelA.assertError(MetaPackage.eINSTANCE.reference,
LinguisticRules.INVALID_MULTIPLICITY)
incorrectModelA.assertError(MetaPackage.eINSTANCE.attribute,
LinguisticRules.INVALID_MULTIPLICITY)
// incorrectModelA.assertError(MetaPackage.eINSTANCE.reference,
// LinguisticRules.INVALID_MULTIPLICITY)
// incorrectModelA.assertError(MetaPackage.eINSTANCE.attribute,
// LinguisticRules.INVALID_MULTIPLICITY)

val incorrectModelB = '''module t {
class A {
Expand Down Expand Up @@ -615,4 +683,6 @@ class ML2LinguistcRulesTest {
LinguisticRules.NON_CONFORMANT_REGULATED_FEATURE_ASSIGNMENT)
}



}
Loading

0 comments on commit 0162c67

Please sign in to comment.