Skip to content

Commit

Permalink
Revert "Update testcases for (now missing) behaviors"
Browse files Browse the repository at this point in the history
This reverts commit d1ac2ca.
  • Loading branch information
Entenwilli committed Nov 26, 2023
1 parent 7b93427 commit 8b5ecde
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,88 @@ class DDDslFormatterTest {
C
}'''.assertFormatting
}


@Test
def testBehavior() {
val expected = '''
dictionary id "123456"
behavior Behavior1 {
input in1
input in2
output out1
output out2
out1.*.* := in1.*.*
out2.*.* := in2.*.*
}'''

val toBeFormatted = '''
dictionary id "123456"
behavior Behavior1 {
input in1
input in2
output out1
output out2
out1 . * . * := in1 . * . *
out2 . * . * := in2 . * . *
}'''
assertFormatting(expected, toBeFormatted)
}

@Test
def testTerms() {
val expected = '''
dictionary id "123456"
enum FirstEnum {
A
}
enumCharacteristicType Type1 using FirstEnum
behavior Behavior1 {
input in1
input in2
output out1
output out2
out1.Type1.* := in1.Type1.*
out1. {
Type1.A := in2.Type1.A
*.* := in1.*.*
}
out2.Type1.A := in2.Type1.A
out1.*.* := true
out2.*.* := !(in1.*.* & in2.*.*)
}'''

val toBeFormatted = '''
dictionary id "123456"
enum FirstEnum {
A
}
enumCharacteristicType Type1 using FirstEnum
behavior Behavior1 {
input in1
input in2
output out1
output out2
out1 . Type1 . * := in1 . Type1 . *
out1 . {
Type1 . A := in2 . Type1 . A
* . * := in1 . * . *
}
out2 . Type1 . A := in2 . Type1 . A
out1 . * . * := true
out2 . * . * := ! ( in1 . * . * & in2 . * . * )
}'''
assertFormatting(expected, toBeFormatted)
}


protected def assertFormatting(CharSequence expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,25 @@ class DDDslParsingTest {
}
enumCharacteristicType AssignedRoles using Roles
enumCharacteristicType ReadAccess using Roles
behavior foo {
input ccd
output RESULT
RESULT.{
*.* := ccd.*.*
ReadAccess.Airline := true
}
}
'''.parse
var characterisations = result.reusableBehaviours.get(0).variableUsages.get(0).
variableCharacterisation_VariableUsage;
var characterisation = characterisations.get(1) as ConfidentialityVariableCharacterisation
var lhs = characterisation.lhs as LhsEnumCharacteristicReference
assertNotNull(lhs.characteristicType)
assertNotNull(lhs.characteristicType.name)
assertNotNull(lhs.literal)
assertNotNull(lhs.literal.name)
}

protected def parse(CharSequence text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,144 @@ class CharacterizedDataDictionaryFormatterTest {
'''.assertFormatting
}

@Test
def testBehaviorDefinition() {
'''
dictionary id "123456"
behavior SomeBehavior {
input in1
input in2
output out1
output out2
out1.*.* := in1.*.*
out2.*.* := in2.*.*
}
'''.assertFormatting
}

@Test
def testWildcardAssignments() {
val initial = '''
dictionary id "123456"
behavior SomeBehavior {
input in1
input in2
output out1
output out2
out1 . * . * := in1 . * . *
out2 . * . * := container . * . *
}
'''
val expected = '''
dictionary id "123456"
behavior SomeBehavior {
input in1
input in2
output out1
output out2
out1.*.* := in1.*.*
out2.*.* := container.*.*
}'''
assertFormatting(expected, initial)
}

@Test
def testBinaryLogicTerm() {
val initial = '''
dictionary id "123456"
behavior SomeBehavior {
input in1
input in2
output out1
output out2
out1 . * . * := in1 . * . * & in2 . * . *
out2 . * . * := container . * . * | in2 . * . *
}
'''
val expected = '''
dictionary id "123456"
behavior SomeBehavior {
input in1
input in2
output out1
output out2
out1.*.* := in1.*.* & in2.*.*
out2.*.* := container.*.* | in2.*.*
}'''
assertFormatting(expected, initial)
}

@Test
def testUnaryTerm() {
val initial = '''
dictionary id "123456"
behavior SomeBehavior {
input in1
input in2
output out1
output out2
out1 . * . * := ! in1 . * . *
}
'''
val expected = '''
dictionary id "123456"
behavior SomeBehavior {
input in1
input in2
output out1
output out2
out1.*.* := !in1.*.*
}'''
assertFormatting(expected, initial)
}

@Test
def testPrimaryTerm() {
val initial = '''
dictionary id "123456"
behavior SomeBehavior {
input in1
input in2
output out1
output out2
out1 . * . * := ( in1 . * . * )
}
'''
val expected = '''
dictionary id "123456"
behavior SomeBehavior {
input in1
input in2
output out1
output out2
out1.*.* := (in1.*.*)
}'''
assertFormatting(expected, initial)
}

protected def assertFormatting(CharSequence expected) {
val toBeFormatted = expected.toString.replaceAll("\\s(?=([^\"']*[\"'][^\"']*[\"'])*[^\"']*$)", " ")
assertFormatting(expected.toString.trim, toBeFormatted)
Expand Down

0 comments on commit 8b5ecde

Please sign in to comment.